How to Install PHP 7 with Apache and MariaDB on CentOS 7/Debian 8

来源:互联网 发布:如何开手机淘宝网店 编辑:程序博客网 时间:2024/05/01 13:01
http://www.tecmint.com/install-and-compile-php-7-on-centos-7-and-debian-8/

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 bug tracking system and to not use PHP 7 in production while it remains in that phase.

Install PHP 7 on CentOS 7 and Debian 8

Compile PHP 7 on CentOS 7 and Debian 8

The bright side is that this version includes several fixes (you may want to refer to this page 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.

Installing PHP 7 in CentOS 7 and Debian 8

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:

On CentOS 7

# yum update && yum install httpd mariadb mariadb-server

On Debian 8

# 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 https://downloads.php.net/~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
PHP 7 buildconf

PHP 7 buildconf

# cd /opt/php-7.0.0RC1.tar.gz# ./buildconf --force
Build PHP 7

Build PHP 7

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 PHP manual 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 $PATHsee 'config.log' for more details
PHP 7 Configure

PHP 7 Configure

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 this page which outlines several errors that you may run into while installing PHP from source, along with their respective solutions.

On CentOS 7

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:

gcclibxml2-develpkgconfigopenssl-develbzip2-develcurl-devellibpng-devellibpng-devellibjpeg-devellibXpm-develfreetype-develgmp-devellibmcrypt-develmariadb-develaspell-develrecode-develhttpd-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:

PHP 7 Configuration Successful

PHP 7 Configuration Successful

Then run,

# make# make install

When the installation is complete you can check the version using the command line:

Check PHP Version

Check PHP Version

On Debian 8

In Debian, I had to install the following packages for the configure process to complete successfully:

makelibxml2-devlibcurl4-openssl-devlibjpeg-devlibpng-devlibxpm-devlibmysqlclient-devlibicu-devlibfreetype6-devlibxslt-devlibssl-devlibbz2-devlibgmp-devlibmcrypt-devlibpspell-dev librecode-devapache2-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
Check PHP Version in Debian

Check PHP Version in Debian 8

Setting Up php.ini and Testing PHP 7 Installation

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
PHP 7 Configuration php.ini File

PHP 7 Configuration php.ini File

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.so<FilesMatch \.php$>SetHandler application/x-httpd-php</FilesMatch>

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

<?phpphpinfo();?>

And launch a browser in a client within your network to test:

http://localhost/test.phpORhttp://IP-address/test.php
Verify PHP 7 info in CentOS 7

Verify PHP 7 info in CentOS 7

Verify PHP 7 info in Debian 8

Verify PHP 7 info in Debian 8

Summary

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.


<script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"16"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script>
阅读(99) | 评论(0) | 转发(0) |
0

上一篇:ProcessMaker 3 Workflow & BPM Documentation——Enterprise Trial Guide

下一篇:(OK) centos7 编译 php-7.0.0RC5

相关热门文章
  • phpStudy 下载,PHP5开发环境...
  • 为PHP添加GD库支持
  • 灵芝的种类和图片
  • yii2权限(RBAC)
  • php生成二维码的几种方式...
  • linux dhcp peizhi roc
  • 关于Unix文件的软链接
  • 求教这个命令什么意思,我是新...
  • sed -e "/grep/d" 是什么意思...
  • 谁能够帮我解决LINUX 2.6 10...
给主人留下些什么吧!~~
原创粉丝点击