How to compile and upgrade php in Linux

Source: Internet
Author: User
Linux compiled to upgrade php detailed method, there is the configuration of php. ini, configure the php-fpm.conf code. Environment: CentOS-5.4
Php upgrade: 5.4.14-5.5.0
Upgrade experience: relatively smooth, but one thing to note: eaccelerator is not compatible with php5.5.0. Fortunately, php provides Zend OPcache by default in 5.5.0, so friends who have been used to eaccelerator will upgrade to php5.5.0, it may be necessary to talk to the eaccelerator about bye temporarily.
1. install php5.5.0
Download php installation package: http://www.php.net/get/php-5.5.0.tar.gz/from/a/mirror
The code is as follows:
# Decompress the installation package
Tar zxvf php-5.5.0.tar.gz

# Enter the Directory
Cd php-5.5.0

# Compile and install
./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 notes:
During installation, add or delete additional components as needed and modify the corresponding directory path.
Do not forget to match opcache:-enable-opcache during installation
The-enable-safe-mode option is added during php-5.3.10 compilation, but the php-5.4.0 has removed this option, which can be used during compilation. /configure-help | grep "safe-mode". no information is output, indicating that it is not supported!
Also available: '-enable-discard-path','-enable-fastcgi ','-enable-force-cgi-redirect ','-with-curlwrappers'
2. Compile and install the php5.5.0 extension module:
Install imagick
To install this module, the server must support ImageMagick, which is irrelevant to php upgrade. This part is omitted. if you need this module, search for it.
: Http://pecl.php.net/package/imagick
The code is as follows:
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:
Avoid compatibility issues. use the latest version instead of versions earlier than 3.0.1.
If make: *** [imagick_file.lo] Error 1 is reported during installation, call pkgconfig
Modify the directory path based on your needs.
Install memcache:
To install this module, the server must support memcached, which is irrelevant to upgrading php. This part is omitted. if you need to install this module, search for it.
: Http://pecl.php.net/package/memcache
The code is as follows:
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 earlier versions, not compatible
Install phpredis-master
To install this module, the server must support redis, which is irrelevant to the upgrade of php. if you need this module, search for it.
: Https://github.com/nicolasff/phpredis
The code is as follows:
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

So far, all required modules have been installed.
3. configure php. ini
The code is as follows:
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"

# Locate date. timezone
Date. timezone = Asia/Shanghai

# Find session. save_handler
Session. save_handler = redis

# Find session. save_path
Session. save_path = "tcp: // fig: 6379? Weight = 1"

Configure Zend OPcache
EAccelerator has always been used to providing php acceleration, but there are two problems:
The eAccelerator is currently not compatible with php5.5.0.
Conflict between eAccelerator and Zend Opcache
Fortunately, php5.5.0 provides Zend Opcache for php acceleration by default. the configuration method is as follows:
The code is as follows:
Zend_extension =/usr/local/webserver/php-d/php-5.5.0/lib/php/extensions/no-debug-non-zts-20121212/opcache. so
Above zend_extension path is opcache. so Path

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 opcache. so cannot be found in your php extension module, it indicates that the installation is not successful. please reinstall it.
4. configure php-fpm.conf
The code is as follows:
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 = 60 s

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: modify the configuration file as needed.
5. modify the startup item:
The code is as follows:
Cp/usr/local/webserver/php-d/php-5.5.0/bin/php/etc/init. d/php

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.