Install PHP7.0.3 for WordPress compilation

Source: Internet
Author: User
Tags config php zts
How can I install PHP7.0.3 for WordPress compilation?

First, it occupies less memory than PHP5; secondly, it doubles the performance faster; finally, the QPS of WordPress can be increased to about three times.

Comparison of WordPress 4.4 QPS: The larger the number, the higher the QPS

Host VPS configuration in this example
  • Bandwidth: 1 Mbps
  • CPU: 1 Core
  • Operating system: Ubuntu 12.04 64-bit
  • Memory: 1 GB
  • Yundun: Yes
  • Environment: Linux + Nginx + Memcached + PHP-FPM
Why compile and install

This is not for cool purposes. The Ubuntu 12.04 version used on this site is too low. apt-get install cannot install the latest GCC and PHP7 versions.

Check the GCC version

@ Laruence we recommend that you use GCC 4.8 or later to compile PHP7. check the GCC version:

$ gcc -v

If it is less than 4.8, it is recommended to compile and upgrade GCC. refer to the method for upgrading gcc in linux-Test-available-C ++ fans blog.

As of January 1, February 15, 2016, the latest version of GCC is 5.3.0. go to the GCC official website to view and select the latest version.

In this example, we upgraded from GCC 4.6.3 to GCC 5.3.0 by performing the following steps:

$ wget$ tar -xf gcc-5.3.0.tar.gz$ cd gcc-5.3.0

Run the download_prerequisites script, which will automatically help you download the required dependent files and libraries:

$ ./contrib/download_prerequisites

Create an output directory and place all intermediate files in the directory,

$ mkdir gcc_temp$ cd gcc_temp


$ ../configure --enable-checking=release --enable-languages=c,c++ --disable-multilib$ make && make install
Special note

The compilation time depends on the machine performance and consumes a large amount of memory. If your server memory is also very tight, enable the 500 m swap zone. Otherwise, an error will be reported if the memory in the Make stage is insufficient. In this example, the I/O performance of the server is very poor, so you can turn off the SWAP zone after the end.

$ SWAP=/tmp/swap$ dd if=/dev/zero of=$SWAP bs=1M count=500$ mkswap $SWAP$ sudo swapon $SWAP

In this example, it takes two to three hours to compile GCC 5.3.0. After PHP 7 compilation and installation is complete, the SWAP zone is disabled in this example:

$ sudo swapoff -a
Start compiling and installing PHP7

As of February 15, 2016, PHP7's latest stable version is PHP 7.0.3, the latest version of information: Download the latest version:

$ wget$ tar jxvf mirror$ cd php-7.0.3/

You can first look at the configuration help:

./configure --help

Configuration used in this example, where/usr/local/php is the installation target location

./configure --prefix=/usr/local/php --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --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

If you are prompted that some modules cannot be found, you may need to install them separately, for example

$ sudo apt-get install libcurl4-gnutls-dev

The modules you may need to install include libjpeg-devel libpng-devel freetype-devel libxml2 libxml2-devel mysql pcre-devel curl-devel libxslt-devel and so on ......

Next run:

$ make && make install

Compile and install.

PHP 7 compilation and installation completed

Configure and optimize the replication configuration file for PHP 7

Some configuration and optimization are required. First, copy the configuration file:

$ cp php.ini-development /usr/local/php/lib/php.ini$ cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf$ cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf$ cp -R ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
Test start PHP7-FPM

An online server typically has a PHP5-FPM service running. change the user and group in www. conf to the username and user group used online, and change the default 9000 port number to avoid conflict.

Start PHP7-FPM:

$ service php-fpm start

After the startup is successful, you can view phpinfo () and so on.

In this example, the test port of the PHP7-FPM is 9008, assuming that the online nginx configuration is bokeyy, then:

$ cp /etc/nginx/site-available/bokeyy /etc/nginx/site-enabled/bokeyy_php7$ vim /etc/nginx/site-enabled/bokeyy_php7



And open a port. Then

$ service nginx configtest$ service nginx reload

You can test whether the website on the new port is normal.

Performance Comparison test

Next, we will directly compare with PHP5.3.10 to test the efficiency (source ).

Compared with PHP7.0.3 and PHP5.3.10 without Opache, PHP7 is about twice faster but not obvious.

Compared with PHP7.0.3 and PHP5.3.10 of Opache, the performance improvement is remarkable.

Content of test. php

Configure opcache

