Linux compiles the detailed method for upgrading php

  • 2020-11-03 22:03:10
  • OfStack

Server environment: CentOS w4, 5.4
php upgrade: 5.4.14-5.5.0
eaccelerator is not compatible with php5.5.0. Fortunately, php provides Zend OPcache by default in 5.5.0, so people who are used to eaccelerator may need to talk to eaccelerator bye temporarily if they want to upgrade to php5.5.0.
1. Install php5.5.0
Download php installation package: http: / / www php. net get/php - 5.5.0. tar. gz/from/a/mirror

#  Unzip the installation package 
tar zxvf php-5.5.0.tar.gz

#  Enter the directory 
cd php-5.5.0

#  Compile the installation 
./configure \
--prefix=/usr/local/webserver/php-d/php-5.5.0 \
--with-config-file-path=/usr/local/webserver/php-d/php-5.5.0/etc \
--with-config-file-scan-dir=/usr/local/webserver/php-d/php-5.5.0/etc/php.d \
--with-curl=/usr/local/lib \
--with-freetype-dir=/usr/lib64 \
--with-gd \
--with-gettext \
--with-iconv-dir=/usr/local/lib \
--with-jpeg-dir=/usr/lib64 \
--with-kerberos \
--with-ldap \
--with-ldap-sasl \
--with-libdir=lib64 \
--with-libxml-dir=/usr/lib64 \
--with-mcrypt \
--with-mhash \
--with-mysql \
--with-mysqli \
--with-openssl \
--with-pcre-regex=/usr \
--with-pdo-mysql=shared \
--with-pdo-sqlite=shared \
--with-pear=/usr/local/lib/php \
--with-png-dir=/usr/lib64 \
--with-xmlrpc \
--with-xsl \
--with-zlib \
--enable-fpm \
--enable-bcmath \
--enable-libxml \
--enable-inline-optimization \
--enable-gd-native-ttf \
--enable-mbregex \
--enable-mbstring \
--enable-opcache \
--enable-pcntl \
--enable-shmop \
--enable-soap \
--enable-sockets \
--enable-sysvsem \
--enable-xml \
--enable-zip \
--disable-rpath

make ZEND_EXTRA_LIBS='liconv'
make install
cp php.ini-production /usr/local/webserver/php-d/php-5.5.0/etc/php.ini

Here are a few points to note 1:
When installing, please add or delete additional components according to your own situation, modify the corresponding directory path
Remember to install with opcache: WW: ES35en-ES36en
enable-safe-mode has been added to php-5.3.10. However, php-5.4.0 has removed the option./configure? help | grep? safe-mode?
Also go to: 'ES49en-ES50en-ES51en', 'ES52en-ES53en', 'ES54en-ES56en-ES57en', 'ES58en-ES59en'.
2. Compile and install php5.5.0 extension module:
Install imagick
Installation of this module requires the server to support ImageMagick, which has nothing to do with upgrading php, this part is omitted, please search by yourself if needed
Download address: http: / / pecl php. net/package/imagick

tar xvzf imagick-3.1.0RC2.tgz
cd imagick-3.1.0RC2
/usr/local/webserver/php-d/php-5.5.0/bin/phpize
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/
./configure --with-php-config=/usr/local/webserver/php-d/php-5.5.0/bin/php-config
make
make install

Note:
To avoid compatibility problems, please use the latest version and do not use the version before 3.0.1
If the installation error make: *** [imagick_file.lo] error 1 is reported, call pkgconfig
Please modify the above directory path according to your personal situation
Install memcache:
Installation of this module requires the server to support memcached, which has nothing to do with upgrading php, this part is omitted, please search by yourself if needed
Download address: http: / / pecl php. net/package/memcache

tar xvzf memcache-3.0.tgz
cd memcache-3.0.8
/usr/local/webserver/php-d/php-5.5.0/bin/phpize
./configure \
--enable-memcache \
--with-php-config=/usr/local/webserver/php-d/php-5.5.0/bin/php-config
make
make install

Note: Please do not use 2.2.6 or the following versions. They are not compatible
Install phpredis - master
Installation of this module requires the server to support redis, which has nothing to do with upgrading php, this part is omitted, please search by yourself if needed
Download address: https: / / github com/nicolasff/phpredis

unzip master
cd phpredis-master
/usr/local/webserver/php-d/php-5.5.0/bin/phpize
./configure \
--enable-redis \
--with-php-config=/usr/local/webserver/php-d/php-5.5.0/bin/php-config
make
make install

At this point, all the required modules are installed.
3. Configure php. ini

vi /usr/local/webserver/php-d/php-5.5.0/etc/php.ini

#  find extension_dir
extension_dir = "/usr/local/webserver/php-d/php-5.5.0/lib/php/extensions/no-debug-non-zts-20121212/"

extension = "imagick.so"
extension = "memcache.so"
extension = "pdo_mysql.so"
extension = "redis.so"

#  find date.timezone
date.timezone = Asia/Shanghai

#  find session.save_handler
session.save_handler = redis

 #   find session.save_path
session.save_path = "tcp://127.0.0.1:6379?weight=1"

Configuration Zend OPcache
1 It has long been customary to use eAccelerator to provide acceleration for php, but there are currently two problems:
eAccelerator is not compatible with php5.5.0
eAccelerator and Zend Opcache conflict
Fortunately, php5.5.0 provides Zend Opcache as php acceleration by default. The configuration method is as follows:

zend_extension = /usr/local/webserver/php-d/php-5.5.0/lib/php/extensions/no-debug-non-zts-20121212/opcache.so
;  The above zend_extension Path for opcache.so The path of the 

opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
opcache.fast_shutdown=1
opcache.enable_cli=1

Note: If you cannot find ES142en. so extension module in your php, please reinstall it
4. Configuration php - fpm. conf

pid = /usr/local/webserver/php-d/php-5.5.0/var/run/php-fpm.pid
error_log = /usr/local/webserver/php-d/php-5.5.0/logs/php-fpm.log

log_level = notice

emergency_restart_threshold = 10
emergency_restart_interval = 60s

process_control_timeout = 5s
daemonize = yes

rlimit_files = 65535
rlimit_core = 0

user = www
group = www

listen.backlog = -1
listen.owner = www
listen.group = www
listen.mode = 0666
listen.allowed_clients = 127.0.0.1

pm = static
pm.max_children = 64
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 1024

ping.response = pong
slowlog = /usr/local/webserver/php-d/php-5.5.0/logs/$pool.log.slow
request_slowlog_timeout = 0
request_terminate_timeout = 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_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f jht2718@163.com
php_flag[display_errors] = on

Note: Please modify the configuration file according to your own situation
5. Modify the startup item:

cp /usr/local/webserver/php-d/php-5.5.0/bin/php /etc/init.d/php

Related articles: