Compile for WordPress to install PHP 7.0.3 Pro-Test all Raiders

Source: Internet
Author: User

What are the benefits of PHP7?

First, it consumes less memory than the PHP5, and secondly, the performance is more than one fold; Finally, the QPS of WordPress can be raised to about 3 times times the original.

WordPress 4.4 's QPS comparison: The larger the number, the higher the QPS

The host VPS configuration for this example

    • Bandwidth: 1Mbps
    • Cpu:1 Nuclear
    • Operating system: Ubuntu 12.04 64-bit
    • Memory: 1GB
    • Solutions: Yes
    • Environment: Linux + Nginx + Memcached + php-fpm

Why to compile the installation

Not for the sake of cool, the Ubuntu 12.04 version of this site is too low, apt-get install not to the latest version of GCC and PHP7.

Check GCC version

@Laruence recommend compiling PHP7 with GCC 4.8 to check the GCC version:

$ gcc-v

If it is below 4.8, it is recommended to compile and upgrade GCC, please refer to the method of upgrading GCC under Linux – Pro-Test available –c++ enthusiasts blog.

As of February 15, 2016, the latest GCC version is 5.3.0, please visit the GCC website and select the download address.

This example has been upgraded from GCC 4.6.3 to GCC 5.3.0, with the following steps:

$ wget http://ftp.tsukuba.wide.ad.jp/software/gcc/releases/gcc-5.3.0/gcc-5.3.0.tar.gz$ 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 dependent files and libraries you need:

$./contrib/download_prerequisites

Set up the output directory and place all the intermediate files in the directory.

$ mkdir gcc_temp$ CD gcc_temp

Run

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

Special attention

The compilation time depends on the performance of the machine and consumes more memory. If your server memory is also very tight, please open 500M swap area, otherwise the make stage memory is not enough to error. This example server IO performance is very poor, so after the end of the swap area to switch off.

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

This example compiles GCC 5.3.0 for 2-3 hours. After the PHP7 compile and install is finished, this example turns off the swap zone:

$ sudo swapoff-a

Start compiling the installation PHP7

As of February 15, 2016, the latest stable version of PHP7 is PHP 7.0.3, the latest version: Http://php.net/downloads.php. Download the latest version:

$ wget http://cn2.php.net/get/php-7.0.3.tar.bz2/from/this/mirror$ tar jxvf mirror$ cd php-7.0.3/

You can look at configuration help first:

./configure--help

This example uses the configuration 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

You may need to install a module that has libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel mysql pcre-devel Curl -devel libxslt-devel and so on ...

Next Run:

$ make && make install

It starts to compile the installation.

PHP7 compile and install the completed screen

Configuration and optimization of PHP7

Copying a configuration file

Some configuration and optimization is required after completion. 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

The online server generally already has the PHP5-FPM service running, modify the user and group in the www.conf to use the username and user groups online, and get rid of the default 9000 port number to avoid conflicts.

Start PHP7-FPM:

$ service PHP-FPM Start

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

This example php7-fpm the test port 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

Put

Fastcgi_pass 127.0.0.1:9000;

9000 is changed to 9008, and a port is opened. And then

$ service Nginx configtest$ service Nginx Reload

You can test the new Port's website in all aspects of whether it is normal.

Performance comparison test

Next, test the efficiency (source) directly with the PHP5.3.10.

The performance comparison of PHP7.0.3 and PHP5.3.10 without opening opache, PHP7 about one times faster but not very obvious

The performance improvement of Opache PHP7.0.3 and PHP5.3.10 is very significant.

Test.php's Content

 
  

Configure Opcache

