php安裝步驟:
1. 下載php-7.0.14.tar.gz简软,并將其解壓:
$ tar -zvxf php-7.0.14.tar.gz
2. 安裝相關(guān)依賴包:
$ apt-get install -y libxml2 libxml2-dev openssl libcurl4-gnutls-dev libjpeg-dev libpng12-dev libfreetype6-dev
3. 執(zhí)行:ln -s /usr/lib/x86_64-linux-gnu/libssl.so /usr/lib
注:否則會報(bào)錯:configure: error: Cannot find OpenSSL's libraries
4. 編譯:
$ cd php-7.0.14
$ ./configure --with-openssl --with-mysqli=shared,mysqlnd --with-pdo-MySQL=shared,mysqlnd \
--with-gd --with-iconv --with-zlib --enable-zip \
--enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-xml \
--enable-bcmath --enable-shmop --enable-sysvsem --enable-mbregex --enable-mbstring \
--enable-gd-native-ttf --enable-pcntl --enable-sockets --with-xmlrpc --enable-soap \
--without-pear --with-gettext --enable-session --with-curl --with-jpeg-dir --with-freetype-dir --enable-opcache --enable-fpm \
--enable-fastcgi --without-gdbm --disable-fileinfo
5. 安裝:
$ make && make install
成功:
php-fpm配置
$ cd php-7.0.14
$ cp php.ini-production /usr/local/etc/php.ini
在php.ini中添加一行:cgi.fix_pathinfo=0$ cp /usr/local/etc/php-fpm.conf.default /usr/local/etc/php-fpm.conf
$ cp /usr/local/etc/php-fpm.d/www.conf.default /usr/local/etc/php-fpm.d/www.conf$ vi /usr/local/etc/php-fpm.d/www.conf
將group = nobody修改為 group = ,即將nobody刪除。否則在后面執(zhí)行service php-fpm start時會報(bào)錯望忆,即Starting php-fpm [10-Feb-2017 06:32:10] ERROR: [pool www] cannot get gid for group 'nobody'
(可直接執(zhí)行:sed -i "s/group = nobody/group = /g" /usr/local/etc/php-fpm.d/www.conf)$ vi /usr/local/etc/php-fpm.conf
將php-fpm.conf最后一行的include=NONE/etc/php-fpm.d/.conf修改為include=etc/php-fpm.d/.conf
(注:此時可以使用命令進(jìn)行測試:
$ /usr/local/sbin/php-fpm -t
輸出:NOTICE: configuration file /usr/local/etc/php-fpm.conf test is successful 即配置正確)$ cp /root/php-7.0.14/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
$ chmod 755 /etc/init.d/php-fpm
$ service php-fpm start
輸出:Starting php-fpm done
測試是否能解析php文件:
注:先要安裝nginx,具體步聚見http://www.reibang.com/p/6b70db035b95
- 在/usr/local/nginx/html/文件夾下創(chuàng)建一個用于測試的php文件,如test.php:
<?php
phpinfo()
?>
- 啟動nginx(需要對腳本做修改),在瀏覽器中輸入
http://localhost/test.php
称龙,看到以下頁面即成功。
遇到的問題及解決方法
- .編譯時報(bào)錯:configure: error: Cannot find OpenSSL's libraries
解決方法:
apt-get install openssl
apt-get install libssl
find / -name libssl.so
輸出:/usr/lib/x86_64-linux-gnu/libssl.so
執(zhí)行:ln -s /usr/lib/x86_64-linux-gnu/libssl.so /usr/lib - 編譯時報(bào)錯:configure: error: Please reinstall the libcurl distribution -
easy.h should be in <curl-dir>/include/curl/
解決方法:apt-get install libcurl4-gnutls-dev - 編譯時報(bào)錯:configure: error: jpeglib.h not found.
解決方法:apt-get install libjpeg-dev - 編譯時報(bào)錯:configure: error: png.h not found.
解決方法:apt-get install libpng12-dev - 編譯報(bào)錯:configure: error: freetype-config not found.
解決方法:apt-get install libfreetype6-dev - 執(zhí)行/web/php/etc/php-fpm -t報(bào)錯 :
root@ng1:~/php-7.0.14# /web/php/sbin/php-fpm -t
[10-Feb-2017 10:29:10] WARNING: Nothing matches the include pattern '/web/php/etc/php-fpm.d/*.conf' from /web/php/etc/php-fpm.conf at line 125.
[10-Feb-2017 10:29:10] ERROR: No pool defined. at least one pool section must be specified in config file
[10-Feb-2017 10:29:10] ERROR: failed to post process the configuration
[10-Feb-2017 10:29:10] ERROR: FPM initialization failed
解決方法:cd /web/php/etc/php-fpm.d
cp www.conf.default www.conf