開発環境構築メモ(PHP/XAMPP/PHPUnit on Windows7)
ちょっくら環境として使う可能性が出てきたので、最低限の準備の過程をメモ。ちなみにPHP環境はベースとして以下の書籍を参考にしています。
- 作者: 小川雄大,柄沢聡太郎,橋口誠
- 出版社/メーカー: 技術評論社
- 発売日: 2010/11/12
- メディア: 大型本
- 購入: 32人 クリック: 1,065回
- この商品を含むブログ (59件) を見る
XAMPPのインストール
- 以下のサイトにアクセスし、インストーラを入手。(xampp-win32-1.7.7-VC9-installer.exe, 80.9MB)
- 管理者で起動。後はデフォルト指定のままひたすら進めて完了。インストールパスは『C:\xampp』とした。
稼働諸設定
<VirtualHost *:80> ServerName study.localhost DocumentRoot "C:/xampp/htdocs/study.localhost" DirectoryIndex index.php index.html <Directory "C:/xampp/htdocs/study.localhost"> AllowOverride All Allow from All </Directory> </VirtualHost>
- 『C:\Windows\System32\drivers\etc\hosts』に以下の設定を追記。
127.0.0.1 study.localhost
- 上記設定ファイルに併せてフォルダ及びphpファイルを配置。
C:\xampp\htdocs\study.localhost>dir ドライブ C のボリューム ラベルは ローカル ディスク です ボリューム シリアル番号は 8609-AF4E です C:\xampp\htdocs\study.localhost のディレクトリ 2011/11/28 23:47 <DIR> . 2011/11/28 23:47 <DIR> .. 2011/11/28 22:45 261 index.php 1 個のファイル 261 バイト 2 個のディレクトリ 184,321,744,896 バイトの空き領域 C:\xampp\htdocs\study.localhost>
- phpファイルの中身は例によってこちらのコードで。
<?php phpinfo() ?>
- Apache起動。
- 指定のURL( http://study.localhost/ )にアクセス。PHP設定内容が表示されていることを確認。
PHPUnitのインストール
参考にしたのは下記サイト。参考というかほぼそのままですが...(^_^;)
- インストール先へ移動。
C:\>cd C:\xampp\php
- 現在のバージョンを確認。(pear version)
C:\xampp\php>pear version PEAR Version: 1.7.2 PHP Version: 5.3.8 Zend Engine Version: 2.3.0 Running on: Windows NT ABESLETSNOTEF9 6.1 build 7600 (Windows 7 Business Edition) i586
C:\xampp\php>pear upgrade PEAR WARNING: channel "pear.php.net" has updated its protocols, use "channel-update pear.php.net" to update pear/Console_Getopt requires PEAR Installer (version >= 1.8.0), installed version is 1.7.2 downloading PEAR-1.9.4.tgz ... Starting to download PEAR-1.9.4.tgz (296,332 bytes) .............................................................done: 296,332 bytes downloading Archive_Tar-1.3.8.tgz ... Starting to download Archive_Tar-1.3.8.tgz (17,995 bytes) ...done: 17,995 bytes downloading Structures_Graph-1.0.4.tgz ... Starting to download Structures_Graph-1.0.4.tgz (30,318 bytes) ...done: 30,318 bytes upgrade ok: channel://pear.php.net/Archive_Tar-1.3.8 upgrade ok: channel://pear.php.net/Structures_Graph-1.0.4 upgrade ok: channel://pear.php.net/PEAR-1.9.4 PEAR: Optional feature webinstaller available (PEAR's web-based installer) PEAR: Optional feature gtkinstaller available (PEAR's PHP-GTK-based installer) PEAR: Optional feature gtk2installer available (PEAR's PHP-GTK2-based installer) PEAR: To install optional features use "pear install pear/PEAR#featurename"
- 再度バージョンを確認。最新1.9.4になっている事を確認。(pear version)
C:\xampp\php>pear version PEAR Version: 1.9.4 PHP Version: 5.3.8 Zend Engine Version: 2.3.0 Running on: Windows NT ABESLETSNOTEF9 6.1 build 7600 (Windows 7 Business Edition) i586
- インストール用に別途チャンネルを追加。(pear channel-discover)
C:\xampp\php>pear channel-discover pear.phpunit.de C:\xampp\php>pear channel-discover components.ez.no C:\xampp\php>pear channel-discover pear.symfony-project.com
- PHPUnit3のインストール前に、現時点で入っている旧バージョンをアンインストールしておく。(pear uninstall)
C:\xampp\php>pear uninstall phpunit uninstall ok: channel://pear.php.net/PHPUnit-1.3.2 C:\xampp\php>pear uninstall phpunit2 uninstall ok: channel://pear.php.net/PHPUnit2-2.3.6
C:\xampp\php>pear install phpunit/PHPUnit Did not download optional dependencies: phpunit/PHP_Invoker, use --alldeps to download automatically phpunit/PHPUnit can optionally use package "phpunit/PHP_Invoker" (version >= 1.0.0) phpunit/PHP_CodeCoverage can optionally use PHP extension "xdebug" (version >= 2.0.5) downloading PHPUnit-3.6.4.tgz ... Starting to download PHPUnit-3.6.4.tgz (116,783 bytes) .........................done: 116,783 bytes downloading File_Iterator-1.3.0.tgz ... Starting to download File_Iterator-1.3.0.tgz (5,109 bytes) ...done: 5,109 bytes downloading Text_Template-1.1.1.tgz ... Starting to download Text_Template-1.1.1.tgz (3,622 bytes) ...done: 3,622 bytes downloading PHP_CodeCoverage-1.1.1.tgz ... Starting to download PHP_CodeCoverage-1.1.1.tgz (132,339 bytes) ...done: 132,339 bytes downloading PHP_Timer-1.0.2.tgz ... Starting to download PHP_Timer-1.0.2.tgz (3,686 bytes) ...done: 3,686 bytes downloading PHPUnit_MockObject-1.1.0.tgz ... Starting to download PHPUnit_MockObject-1.1.0.tgz (19,688 bytes) ...done: 19,688 bytes downloading YAML-1.0.6.tgz ... Starting to download YAML-1.0.6.tgz (10,010 bytes) ...done: 10,010 bytes downloading PHP_TokenStream-1.1.1.tgz ... Starting to download PHP_TokenStream-1.1.1.tgz (9,672 bytes) ...done: 9,672 bytes install ok: channel://pear.phpunit.de/File_Iterator-1.3.0 install ok: channel://pear.phpunit.de/Text_Template-1.1.1 install ok: channel://pear.phpunit.de/PHP_Timer-1.0.2 install ok: channel://pear.symfony-project.com/YAML-1.0.6 install ok: channel://pear.phpunit.de/PHP_TokenStream-1.1.1 install ok: channel://pear.phpunit.de/PHP_CodeCoverage-1.1.1 install ok: channel://pear.phpunit.de/PHPUnit_MockObject-1.1.0 install ok: channel://pear.phpunit.de/PHPUnit-3.6.4 C:\xampp\php>
- インストール内容の確認。(pear list -a)
C:\xampp\php>pear list -a INSTALLED PACKAGES, CHANNEL __URI: ================================== (no packages installed) INSTALLED PACKAGES, CHANNEL COMPONENTS.EZ.NO: ============================================= (no packages installed) INSTALLED PACKAGES, CHANNEL DOC.PHP.NET: ======================================== (no packages installed) INSTALLED PACKAGES, CHANNEL PEAR.PHP.NET: ========================================= PACKAGE VERSION STATE Archive_Tar 1.3.8 stable Archive_Zip 0.1.1 beta Auth 1.6.1 stable Auth_SASL 1.0.2 stable Benchmark 1.2.7 stable Cache 1.5.5 stable Cache_Lite 1.7.4 stable Calendar 0.5.4 beta Config 1.10.11 stable Console_Color 1.0.2 stable Console_CommandLine 1.0.5 stable Console_Getargs 1.3.4 stable Console_Getopt 1.2.3 stable Console_ProgressBar 0.5.2beta beta Console_Table 1.1.3 stable Crypt_CHAP 1.0.1 stable DB 1.7.13 stable DB_DataObject 1.8.8 stable Date 1.4.7 stable Event_Dispatcher 1.0.0 stable File 1.3.0 stable File_Find 1.3.0 stable File_PDF 0.3.2 beta HTML_Common 1.2.4 stable HTML_Form 1.3.0 stable HTML_Page 2.0.0RC2 beta HTML_Table 1.8.2 stable HTTP 1.4.1 stable HTTP_Download 1.1.3 stable HTTP_Header 1.2.0 stable HTTP_Request 1.4.4 stable I18Nv2 0.11.4 beta Image_Barcode 1.1.0 stable Image_Color 1.0.2 stable Image_Tools 1.0.0RC1 beta Log 1.11.3 stable MDB 1.3.0 stable MDB2 2.4.1 stable MIME_Type 1.1.3 stable MP3_Id 1.2.1 stable MP3_Playlist 0.5.1alpha1 alpha Mail 1.1.14 stable Mail_Mime 1.5.2 stable Mail_mimeDecode 1.5.0 stable Math_Basex 0.3 stable Math_Finance 1.0.0 stable Math_Integer 0.8 stable Math_Numerical_RootFinding 1.0.0 stable Net_DIME 1.0.1 stable Net_SMTP 1.3.2 stable Net_Socket 1.0.9 stable Net_URL 1.0.15 stable Numbers_Roman 1.0.2 stable OLE 1.0.0RC1 beta PEAR 1.9.4 stable PEAR_PackageFileManager 1.6.3 stable PHPDoc 0.1.0 beta PHP_Beautifier 0.1.14 beta PHP_Compat 1.5.0 stable PHP_CompatInfo 1.8.1 stable Pager 2.4.7 stable PhpDocumentor 1.4.2 stable SOAP 0.12.0 beta SQL_Parser 0.5 devel Services_Akismet 1.0.1 stable Services_Amazon 0.7.1 beta Services_Blogging 0.2.3 beta Services_Google 0.2.0 alpha Services_YouTube 0.2.1 alpha Structures_Graph 1.0.4 stable System_Folders 1.0.0 stable Testing_Selenium 0.4.3 beta Text_Diff 1.1.0 stable Text_Wiki 1.2.0 stable Translation2 2.0.1 stable Var_Dump 1.0.3 stable VersionControl_SVN 0.3.1 alpha XML_Beautifier 1.2.0 stable XML_HTMLSax3 3.0.0 stable XML_Parser 1.3.1 stable XML_RPC 1.5.1 stable XML_RPC2 1.0.5 stable XML_Serializer 0.19.1 beta XML_Util 1.2.1 stable XML_fo2pdf 0.98 stable XML_sql2xml 0.3.4 beta INSTALLED PACKAGES, CHANNEL PEAR.PHPUNIT.DE: ============================================ PACKAGE VERSION STATE File_Iterator 1.3.0 stable PHPUnit 3.6.4 stable PHPUnit_MockObject 1.1.0 stable PHP_CodeCoverage 1.1.1 stable PHP_Timer 1.0.2 stable PHP_TokenStream 1.1.1 stable Text_Template 1.1.1 stable INSTALLED PACKAGES, CHANNEL PEAR.SYMFONY-PROJECT.COM: ===================================================== PACKAGE VERSION STATE YAML 1.0.6 stable INSTALLED PACKAGES, CHANNEL PECL.PHP.NET: ========================================= (no packages installed)
- インストール内容の確認。(phpunit --version)
C:\xampp\php>phpunit --version PHPUnit 3.6.4 by Sebastian Bergmann. C:\xampp\php>phpunit.bat PHPUnit 3.6.4 by Sebastian Bergmann. Usage: phpunit [switches] UnitTest [UnitTest.php] phpunit [switches]--log-junit Log test execution in JUnit XML format to file. --log-tap Log test execution in TAP format to file. --log-json Log test execution in JSON format. --coverage-clover Generate code coverage report in Clover XML format. --coverage-html Generate code coverage report in HTML format. --coverage-php Serialize PHP_CodeCoverage object to file. --coverage-text= Generate code coverage report in text format. Default to writing to the standard output. --testdox-html Write agile documentation in HTML format to file. --testdox-text Write agile documentation in Text format to file. --filter Filter which tests to run. --group ... Only runs tests from the specified group(s). --exclude-group ... Exclude tests from the specified group(s). --list-groups List available test groups. --loader TestSuiteLoader implementation to use. --printer TestSuiteListener implementation to use. --repeat Runs the test(s) repeatedly. --tap Report test execution progress in TAP format. --testdox Report test execution progress in TestDox format. --colors Use colors in output. --stderr Write to STDERR instead of STDOUT. --stop-on-error Stop execution upon first error. --stop-on-failure Stop execution upon first error or failure. --stop-on-skipped Stop execution upon first skipped test. --stop-on-incomplete Stop execution upon first incomplete test. --strict Run tests in strict mode. -v|--verbose Output more verbose information. --skeleton-class Generate Unit class for UnitTest in UnitTest.php. --skeleton-test Generate UnitTest class for Unit in Unit.php. --process-isolation Run each test in a separate PHP process. --no-globals-backup Do not backup and restore $GLOBALS for each test. --static-backup Backup and restore static attributes for each test. --bootstrap A "bootstrap" PHP file that is run before the tests. -c|--configuration Read configuration from XML file. --no-configuration Ignore default configuration file (phpunit.xml). --include-path Prepend PHP's include_path with given path(s). -d key[=value] Sets a php.ini value. -h|--help Prints this usage information. --version Prints the version and exits. --debug Output debugging information.
PHPは以前自宅鯖・社内鯖のPukiWiki導入〜ちょっとした改修で軽く触った程度なのでガッツリ業務などで経験したことは無いレベルです。一通りの仕様を把握して、何か最近のフレームワーク(symfonyとか)で一つアプリを作ってみたいんですけどね〜。まずは「パーフェクトPHP」で文法的な所をサラリと流しつつ進めて行こうと思います。