文章目录[隐藏]
PHP5.6的性能和稳定性都不错,以下是在centos7.2上安装PHP5.6的流程和步骤。
确认一下centos的版本
[root@localhost ~]# cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core)
一、安装依赖包和开发工具:
yum install vim vim-enhanced wget zip unzip telnet ntsysv compat* apr* nasm* gcc gcc* gcc-c++ ntp make imake cmake automake autoconf python-devel zlib zlib-devel glibc glibc-devel glib2 libxml glib2-devel libxml2 libxml2-devel bzip2 bzip2-devel libXpm libXpm-devel libidn libidn-devel libtool libtool-ltdl-devel* libmcrypt libmcrypt-devel libevent-devel libmcrypt* libicu-devel libxslt-devel postgresql-devel curl curl-devel perl perl-Net-SSLeay pcre pcre-devel ncurses ncurses-devel openssl openssl-devel openldap openldap-devel openldap-clients openldap-servers krb5 krb5-devel e2fsprogs e2fsprogs-devel libjpeg libpng libjpeg-devel libjpeg-6b libjpeg-devel-6b libpng-devel libtiff-devel freetype freetype-devel fontconfig-devel gd gd-devel kernel screen sysstat flex bison nss_ldap pam-devel compat-libstdc++-33
二、清除系统中php痕迹:
yum remove php rm -rvf /etc/php rm -rvf /etc/php.ini rm -rvf /usr/bin/php
三、安装php所需软件包:
tar zxvf autoconf-2.68.tar.gz -C /usr/src cd /usr/src/autoconf-2.68/ ./configure && make && make install tar zxvf libiconv-1.14.tar.gz -C /usr/src cd /usr/src/libiconv-1.14/srclib/ sed -i -e '/gets is a security/d' ./stdio.in.h cd /usr/src/libiconv-1.14/ ./configure && make && make install tar zxvf libmcrypt-2.5.8.tar.gz -C /usr/src cd /usr/src/libmcrypt-2.5.8/ ./configure && make && make install ldconfig cd libltdl/ ./configure --enable-ltdl-install make && make install export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH tar zxvf mhash-0.9.9.9.tar.gz -C /usr/src cd /usr/src/mhash-0.9.9.9/ ./configure && make && make install tar zxvf mcrypt-2.6.8.tar.gz -C /usr/src cd /usr/src/mcrypt-2.6.8/ ./configure && make && make install
四、 加载php动态模块:
ln -s /usr/local/lib/libmcrypt.la /usr/lib64/libmcrypt.la ln -s /usr/local/lib/libmcrypt.so /usr/lib64/libmcrypt.so ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib64/libmcrypt.so.4 ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib64/libmcrypt.so.4.4.8 ln -s /usr/local/lib/libmhash.a /usr/lib64/libmhash.a ln -s /usr/local/lib/libmhash.la /usr/lib64/libmhash.la ln -s /usr/local/lib/libmhash.so /usr/lib64/libmhash.so ln -s /usr/local/lib/libmhash.so.2 /usr/lib64/libmhash.so.2 ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib64/libmhash.so.2.0.1 cp -R /usr/lib64/libpng.* /usr/lib/ cp -R /usr/lib64/libjpeg.* /usr/lib/
五、 配置模块认证:
echo "/lib" >> /etc/ld.so.conf
echo "/usr/lib" >> /etc/ld.so.conf
echo "/usr/lib64" >> /etc/ld.so.conf
echo "/usr/local/lib" >> /etc/ld.so.conf
echo "* soft nproc 65535" >> /etc/security/limits.conf
echo "* hard nproc 65535" >> /etc/security/limits.conf
echo "* soft nofile 65535" >> /etc/security/limits.conf
echo "* hard nofile 65535" >> /etc/security/limits.conf
echo "fs.file-max=65535" >> /etc/sysctl.conf
ldconfig
六、 解压、配置、编译、安装php:
tar zxvf php-5.6.20.tar.gz -C /usr/src cd /usr/src/php-5.6.20/ ./configure --prefix=/usr/local/php \ --with-config-file-path=/usr/local/php/etc \ --with-fpm-user=www \ --with-fpm-group=www \ --with-mysql=mysqlnd \ --with-mysqli=mysqlnd \ --with-pdo-mysql=mysqlnd \ --with-pgsql \ --with-iconv \ --with-iconv-dir=/usr/ \ --with-freetype-dir=/usr/ \ --with-jpeg-dir=/usr/ \ --with-png-dir=/usr/ \ --with-libxml-dir=/usr \ --with-gettext \ --with-gd \ --with-pear \ --with-curl \ --with-zlib \ --with-zlib-dir \ --with-mcrypt \ --with-mhash \ --with-openssl \ --with-xmlrpc \ --with-xsl \ --with-pcre-regex \ --with-kerberos \ --enable-fpm \ --enable-opcache \ --enable-gd-native-ttf \ --enable-exif \ --enable-mysqlnd \ --enable-ftp \ --enable-zip \ --enable-sockets \ --enable-static \ --enable-xml \ --enable-xmlreader \ --enable-xmlwriter \ --enable-soap \ --enable-mbstring \ --enable-bcmath \ --enable-sysvshm \ --enable-sysvsem \ --enable-intl \ --enable-wddx \ --enable-shmop \ --enable-pcntl \ --enable-mbregex \ --enable-calendar \ --enable-inline-optimization \ --disable-maintainer-zts \ --disable-ipv6 \ --disable-rpath \ --disable-debug \ --disable-fileinfo make ZEND_EXTRA_LIBS='-liconv' make install
七、链接php可执行文件:
ln -s /usr/local/php/bin/php /usr/bin/php
ln -s /usr/local/php/bin/phpize /usr/bin/phpize
ln -s /usr/local/php/sbin/php-fpm /usr/bin/php-fpm
八、创建php相关目录:
mkdir -p /home/php/log mkdir -p /home/php/pid
九、编辑php.ini配置文件:
cp /usr/src/php-5.6.20/php.ini-production /usr/local/php/etc/php.ini
ln -s /usr/local/php/etc/php.ini /etc/php.ini
vim /etc/php.ini
php.ini配置文件百度云盘下载:http://pan.baidu.com/s/1hse6vjQ
十、配置php-fpm.conf配置文件:
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
ln -s /usr/local/php/etc/php-fpm.conf /etc/php-fpm.conf
vim /etc/php-fpm.conf
;;;;;;;;;;;;;;;;;;;; FPM Configuration ;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;; Global Options ;;;;;;;;;;;;;;;;;;;;
[global]
pid = /home/php/pid/php-fpm.pid
error_log = /home/php/log/php-fpm_error.log
log_level = warning
emergency_restart_threshold = 30
emergency_restart_interval = 60s
process_control_timeout = 5s
daemonize = yes
;;;;;;;;;;;;;;;;;;;; Pool Definitions ;;;;;;;;;;;;;;;;;;;;
[www]
listen = /dev/shm/php-cgi.sock
listen.backlog = -1
listen.allowed_clients = 127.0.0.1
listen.owner = www
listen.group = www
listen.mode = 0666
user = www
group = www
pm = dynamic
pm.max_children = 70
pm.start_servers = 50
pm.min_spare_servers = 40
pm.max_spare_servers = 70
pm.max_requests = 2048
pm.process_idle_timeout = 10s
request_terminate_timeout = 120
request_slowlog_timeout = 0
pm.status_path = /php-fpm_status
ping.path = /php-fpm_ping
ping.response = pong
slowlog = /home/php/log/slow.log
rlimit_files = 51200
rlimit_core = 0
catch_workers_output = yes
;env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp
十一、编写php-fpm启动脚本:
vim /etc/init.d/php-fpm
#!/bin/sh
# chkconfig: 2345 90 10
# Description: Start and Stop php-fpm
# Provides: php-fpm
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
prefix=/usr/local/php
exec_prefix=${prefix}
php_fpm_BIN=${prefix}/sbin/php-fpm
php_fpm_CONF=${prefix}/etc/php-fpm.conf
php_fpm_PID=/home/php/pid/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 "Stoping 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
;;
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"
;;
*)
echo "Usage: $0 {start|stop|force-quit|restart|reload}"
exit 1
;;
esac
十二、添加php-fpm系统服务:
chmod a+x /etc/init.d/php-fpm
chkconfig --add php-fpm
chkconfig --level 2345 php-fpm on
chkconfig --list | grep php-fpm
十三、启动php-fpm服务:
service php-fpm start
ps -aux | grep php-fpm
十四、测试:
vim /home/www/html/index.php
<?php
phpinfo();
?>
chown www:www /home/www/html/index.php