本文章緊接上一篇CentOS7.0下編譯安裝Nginx 1.10.0。來完成經常使用的web開發集成環境lnmp的基本搭建,本篇來記錄php的安裝,仍是那些步驟。
php
安裝編譯工具、依賴包及下載源碼包html
解壓編譯mysql
安裝linux
啓動nginx
因爲在上篇文章中編譯工具什麼的都安裝完了,因此直接進行下一步,下載PHP源碼包web
wget http://cn2.php.net/distributions/php-5.6.21.tar.gz
tar -zxvf php-5.6.21.tar.gz
./configure --prefix=/usr/local/php/5.6.21 --enable-fpm
本配置也只是簡單地配置了安裝目錄和支持php-fpm。其餘的配置好比mysql,ssl之類的能夠後期在配置文件裏面加。
可是我配置完給我報了這麼一個錯誤。sql
configure: error: xml2-config not found. Please check your libxml2 installation.
原來是缺乏了一個依賴包,下載安裝從新配置便可:vim
yum install libxml2-devel
配置成功後會給出如下提示:centos
Thank you for using PHP. config.status: creating php5.spec config.status: creating main/build-defs.h config.status: creating scripts/phpize config.status: creating scripts/man1/phpize.1 config.status: creating scripts/php-config config.status: creating scripts/man1/php-config.1 config.status: creating sapi/cli/php.1 config.status: creating sapi/fpm/php-fpm.conf config.status: creating sapi/fpm/init.d.php-fpm config.status: creating sapi/fpm/php-fpm.service config.status: creating sapi/fpm/php-fpm.8 config.status: creating sapi/fpm/status.html config.status: creating sapi/cgi/php-cgi.1 config.status: creating ext/phar/phar.1 config.status: creating ext/phar/phar.phar.1 config.status: creating main/php_config.h config.status: executing default commands
make
編譯時間較長,請耐心等待,不出意外,編譯成功爲出現如下提示:api
Build complete. Don't forget to run 'make test'.
make install
能夠在安裝以前先運行下make test
,不過我不習慣先運行make test
,由於我是一枚業餘寫代碼的段子手。
安裝完以後給出提示
Installing PHP CLI binary: /usr/local/php/5.6.21/bin/ Installing PHP CLI man page: /usr/local/php/5.6.21/php/man/man1/ Installing PHP FPM binary: /usr/local/php/5.6.21/sbin/ Installing PHP FPM config: /usr/local/php/5.6.21/etc/ Installing PHP FPM man page: /usr/local/php/5.6.21/php/man/man8/ Installing PHP FPM status page: /usr/local/php/5.6.21/php/php/fpm/ Installing PHP CGI binary: /usr/local/php/5.6.21/bin/ Installing PHP CGI man page: /usr/local/php/5.6.21/php/man/man1/ Installing build environment: /usr/local/php/5.6.21/lib/php/build/ Installing header files: /usr/local/php/5.6.21/include/php/ Installing helper programs: /usr/local/php/5.6.21/bin/ program: phpize program: php-config Installing man pages: /usr/local/php/5.6.21/php/man/man1/ page: phpize.1 page: php-config.1 Installing PEAR environment: /usr/local/php/5.6.21/lib/php/ [PEAR] Archive_Tar - installed: 1.4.0 [PEAR] Console_Getopt - installed: 1.4.1 [PEAR] Structures_Graph- installed: 1.1.1 [PEAR] XML_Util - installed: 1.3.0 [PEAR] PEAR - installed: 1.10.1 Wrote PEAR system config file at: /usr/local/php/5.6.21/etc/pear.conf You may want to add: /usr/local/php/5.6.21/lib/php to your php.ini include_path /root/php-5.6.21/build/shtool install -c ext/phar/phar.phar /usr/local/php/5.6.21/bin ln -s -f phar.phar /usr/local/php/5.6.21/bin/phar Installing PDO headers: /usr/local/php/5.6.21/include/php/ext/pdo/
安裝完成後還須要更改nginx配置文件使之支持php文件
vim /etc/nginx/nginx.conf
更改的地方以下圖所示
而後重啓nginx,啓動php-fpm
/usr/local/nginx/sbin/nginx -s reload //重啓nginx /usr/local/php/5.6.21/sbin/php-fpm //啓動php-fpm
此時就應該都ok了,在html目錄下新建一測試文件index.php
<?php phpinfo();
打開瀏覽器訪問,出現如圖信息,good,安裝完畢。
附:php-fpm啓動,中止命令
killall php-fpm //中止命令 /usr/local/php/5.6.21/sbin/php-fpm //啓動命令
仍是那句話,以上各步出現錯誤請根據錯誤提示解決,通常都不是大錯誤,也可留言,我們共同討論?。