CentOS7.2安装PHP5.6

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/

五、 配置模块认证:

  1. echo "/lib" >> /etc/ld.so.conf
  2. echo "/usr/lib" >> /etc/ld.so.conf
  3. echo "/usr/lib64" >> /etc/ld.so.conf
  4. echo "/usr/local/lib" >> /etc/ld.so.conf
  5. echo "* soft nproc 65535" >> /etc/security/limits.conf
  6. echo "* hard nproc 65535" >> /etc/security/limits.conf
  7. echo "* soft nofile 65535" >> /etc/security/limits.conf
  8. echo "* hard nofile 65535" >> /etc/security/limits.conf
  9. echo "fs.file-max=65535" >> /etc/sysctl.conf
  10.  
  11. 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可执行文件:

  1. ln -s /usr/local/php/bin/php /usr/bin/php
  2. ln -s /usr/local/php/bin/phpize /usr/bin/phpize
  3. 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配置文件:

  1. cp /usr/src/php-5.6.20/php.ini-production /usr/local/php/etc/php.ini
  2. ln -s /usr/local/php/etc/php.ini /etc/php.ini
  3. vim /etc/php.ini

php.ini配置文件百度云盘下载:http://pan.baidu.com/s/1hse6vjQ

十、配置php-fpm.conf配置文件:

  1. cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
  2. ln -s /usr/local/php/etc/php-fpm.conf /etc/php-fpm.conf
  3. vim /etc/php-fpm.conf
  1. ;;;;;;;;;;;;;;;;;;;; FPM Configuration ;;;;;;;;;;;;;;;;;;;;
  2.  
  3. ;;;;;;;;;;;;;;;;;;;; Global Options ;;;;;;;;;;;;;;;;;;;;
  4.  
  5. [global]
  6. pid = /home/php/pid/php-fpm.pid
  7. error_log = /home/php/log/php-fpm_error.log
  8. log_level = warning 
  9.  
  10. emergency_restart_threshold = 30
  11. emergency_restart_interval = 60s 
  12. process_control_timeout = 5s
  13. daemonize = yes
  14.  
  15. ;;;;;;;;;;;;;;;;;;;; Pool Definitions ;;;;;;;;;;;;;;;;;;;;
  16.  
  17. [www]
  18. listen = /dev/shm/php-cgi.sock
  19. listen.backlog = -1
  20. listen.allowed_clients = 127.0.0.1
  21. listen.owner = www 
  22. listen.group = www
  23. listen.mode = 0666
  24. user = www 
  25. group = www
  26.  
  27. pm = dynamic
  28. pm.max_children = 70
  29. pm.start_servers = 50
  30. pm.min_spare_servers = 40
  31. pm.max_spare_servers = 70
  32. pm.max_requests = 2048
  33. pm.process_idle_timeout = 10s
  34. request_terminate_timeout = 120
  35. request_slowlog_timeout = 0
  36.  
  37. pm.status_path = /php-fpm_status
  38. ping.path = /php-fpm_ping
  39. ping.response = pong
  40. slowlog = /home/php/log/slow.log
  41. rlimit_files = 51200
  42. rlimit_core = 0
  43.  
  44. catch_workers_output = yes
  45. ;env[HOSTNAME] = $HOSTNAME
  46. env[PATH] = /usr/local/bin:/usr/bin:/bin
  47. env[TMP] = /tmp
  48. env[TMPDIR] = /tmp
  49. env[TEMP] = /tmp

十一、编写php-fpm启动脚本:

  1. vim /etc/init.d/php-fpm
  1. #!/bin/sh
  2. # chkconfig:        2345 90 10
  3. # Description:        Start and Stop php-fpm
  4. # Provides:        php-fpm
  5. # Default-Start:    2 3 4 5
  6. # Default-Stop:        0 1 6
  7. prefix=/usr/local/php
  8. exec_prefix=${prefix}
  9. php_fpm_BIN=${prefix}/sbin/php-fpm
  10. php_fpm_CONF=${prefix}/etc/php-fpm.conf
  11. php_fpm_PID=/home/php/pid/php-fpm.pid
  12. php_opts="--fpm-config $php_fpm_CONF --pid $php_fpm_PID"
  13. wait_for_pid () {
  14. try=0
  15. while test $try -lt 35 ; do
  16. case "$1" in
  17. 'created')
  18. if [ -f "$2" ] ; then
  19. try=''
  20. break
  21. fi
  22. ;;
  23. 'removed')
  24. if [ ! -f "$2" ] ; then
  25. try=''
  26. break
  27. fi
  28. ;;
  29. esac
  30. echo -n .
  31. try=`expr $try + 1`
  32. sleep 1
  33. done
  34. }
  35. case "$1" in
  36. start)
  37. echo -n "Starting php-fpm..."
  38. $php_fpm_BIN --daemonize $php_opts
  39. if [ "$?" != 0 ] ; then
  40. echo " failed"
  41. exit 1
  42. fi
  43. wait_for_pid created $php_fpm_PID
  44. if [ -n "$try" ] ; then
  45. echo " failed"
  46. exit 1
  47. else
  48. echo " done"
  49. fi
  50. ;;
  51. stop)
  52. echo -n "Stoping php-fpm..."
  53. if [ ! -r $php_fpm_PID ] ; then
  54. echo "warning, no pid file found - php-fpm is not running ?"
  55. exit 1
  56. fi
  57. kill -QUIT `cat $php_fpm_PID`
  58. wait_for_pid removed $php_fpm_PID
  59. if [ -n "$try" ] ; then
  60. echo " failed. Use force-quit"
  61. exit 1
  62. else
  63. echo " done"
  64. fi
  65. ;;
  66. force-quit)
  67. echo -n "Terminating php-fpm "
  68. if [ ! -r $php_fpm_PID ] ; then
  69. echo "warning, no pid file found - php-fpm is not running ?"
  70. exit 1
  71. fi
  72. kill -TERM `cat $php_fpm_PID`
  73. wait_for_pid removed $php_fpm_PID
  74. if [ -n "$try" ] ; then
  75. echo " failed"
  76. exit 1
  77. else
  78. echo " done"
  79. fi
  80. ;;
  81. restart)
  82. $0 stop
  83. $0 start
  84. ;;
  85. reload)
  86. echo -n "Reload service php-fpm "
  87. if [ ! -r $php_fpm_PID ] ; then
  88. echo "warning, no pid file found - php-fpm is not running ?"
  89. exit 1
  90. fi
  91. kill -USR2 `cat $php_fpm_PID`
  92. echo " done"
  93. ;;
  94. *)
  95. echo "Usage: $0 {start|stop|force-quit|restart|reload}"
  96. exit 1
  97. ;;
  98. esac

十二、添加php-fpm系统服务:

  1. chmod a+x /etc/init.d/php-fpm
  2. chkconfig --add php-fpm
  3. chkconfig --level 2345 php-fpm on
  4. chkconfig --list | grep php-fpm

十三、启动php-fpm服务:

  1. service php-fpm start
  2. ps -aux | grep php-fpm

十四、测试:

  1. vim /home/www/html/index.php
  2. <?php
  3. phpinfo();
  4. ?>
  5. chown www:www /home/www/html/index.php

发布日期:

所属分类: Linux/Centos/Os 标签: