php学习笔记之搭建开发环境
http://www.cnblogs.com/Village/archive/2012/05/25/2507517.html
当前有好多的PHP集成环境比如lnmp、xampp、lamp都很好用,本来不像介绍这些东西的,无奈我刚转到linux下面,所以就将配置环境这里记录一下,方便以后备查。
安装lnmp
我当前的环境是 debian,我曾在 ylmfOS,Ubuntu,archlinux几个环境下安装过lnmp,感觉就是简单的将脚本分开编译,提示缺少什么组件就安装啥组件,很容易就可以安装成功的。在debian下安装lnmp貌似就更简单了,因为它直接就提供有debian.sh 的安装脚本。只是我编译的过程中遇到了如下两个问题,这里记录下来。
问题一:undefined reference to `libiconv'
/home/besterchen/下载/开发工具/开发环境/PHP/lnmp0.8-full/php-5.2.17/ext/iconv/iconv.c:441: undefined reference to `libiconv_open'
/home/besterchen/下载/开发工具/开发环境/PHP/lnmp0.8-full/php-5.2.17/ext/iconv/iconv.c:453: undefined reference to `libiconv'
/home/besterchen/下载/开发工具/开发环境/PHP/lnmp0.8-full/php-5.2.17/ext/iconv/iconv.c:467: undefined reference to `libiconv'
/home/besterchen/下载/开发工具/开发环境/PHP/lnmp0.8-full/php-5.2.17/ext/iconv/iconv.c:478: undefined reference to `libiconv_close' ext/iconv/iconv.o: In function `_php_iconv_strpos':
/home/besterchen/下载/开发工具/开发环境/PHP/lnmp0.8-full/php-5.2.17/ext/iconv/iconv.c:851: undefined reference to `libiconv_open'
/home/besterchen/下载/开发工具/开发环境/PHP/lnmp0.8-full/php-5.2.17/ext/iconv/iconv.c:879: undefined reference to `libiconv'
/home/besterchen/下载/开发工具/开发环境/PHP/lnmp0.8-full/php-5.2.17/ext/iconv/iconv.c:993: undefined reference to `libiconv_close'
可以确定的是,我确实安装过libiconv组件了,而且安装了好多遍,百度找到了不少的解决方法,试了几个都没解决,根据别人的帖子胡乱的修改编译脚本,反而将问题解决了这里记录下来:
打开debian.sh找到编译PHP的代码:
1 ./buildconf --force 2 ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-discard-path --enable-magic-quotes --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --with-mime-magic 3 make ZEND_EXTRA_LIBS='-liconv' 4 make install
将 '-liconv' 包的包含放入到 configure 的附加条件中,代码如下:
1 ./buildconf --force 2 ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-discard-path --enable-magic-quotes --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --with-mime-magic --with-iconv=/usr/local/libiconv 3 make 4 make install
OK,问题解决。
问题二:undefined reference to `SSLv2_server_method'
ext/openssl/xp_ssl.o: In function `php_openssl_setup_crypto':
/home/besterchen/下载/开发工具/开发环境/PHP/lnmp0.8-full/php-5.2.17/ext/openssl/xp_ssl.c:357: undefined reference to `SSLv2_server_method'
/home/besterchen/下载/开发工具/开发环境/PHP/lnmp0.8-full/php-5.2.17/ext/openssl/xp_ssl.c:337: undefined reference to `SSLv2_client_method' collect2: ld returned 1 exit status make: *** [sapi/cgi/php-cgi] 错误 1
这个问题,需要对php/ext/openssl/xp_ssl.c打补丁(点击这里下载补丁文件),将补丁文件放到PHP的ext目录下的openssl中,然后在该目录中执行:
patch -p3 < debian-patches-disable_SSLv2_for_openssl_1_0_0.patch
要记住php目录要make clean,然后重新make。
到这里编译lnmp应该没有什么问题了。
安装php-pear、phpunit
这两个工具应该是做php开发必备的单元测试工具了吧,网上安装的教程好多的。尤其是windows下。linux下的安装由于确实比较简单。所以也没搜到过详细的记录,这里我记录下来,也算是备查吧。
安装php-pear
将lnmp中php5.2.17目录下的pear文件夹 中的 install-pear-nozlib.phar 拷贝到PHP的安装目录,然后执行命令:
1 besterchen@besterchen-pc ~/下载/PHP/lnmp0.8-full/php-5.2.17/pear $ sudo cp install-pear-nozlib.phar /usr/local/php/ 2 besterchen@besterchen-pc ~/下载/PHP/lnmp0.8-full/php-5.2.17/pear $ cd /usr/local/php/ 3 besterchen@besterchen-pc /usr/local/php $ sudo php install-pear-nozlib.phar 4 [sudo] password for besterchen: 5 [PEAR] Archive_Tar - installed: 1.3.7 6 [PEAR] Console_Getopt - installed: 1.2.3 7 [PEAR] Structures_Graph- installed: 1.0.3 8 [PEAR] XML_Util - installed: 1.2.1 9 [PEAR] PEAR - installed: 1.9.1 10 Wrote PEAR system config file at: /usr/local/php/etc/pear.conf 11 You may want to add: /usr/local/php/lib/php/pear to your php.ini include_path
根据提示将 pear的路径加入到 php.ini的include_path字段中:
1 besterchen@besterchen-pc /usr/local/php $ sudo gedit etc/php.ini
1 ;;;;;;;;;;;;;;;;;;;;;;;;; 2 ; Paths and Directories ; 3 ;;;;;;;;;;;;;;;;;;;;;;;;; 4 5 ; UNIX: "/path1:/path2" 6 include_path = ".:/usr/local/php/lib/php/pear" ; <<<<<< here 7 ; 8 ; Windows: "\path1;\path2" 9 ;include_path = ".;c:\php\includes"
将pear程序链接到 /usr/bin 目录下,使得我们可以在任何目录下都使用pear命令:
1 besterchen@besterchen-pc:~$ sudo ln -s /usr/local/php/bin/pear /usr/bin/
这样pear算是安装完成了,我们更新下它的所有软件包:
1 besterchen@besterchen-pc:~$ sudo pear upgrade-all 2 Will upgrade channel://pear.php.net/pear 3 Will upgrade channel://pear.php.net/console_getopt 4 Will upgrade channel://pear.php.net/archive_tar 5 Will upgrade channel://pear.php.net/structures_graph 6 WARNING: channel "pear.php.net" has updated its protocols, use "pear channel-update pear.php.net" to update 7 downloading PEAR-1.9.4.tgz ... 8 Starting to download PEAR-1.9.4.tgz (296,332 bytes) 9 .............................................................done: 296,332 bytes 10 downloading Console_Getopt-1.3.1.tgz ... 11 Starting to download Console_Getopt-1.3.1.tgz (4,471 bytes) 12 ...done: 4,471 bytes 13 downloading Archive_Tar-1.3.10.tgz ... 14 Starting to download Archive_Tar-1.3.10.tgz (18,294 bytes) 15 ...done: 18,294 bytes 16 downloading Structures_Graph-1.0.4.tgz ... 17 Starting to download Structures_Graph-1.0.4.tgz (30,318 bytes) 18 ...done: 30,318 bytes 19 upgrade-all ok: channel://pear.php.net/Console_Getopt-1.3.1 20 upgrade-all ok: channel://pear.php.net/Archive_Tar-1.3.10 21 upgrade-all ok: channel://pear.php.net/Structures_Graph-1.0.4 22 upgrade-all ok: channel://pear.php.net/PEAR-1.9.4 23 PEAR: Optional feature webinstaller available (PEAR's web-based installer) 24 PEAR: Optional feature gtkinstaller available (PEAR's PHP-GTK-based installer) 25 PEAR: Optional feature gtk2installer available (PEAR's PHP-GTK2-based installer) 26 PEAR: To install optional features use "pear install pear/PEAR#featurename"
OK, php-pear安装完毕。
安装phpunit
添加phpunit的相关频道:
1 besterchen@besterchen-pc:~$ sudo pear channel-discover pear.phpunit.de 2 Adding Channel "pear.phpunit.de" succeeded 3 Discovery of channel "pear.phpunit.de" succeeded 4 besterchen@besterchen-pc:~$ sudo pear channel-discover pear.symfony-project.com 5 Adding Channel "pear.symfony-project.com" succeeded 6 Discovery of channel "pear.symfony-project.com" succeeded
开始安装phpunit
1 besterchen@besterchen-pc:~$ sudo pear install --alldeps --force phpunit/phpunit 2 phpunit/PHP_CodeCoverage can optionally use PHP extension "xdebug" (version >= 2.0.5) 3 downloading PHPUnit-3.6.10.tgz ... 4 Starting to download PHPUnit-3.6.10.tgz (118,595 bytes) 5 .................done: 118,595 bytes 6 downloading File_Iterator-1.3.1.tgz ... 7 Starting to download File_Iterator-1.3.1.tgz (5,157 bytes) 8 ...done: 5,157 bytes 9 downloading Text_Template-1.1.1.tgz ... 10 Starting to download Text_Template-1.1.1.tgz (3,622 bytes) 11 ...done: 3,622 bytes 12 downloading PHP_CodeCoverage-1.1.2.tgz ... 13 Starting to download PHP_CodeCoverage-1.1.2.tgz (132,552 bytes) 14 ...done: 132,552 bytes 15 downloading PHP_Timer-1.0.2.tgz ... 16 Starting to download PHP_Timer-1.0.2.tgz (3,686 bytes) 17 ...done: 3,686 bytes 18 downloading PHPUnit_MockObject-1.1.1.tgz ... 19 Starting to download PHPUnit_MockObject-1.1.1.tgz (19,897 bytes) 20 ...done: 19,897 bytes 21 downloading YAML-1.0.6.tgz ... 22 Starting to download YAML-1.0.6.tgz (10,010 bytes) 23 ...done: 10,010 bytes 24 downloading PHP_Invoker-1.1.0.tgz ... 25 Starting to download PHP_Invoker-1.1.0.tgz (3,727 bytes) 26 ...done: 3,727 bytes 27 downloading PHP_TokenStream-1.1.3.tgz ... 28 Starting to download PHP_TokenStream-1.1.3.tgz (9,860 bytes) 29 ...done: 9,860 bytes 30 install ok: channel://pear.phpunit.de/File_Iterator-1.3.1 31 install ok: channel://pear.phpunit.de/Text_Template-1.1.1 32 install ok: channel://pear.phpunit.de/PHP_Timer-1.0.2 33 install ok: channel://pear.symfony-project.com/YAML-1.0.6 34 install ok: channel://pear.phpunit.de/PHP_TokenStream-1.1.3 35 install ok: channel://pear.phpunit.de/PHP_CodeCoverage-1.1.2 36 install ok: channel://pear.phpunit.de/PHPUnit_MockObject-1.1.1 37 install ok: channel://pear.phpunit.de/PHP_Invoker-1.1.0 38 install ok: channel://pear.phpunit.de/PHPUnit-3.6.10
将phpunit命令也链接到path路径中方便调用命令:
1 besterchen@besterchen-pc:~$ sudo ln -s /usr/local/php/bin/phpunit /usr/bin/
到这里,phpunit 貌似安装好了,找个文件测试一下:
1 besterchen@besterchen-pc:/home/wwwroot/testUnit$ phpunit testHello.php 2 PHPUnit 3.6.10 by Sebastian Bergmann. 3 4 . 5 6 Time: 0 seconds, Memory: 2.25Mb 7 8 OK (1 test, 1 assertion)
在我们测试Yii框架中的测试单元时,出现了如下的错误:
1 Fatal error: require_once(): Failed opening required 'PHPUnit/Extensions/SeleniumTestCase.php' (include_path='.:/usr/local/php/lib/php/pear') in /home/wwwroot/yii/framework/test/CWebTestCase.php on line 11
百度了一下Selenium发现我们还少装了一个扩展:
1 besterchen@besterchen-k52dr:/home/wwwroot/kBase/protected/tests$ sudo pear install phpunit/PHPUnit_Selenium 2 downloading PHPUnit_Selenium-1.2.6.tgz ... 3 Starting to download PHPUnit_Selenium-1.2.6.tgz (30,197 bytes) 4 .........done: 30,197 bytes 5 install ok: channel://pear.phpunit.de/PHPUnit_Selenium-1.2.6
OK,到这里phpunit就安装完成了。
安装PHPUnit_Selenium时,需要PHP开启curl,所以请检查 phpinfo 和 php.ini 确保curl正常工作
搭建JDK开发环境
本来是不需要搭建jdk开发环境的,但是奈何我用的ide是phpstorm,该工具需要jre环境。当然如果看官你不用这些开发环境可以跳过这步骤的。
到sun官网上下载jdk安装包。我下载的是 jdk-7u4-linux-i586.tar.gz。
解压出来放到 /usr/local/java/目录下,然后设置下环境变量,(我图省事儿直接编辑的/etc/profile):
1 #set java environment 2 JAVA_HOME=/usr/local/java/jdk1.7.0 3 CLASSPATH=.:$JAVA_HOME/lib.tools.jar 4 PATH=$PATH:$JAVA_HOME/bin: 5 export JAVA_HOME CLASSPATH PATH
OK,这样就都搞定了~