So Opcache ( must be enabled. It has already been illustrated that it can improve WordPress's QPS a lot.

QPS comparison of WordPress 4.4 with or without Opache

In this example, combined with the configurations officially recommended by Opache and the Opache configurations recommended by @ Laruence, add the following to php. ini:


/Usr/local/php/lib/php/extensions/no-debug-non-zts-20151012/opcache. so is the address of opcache. so.

Restart PHP7-FPM can:

$ service php-fpm restart
All installation and configuration ends here.

Yacheng @ Laruence has an article about several Tips that enables PHP7 to reach the highest performance | 04 Dec 15, providing a lot of useful suggestions for making PHP7 faster.

In this example, only a part is adopted. For every day by the php5-fpm process to fill the poor 1G small memory of the server, HugePage and Opcache file cache need a certain amount of redundant memory, not suitable.

To make PHP 7 faster (gcc pgo), it is recommended that you train GCC first and then compile the customized PHP 7 version for WordPress. However, due to the serious shortage of server resources, basically all WordPress pages are not generated in real time, but are cached in WP Super Cache with a validity period of half a day. Therefore, the speed of generating the WordPress homepage is improved by 7-10%, which is of little significance to the server in this example.

Therefore, only the "Enable Opache" and "use GCC 4.8 or above compilers" are adopted. Clean up the environment

If the test PHP7-FPM has no problem, you can delete the test site

$ rm /etc/nginx/site-enabled/bokeyy_php7

Edit www. conf to change the PHP7-FPM port to 9000

$ vim /usr/local/php/etc/php-fpm.d/www.conf

Finally turn off the PHP5-FPM, with PHP7-FPM to replace:

$ service php-fpm configtest$ service php5-fpm stop$ service php-fpm restart$ service nginx configtest$ service nginx reload
Add soft link

In order to enter php in any directory, you can call the newly installed/usr/local/php/bin/php without having to enter such a long length to create several soft links.

$ cd /usr/bin$ ln -s /usr/local/php/bin/php php$ ln -s /usr/local/php/bin/phpize phpize$ ln -s /usr/local/php/bin/php-config php-config

Now only

$ php -v

You can view the php version you just installed. You can also directly install the PHP plug-in phpize and php-config later.

In this example, the WordPress website needs Memcache, so it is not over yet.

Install and configure the PHP7-MEMCACHED

You must be curious about the differences between memcached and memcache plug-ins in PHP. In fact, they all rely on the memcached service on port 11211 by default, but the encapsulation method is different. php-memcached updates more frequently and has more functions.

Most importantly, after installing PHP 7.0.3, you will find that you can only install php-memcached! Note that this d (as of January 1, February 15, 2016) exists ). Let's start:

Please download php-memcached plug-in php7 branch ( from github ):

$ wget

Unzip and install:

$ unzip$ cd php-memcached-php7/$ root=/usr/local/php$ $root/bin/phpize$ ./configure --with-php-config=$root/bin/php-config

This step may prompt that you do not have the libmemcached Library:

$ cd ..$ wget$ tar xvf libmemcached-1.0.18.tar.gz$ cd libmemcached-1.0.18$ ./configure$ cd ../php-memcached-php7/$ ./configure --with-php-config=$root/bin/php-config

You may also be prompted that memcache sasl is not supported. we recommend that you disable it. okay!

$ ./configure --with-php-config=$root/bin/php-config --disable-memcached-sasl

Finally Run

$ make && make install

Add the memcached. so address to php. ini and install it:

$ vim /usr/local/php/lib/php.ini



However, there is another pitfall that is not mentioned above:WordPress official Memcached plug-in only supports php-memcacheNote that there is no d. So we use this plug-in that supports php-memcached. Configure it step by step as shown in the link.

If you are interested, refer to The plug-in author's article on The differences between php-memcache and php-memcached PHP plug-ins: WordPress Object Cache Driven By The PECL Memcache (d) Extension.

Why can only use php-memcached (with d)

As of March 13, February 15, 2015, php-memcache installation attempt in PHP7.0.3 will report an error:

fatal error: ext/standard/php_smart_str.h: No such file or directory

Check the cause because the file in PHP7 is changed to php_smart_string.h. The blogger has tried to manually change the file name to the correct one, but it is useless. an error will also be reported:

error: 'RETURN STRING' undeclared(first use in this function)

So this plug-in is not compatible with PHP 7 for the moment. Wait until the php-memcache plug-in is updated. As a result, the blogger finally gave up and used the php-memcached plug-in as an alternative.

Reference Blog articles
  • The Definitive PHP 7.0 & HHVM Benchmark
  • How to upgrade gcc in linux-test availability-C ++ fans blog
  • Several Tips for PHP7 to reach the highest performance | 04 Dec 15
  • Install PHP7.0 in Linux

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: 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.