So Opcache (Http://php.net/opcache) is sure to be enabled. and has already shown that it can allow WordPress to improve a lot of QPS.

WordPress 4.4 There is no opache of the QPS comparison

This example combines Opache's official recommended configuration and @Laruence recommended Opache configuration, adding in php.ini:

Zend_extension=/usr/local/php/lib/php/extensions/no-debug-non-zts-20151012/opcache.soopcache.memory_ consumption=128opcache.interned_strings_buffer=8opcache.max_accelerated_files=4000opcache.revalidate_freq= 60opcache.fast_shutdown=1opcache.enable=1opcache.enable_cli=1opcache.file_cache=/tmp

Where/usr/local/php/lib/php/extensions/no-debug-non-zts-20151012/opcache.so is the address where opcache.so resides.

Restart PHP7-FPM:

$ Service PHP-FPM Restart

All installation and configuration is over.

One way @Laruence have a few tips to get PHP7 up to the highest performance | 15, a lot of useful advice to make PHP7 faster.

This example is only part of the adoption. The Hugepage and Opcache file caches require a certain amount of redundant memory for servers that are filled with poor 1G of small memory every day by the PHP5-FPM process, which is not appropriate.

Make your PHP7 faster (gcc PGO) it is advisable to train gcc and then compile the customized PHP7 version for WordPress, which seems worthy of adoption. However, due to the serious shortage of server resources, basically all of the WordPress page is not generated immediately, but the time-lapse for a half-day WP Super cache cache. Therefore, the speed of the generation of WordPress homepage 7-10% for this example of the server meaning is very limited, so also did not do.

As a result, only the "open Opache" and "use of GCC 4.8 + compilers" were adopted.

Clean up the environment

If there is no problem with the test php7-fpm, you can delete the test site

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

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

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

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

$ service PHP-FPM configtest$ service php5-fpm stop$ service php-fpm restart$ service nginx configtest$ service Nginx Relo Ad

Add Soft Links

In order to enter PHP in any directory, you can call the/usr/local/php/bin/php you just installed, without having to enter it so long, to create a few 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-conf IG Php-config

Now just

$ php-v

To see the version of PHP you just installed. Later install PHP plug-ins can also be directly phpize and php-config.

This example also has WordPress website needs Memcache, so has not finished.

Installing and configuring Php7-memcached

You must be curious about the difference between PHP's memcached and Memcache plugins. In fact, they are functionally similar, relying on the default on the 11211 port of the memcached service, only the encapsulation method is different, and the php-memcached update is more diligent, more functions.

Most importantly, when installing PHP 7.0.3 you will find that you can only install php-memcached! Note that there is this d (as of February 15, 2016). Let's get Started:

Please go to GitHub to download the php-memcached plugin's PHP7 branch (HTTPS://GITHUB.COM/PHP-MEMCACHED-DEV/PHP-MEMCACHED/TREE/PHP7):

$ wget Https://github.com/php-memcached-dev/php-memcached/archive/php7.zip

Unzip and install:

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

This step may prompt you without the libmemcached library:

$ CD. $ wget  https://launchpad.net/libmemcached/1.0/1.0.18/+download/libmemcached-1.0.18.tar.gz$ 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

may also prompt does not support Memcache SASL, recommended to disable, OK!

$./configure--with-php-config= $root/bin/php-config--DISABLE-MEMCACHED-SASL

can finally run

$ make && make install

Finally, add the address of memcached.so to php.ini and install it:

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

Join

Extension=/usr/local/php/lib/php/extensions/no-debug-non-zts-20151012/memcached.so

But there is a hole in front of no mention: WordPress official Memcached plugin only support Php-memcache , note no d. So we use this support php-memcached plug-in Https://github.com/tollmanz/wordpress-pecl-memcached-object-cache. Follow the link as shown in step-by-step configuration.

Interested can also see plug-in author about Php-memcache and php-memcached two PHP plug-in differences between the article: WordPress Object Cache driven by the PECL Memcache (d) extensi On.

Why only use php-memcached (with D)

As of February 15, 2015, PHP7.0.3 directly attempting to install Php-memcache will error:

Fatal error:ext/standard/php_smart_str.h:no such file or directory

Check the reason, is because PHP7 inside, this file changed to Php_smart_string.h. Bloggers have tried to manually change the file name to correct, but also no use, but also error:

Error: ' RETURN STRING ' undeclared (first use of this function)

So this is the plugin is temporarily incompatible with PHP7. Only wait until the Php-memcache plugin is updated. So the blogger finally gave up, according to the above, using the Php-memcached plugin as an alternative.

Refer to the blog post

    • The Definitive PHP 7.0 & HHVM Benchmark
    • How to upgrade GCC under Linux – Pro-Test available –c++ enthusiasts blog
    • Several tips for PHP7 to achieve maximum performance | Dec 15
    • Linux Environment PHP7.0 Installation
  • 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.