本身一點小愛好,搭建了一個小網站植物大戰殭屍百科, 使用的是騰訊雲,市場裏的鏡像很差用,因此本身手動搭建一波。php
centos 7 編譯安裝 php-7.2.11的步驟html
在官網下載php-7.2.11的php壓縮包,centos 7 安裝 php-7.2.11的步驟,http://cn2.php.net/distributions/php-7.2.11.tar.gzmysql
cd /usr/local/src
wget -c http://cn2.php.net/distributions/php-7.2.11.tar.gz
下載好後解壓 php-7.2.11.tar.gz 壓縮包,並進入解壓後的目錄nginx
tar -xzvf php-7.2.11.tar.gz
cd php-7.2.11
安裝php7須要的一些依賴庫包 libxml2和一些其餘依賴的擴展庫sql
yum -y install libxml2
yum -y install libxml2-devel
yum -y install openssl
yum -y install openssl-devel
yum -y install curl-devel
yum -y install libjpeg-devel
yum -y install libpng-devel
yum -y install freetype-devel
yum -y install bzip2-devel
yum -y install libmcrypt libmcrypt-devel
yum -y install postgresql-devel
yum -y install aspell-devel
yum -y install readline-devel
yum -y install libxslt-devel
yum -y install net-snmp-devel
yum -y install unixODBC-devel
yum -y install libicu-devel
yum -y install libc-client-devel
yum -y install libXpm-devel
yum -y install libvpx-devel
yum -y install enchant-devel
yum -y install openldap
yum -y install openldap-devel
yum -y install db4-devel
yum -y install gmp-devel
yum -y install sqlite-devel
yum -y install mysql-devel
安裝前的環境配置檢查,php7的一些依賴包的檢查和php擴展的啓動,這個過程若是缺乏php依賴的庫包會有報錯提示。json
添加用戶和組: (此處用戶和組爲 nginx, 我 nginx 用的用戶名 ) groupadd -r nginx && useradd -r -g nginx -s /sbin/nologinvim
php 安裝配置centos
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-soap --with-xmlrpc --with-openssl --with-mcrypt --with-pcre-regex --with-sqlite3 --with-zlib --enable-bcmath --with-iconv --with-bz2 --enable-calendar --with-curl --with-cdb --enable-dom --enable-exif --enable-fileinfo --enable-filter --with-pcre-dir --enable-ftp --with-gd --with-openssl-dir --with-jpeg-dir --with-png-dir --with-freetype-dir --enable-gd-native-ttf --enable-gd-jis-conv --with-gettext --with-gmp --with-mhash --enable-json --enable-mbstring --enable-mbregex --enable-mbregex-backtrack --with-libmbfl --with-onig --enable-pdo --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-zlib-dir --with-pdo-sqlite --with-readline --enable-session --enable-shmop --enable-simplexml --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --with-libxml-dir --with-xsl --enable-zip --enable-mysqlnd-compression-support --with-pear --enable-opcacheapi
對php7進行編譯和安裝的操做session
make && make install
( 若是出現 make: *** [sapi/cli/php] Error 1 的錯誤,經過繼續執行 make ZEND_EXTRA_LIBS='-liconv' 命令解決
編譯成功,查看php版本
/usr/local/php/bin/php -v
運行php-fpm
/usr/local/php/sbin/php-fpm
啓動php-fpm可能會遇到的錯誤,基本都是配置文件配置和重命名的問題:
錯誤一:缺乏www.conf配置文件(WARNING: Nothing matches the include pattern /usr/local/php/etc/php-fpm.d/*.conf),須要把/usr/local/php/etc/php-fpm.d/*.conf目錄中的www.conf.default重命名爲www.conf。
錯誤二:缺乏php-fpm.conf配置文件 須要在/usr/local/php/etc/php-fpm.conf 把默認的配置文件php-fpm.conf.default改爲php-fpm.conf
錯誤三:缺乏php.ini配置文件 php7編譯安裝好後會發現沒有php.ini配置文件,須要在解壓包的根目錄中複製php.ini-production或php.ini-development並重命名爲php.ini到php編譯好的安裝目錄中的/usr/local/php/etc文件夾便可。
在centos7中編譯安裝好php後,系統重啓後並不會對php進行開機啓動,因此須要對centos7添加開機啓動腳本對php進行開機啓動服務。
php7編譯安裝方法:http://zixuephp.net/article-207.html
手動啓動:
/usr/local/php/sbin/php-fpm
開機自動啓動:
開啓配置php-fpm pid
#找到php-fpm.conf配置文件
/usr/local/php/etc/php-fpm.conf
#開啓pid ,去掉分號註釋
pid = run/php-fpm.pid
建立開機啓動腳本
在Linux中將php-fpm配置成服務的方法
PHP 源文件路徑: /usr/local/src/php-7.2.11/
PHP 安裝後路徑: /usr/local/php/
1. 配置 php-fpm.conf
vim /usr/local/php/etc/php-fpm.conf
php-fpm.pid 目錄必須指向:/usr/local/php/var/run/php-fpm.pid
2. 拷貝php-fpm腳本至/etc/init.d目錄
cp /usr/local/src/php-7.2.11/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
#! /bin/sh
### BEGIN INIT INFO
# Provides: php-fpm
# Required-Start: $remote_fs $network
# Required-Stop: $remote_fs $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts php-fpm
# Description: starts the PHP FastCGI Process Manager daemon
### END INIT INFO
prefix=/usr/local/php
exec_prefix=${prefix}
php_fpm_BIN=${exec_prefix}/sbin/php-fpm
php_fpm_CONF=${prefix}/etc/php-fpm.conf
php_fpm_PID=${prefix}/var/run/php-fpm.pid
php_opts="--fpm-config $php_fpm_CONF --pid $php_fpm_PID"
wait_for_pid () {
try=0
while test $try -lt 35 ; do
case "$1" in
'created')
if [ -f "$2" ] ; then
try=''
break
fi
;;
'removed')
if [ ! -f "$2" ] ; then
try=''
break
fi
;;
esac
echo -n .
try=`expr $try + 1`
sleep 1
done
}
case "$1" in
start)
echo -n "Starting php-fpm "
$php_fpm_BIN --daemonize $php_opts
if [ "$?" != 0 ] ; then
echo " failed"
exit 1
fi
wait_for_pid created $php_fpm_PID
if [ -n "$try" ] ; then
echo " failed"
exit 1
else
echo " done"
fi
;;
stop)
echo -n "Gracefully shutting down php-fpm "
if [ ! -r $php_fpm_PID ] ; then
echo "warning, no pid file found - php-fpm is not running ?"
exit 1
fi
kill -QUIT `cat $php_fpm_PID`
wait_for_pid removed $php_fpm_PID
if [ -n "$try" ] ; then
echo " failed. Use force-quit"
exit 1
else
echo " done"
fi
;;
status)
if [ ! -r $php_fpm_PID ] ; then
echo "php-fpm is stopped"
exit 0
fi
PID=`cat $php_fpm_PID`
if ps -p $PID | grep -q $PID; then
echo "php-fpm (pid $PID) is running..."
else
echo "php-fpm dead but pid file exists"
fi
;;
force-quit)
echo -n "Terminating php-fpm "
if [ ! -r $php_fpm_PID ] ; then
echo "warning, no pid file found - php-fpm is not running ?"
exit 1
fi
kill -TERM `cat $php_fpm_PID`
wait_for_pid removed $php_fpm_PID
if [ -n "$try" ] ; then
echo " failed"
exit 1
else
echo " done"
fi
;;
restart)
$0 stop
$0 start
;;
reload)
echo -n "Reload service php-fpm "
if [ ! -r $php_fpm_PID ] ; then
echo "warning, no pid file found - php-fpm is not running ?"
exit 1
fi
kill -USR2 `cat $php_fpm_PID`
echo " done"
;;
configtest)
$php_fpm_BIN -t
;;
*)
echo "Usage: $0 {start|stop|force-quit|restart|reload|status|configtest}"
exit 1
;;
esac
3.設置權限並啓動php-fpm:
chmod 755 /etc/init.d/php-fpm
/etc/init.d/php-fpm start
chkconfig –add php-fpm
最後,給出php-fpm以服務的方式啓動、中止和重啓:
service php-fpm start
service php-fpm stop
service php-fpm reload
PHP-FPM 自啓動配置服務:
vim /etc/rc.d/rc.local
chkconfig --list
nginx demo 配置:(不要忘記chown www-data:www-data 網站目錄 否則沒權限)
server {
listen 80;
server_name {{ server_name }};
access_log /data/logs/nginx/{{ server_name }}/access.log;
error_log /data/logs/nginx/{{ server_name }}/error.log;
location / {
index index.php index.html index.htm;
root /data/www/wwwroot/{{ server_name }}/;
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php;
}
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/tmp/php-fcgi.sock;
fastcgi_index index.php;
}
}
php-fpm配置 (重命名兩個文件 其餘看實際狀況配置(略。。。))www.conf.default -> www.confphp-fpm.conf.default -> php-fpm.conf啓動: php-fpm -Dnginx -s reload