本篇文章給大家分享的內容是關於Nginx和php安裝及配置二之安裝和配置php-fpm,有著一定的參考價值,有需要的朋友可以參考一下
一、編譯安裝php
1、建立放置安裝包的目錄及下載解壓:
php下載地址:http://www.php.net/downloads.php
2、指定安裝目錄和運行時用的屬主和屬組,並啟用狀態監控模組等,在/soft/php/php-5.6.27下:
./configure--prefix=/usr/local/php --with-config-file-path=/etc--enable-inline-optimization --disable-debug --disable-rpath --enable-shared--enable-opcache --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysql=mysqlnd--with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-gettext --enable-mbstring--with-iconv --with-mcrypt --with-mhash --with-openssl --enable-bcmath--enable-soap --with-libxml-dir --enable-pcntl --enable-shmop --enable-sysvmsg--enable-sysvsem --enable-sysvshm --enable-sockets --with-curl --with-zlib--enable-zip --with-bz2 --with-readline --without-sqlite3 --without-pdo-sqlite--with-pear
--------可能出現的錯誤:
出現錯誤: congigure error:xml2-config not found.
解決辦法:
執行命令: sudo yum installlibxml2-devel
查看是否成功: find / -name"xml2-config"
--------出現錯誤: congigure error: Cannotfind OpenSSL's <evp.h>
解決辦法:
yum install opensslopenssl-devel
ln -s/usr/lib64/libssl.so /usr/lib/
--------出現錯誤: configure: error:Please reinstall the BZip2 distribution
解決辦法:yum install bzip2 bzip2-devel
--------出現錯誤: configure: error:Please reinstall the libcurl distribution -easy.h should be in<curl-dir>/include/curl/
解決辦法:yum -y install curl-devel
--------出現錯誤: configure: error:mcrypt.h not found. Please reinstall libmcrypt.
解決辦法:sudo yum installlibmcrypt libmcrypt-devel mcrypt mhash
--------出現錯誤: configure: error:Please reinstall readline - I cannot find readline.h
解決辦法:sudo yum install readline-devel
3、安裝:
make
make install
4、啟動
添加 PHP 命令到環境變數
vim /etc/profile
在末尾加入
PATH=$PATH:/usr/local/php/bin
export PATH
要使改動立即生效執行
. /etc/profile 或source /etc/profile
5、配置php-fpm
cd /usr/local/php/etc
cp php-fpm.conf.defaultphp-fpm.conf
6、啟動php-fpm
sudo /usr/local/php/sbin/php-fpm -c/etc/php.ini -y /usr/local/php/etc/php-fpm.conf
(需要手動引入php.ini檔案)
注意:如果啟動php-fpm出現錯誤: cannot get uid for www,修改php-fpm.conf中user為nginx group為nginx
ERROR: unable to bind listening socket for address ‘127.0.0.1:9000’
解決辦法:
kill all php-fpm
然後重啟即可。