全部博文(1159)
分类: PHP
2015-10-26 15:31:05
Last last week (more precisely on Aug. 21, 2015), the PHP development team announced the availability of the latest release of PHP 7 and encouraged users and developers worldwide to test it.
However, we must note that since this is a RC (Release Candidate) version, it is expected that it may have bugs or incompatibilities with existing setups so users are being asked to report them using the and to not use PHP 7 in production while it remains in that phase.
The bright side is that this version includes several fixes (you may want to refer to in the project’s GitHub repository for a detailed list of the new features and enhancements), with the most distinguishing feature being a remarkable performance increase when compared to previous versions.
This article will walk you through the process of installing and compiling PHP 7 RC1 from source tarball along with Apache and MariaDB on CentOS 7 and Debian 8 Jessie. The same instructions also works on CentOS based distributions like RHEL, Fedora, Scientific Linux and Debian based such as Ubuntu/Mint.
As stated in the introduction, since this version is a RC instead of a stable release, we cannot reasonably expect to find it in the repositories. For that reason, we will have to download the source code and compile the program from scratch.
Before we do that, however, we need to remember that in order to better take advantage of PHP 7 and perhaps the best way to try it out is installing it along with Apache and MariaDB – which we CAN find in the repositories:
# yum update && yum install httpd mariadb mariadb-server
# aptitude update && aptitude install apache2 mariadb-server mariadb-client mariadb.common
In either case, the tarball with the source code of PHP can be downloaded and extracted as follows:
# wget ~ab/php-7.0.0RC1.tar.gz # tar xzf php-7.0.0RC1.tar.gz -C /opt
Once done, let’s move into /opt/php-7.0.0RC1 and execute the buildconf script with the –force switch in order to force the build of a RC version:
# ls
# cd /opt/php-7.0.0RC1.tar.gz # ./buildconf --force
Now it’s time to execute our well-known configure command. While the options below will ensure a standard PHP 7 installation, you can refer to the complete option list in the in order to better customize the installation as per your needs:
# ./configure \ --prefix=$HOME/php7/usr \ --with-config-file-path=$HOME/php7/usr/etc \ --enable-mbstring \ --enable-zip \ --enable-bcmath \ --enable-pcntl \ --enable-ftp \ --enable-exif \ --enable-calendar \ --enable-sysvmsg \ --enable-sysvsem \ --enable-sysvshm \ --enable-wddx \ --with-curl \ --with-mcrypt \ --with-iconv \ --with-gmp \ --with-pspell \ --with-gd \ --with-jpeg-dir=/usr \ --with-png-dir=/usr \ --with-zlib-dir=/usr \ --with-xpm-dir=/usr \ --with-freetype-dir=/usr \ --enable-gd-native-ttf \ --enable-gd-jis-conv \ --with-openssl \ --with-pdo-mysql=/usr \ --with-gettext=/usr \ --with-zlib=/usr \ --with-bz2=/usr \ --with-recode=/usr \ --with-mysqli=/usr/bin/mysql_config \ --with-apxs2
If you run into the following error:
configure: error: no acceptable C compiler found in $PATH see 'config.log' for more details
Simply install gcc and dependencies with following command and run the above configure command again.
# yum install gcc [On CentOS 7 box] # aptitude install gcc [On Debian 8 box]
You’ll be on your way to compiling PHP 7, which may take a while. If there are other missing libraries or resources, this process will fail but you can always install them and run configure again.
For example, I had to install libxml2-devel after getting the following error message:
configure: error: xml2-config not found. Please check your libxml2 installation.
Unfortunately, we cannot possibly cover all case scenarios since the installed software may vary from one system to another. During the installation, you may want to refer to which outlines several errors that you may run into while installing PHP from source, along with their respective solutions.
Here’s a complete list of the packages I had to install in my CentOS 7 box before being able to complete the configure process:
gcc libxml2-devel pkgconfig openssl-devel bzip2-devel curl-devel libpng-devel libpng-devel libjpeg-devel libXpm-devel freetype-devel gmp-devel libmcrypt-devel mariadb-devel aspell-devel recode-devel httpd-devel
You can install all of the above required packages with one single yum command as shown.
# yum install gcc libxml2-devel pkgconfig openssl-devel bzip2-devel libpng-devel libpng-devel libjpeg-devel libXpm-devel freetype-devel gmp-devel libmcrypt-devel mariadb-devel aspell-devel recode-devel httpd-devel
The following message indicates that configure finished successfully:
Then run,
# make # make install
When the installation is complete you can check the version using the command line:
In Debian, I had to install the following packages for the configure process to complete successfully:
make libxml2-dev libcurl4-openssl-dev libjpeg-dev libpng-dev libxpm-dev libmysqlclient-dev libicu-dev libfreetype6-dev libxslt-dev libssl-dev libbz2-dev libgmp-dev libmcrypt-dev libpspell-dev librecode-dev apache2-dev
You can install all the above required packages with apt-get command on Debian 8.
# apt-get install make libxml2-dev libcurl4-openssl-dev libjpeg-dev libpng-dev libxpm-dev libmysqlclient-dev libicu-dev libfreetype6-dev libxslt-dev libssl-dev libbz2-dev libgmp-dev libmcrypt-dev libpspell-dev librecode-dev apache2-dev
Then add, –with-libdir=/lib/x86_64-linux-gnu to the configure options, and create the following symlink to the gmp.h header file:
# ln -s /usr/include/x86_64-linux-gnu/gmp.h /usr/include/gmp.h
Then ran make and make install as in the previous case. Within 10-15 minutes the compilation should have completed and we can verify the installed PHP version as before:
# make # make install
When you install PHP from source, two sample php.ini are provided. In this case, they are located inside /opt/php-7.0.0RC1:
# ls -l /opt/php-7.0.0RC1 | grep php.ini
You now need to copy one of them to /usr/local/lib, which is designated as the default location for such file as per the Install notes:
# cp /opt/php-7.0.0RC1/php.ini-development /usr/local/lib
And don’t forget to add this configuration directive to the main configuration files of Apache.
/etc/httpd/conf/httpd.conf [On CentOS 7 box] /etc/apache2/apache2.conf in [On Debian 8 box]
LoadModule php7_module /usr/lib64/httpd/modules/libphp7.soSetHandler application/x-httpd-php
In Debian 8 you can omit the LoadModule line and also you need to remove and create the following symbolic links to the indicated Apache modules:
# cd /etc/apache2 # rm mods-enabled/mpm_event.conf # rm mods-enabled/mpm_event.load # ln -s mods-available/mpm_prefork.conf mpm_prefork.conf # ln -s mods-available/mpm_prefork.load mpm_prefork.load
Then, restart the web server:
# systemctl restart httpd [On CentOS 7 box] # systemctl restart apache2 [On Debian 8 box]
If starting up Apache in CentOS 7 returns an error message saying it can’t find the libphp7.so module, simply copy to the indicated path from /opt/php-7.0.0RC1/.libs/libphp7.so.
The classic way to test a PHP/Apache installation is using a phpinfo() file. Create a file named test.php with the following contents in the web server’s document root (/var/www/html in both distributions):
And launch a browser in a client within your network to test:
OR
In this article we have explained how to install PHP 7 from source code, the newest RC of this popular server-side scripting language that aims at improving performance at unprecedented values. Until it reaches the stable in November of this year 2015, you are STRONGLY advised to NOT use this release in a production environment.
If you have any questions / comments / suggestions about this article, feel free to let us know using the form below.