Detailed description of the sample code for CENTOS7 compiling and installing PHP7

Source: Internet
Author: User
Tags mcrypt php session zts

Create PHP users and user groups

Start by creating a user named PHP with no login rights and a user group named PHP

###### #新建php用户和php组 [root@localhost ~]# groupadd-r php && useradd-r-G php-s/bin/false-d/usr/local/php7-m ph P

Compile the dependencies required to install PHP 7

Compile and install Libmcrypt, Mhash, mcrypt binary source package
The reason for compiling and installing libmcrypt here is that Yum installation looks like an error

##### #编译安装libmcrypt -2.5.7[root@localhost ~]# tar zxvf libmcrypt-2.5.7.tar.gz[root@localhost ~]# CD libmcrypt-2.5.7[ Root@localhost libmcrypt-2.5.7]#./configure--prefix=/usr/local/related/libmcrypt[root@localhost libmcrypt-2.5.7] # make && make install[root@localhost libmcrypt-2.5.7]# cd ~[root@localhost ~]# rm-rf libmcrypt-2.5.7*
##### #编译安装mhash -0.9.9.9[root@localhost ~]# tar zxf mhash-0.9.9.9.tar.gz [ Root@localhost ~]# cd mhash-0.9.9.9[root@localhost mhash-0.9.9.9]#./configure--prefix=/usr/local/related/mhash[  Root@localhost mhash-0.9.9.9]# make && make install[root@localhost mhash-0.9.9.9]# cd ~[root@localhost ~]# RM-RF mhash-0.9.9.9* 
##### #编译安装mcrypt -2.6.8[root@localhost ~]# tar zxf mcrypt-2.6.8.tar.gz && CD mcrypt-2.6.8[root@localhost mcrypt-2.6.8]# Export ld_library_path=/usr/local/related/libmcrypt/lib:/usr/local/related/mhash/lib[ Root@localhost mcrypt-2.6.8]# export ldflags= "-l/usr/local/related/mhash/lib-i/usr/local/related/mhash/include/" [ Root@localhost mcrypt-2.6.8]# export cflags= "-i/usr/local/related/mhash/include/" [root@localhost mcrypt-2.6.8]#./ Configure--prefix=/usr/local/related/mcrypt--with-libmcrypt-prefix=/usr/local/related/libmcrypt[root@localhost mcrypt-2.6.8]# make && make install[root@localhost mcrypt-2.6.8]# cd ~[root@localhost ~]# rm-rf mcrypt-2.6.8*
##### #其他依赖yum安装 [root@localhost ~]# yum-y install libxml2 libxml2-devel OpenSSL openssl-devel curl-devel libjpeg-devel Li Bpng-devel Freetype-devel

Configuration of PHP 7 compilation parameters

Note that you must first remove the following backslash "\" After the comment text added!!!

##### #生成配置文件 [root@localhost ~]# tar-zxf php-7.0.0.tar.gz && cd php-7.0.0[root@localhost php-7.0.0]#./ buildconf--forceforcing buildconfremoving Configure cachesbuildconf:checking installation...buildconf:autoconf Version 2.69 (OK) rebuilding configurerebuilding main/php_config.h.in##### #开始配置 [root@localhost php-7.0.0]#./ Configure \--PREFIX=/USR/LOCAL/PHP7 \ [PHP7 installation root directory]--exec-prefix=/usr/local/php7 \--bindir=/us R/local/php7/bin \--sbindir=/usr/local/php7/sbin \--includedir=/usr/local/php7/include \--libdir=/usr/local/php7/ lib/php \--mandir=/usr/local/php7/php/man \--with-config-file-path=/usr/local/php7/etc \ [PHP7 Configuration directory]--with-mysql  -sock=/var/run/mysql/mysql.sock \ [PHP7 UNIX socket communication file]--with-mcrypt=/usr/include \--with-mhash \--with-openssl                          \--WITH-MYSQL=SHARED,MYSQLND \ [PHP7 dependent MySQL library]--with-mysqli=shared,mysqlnd \ [PHP7 relies on MySQL library]--with-pdo-mysql=shared,mysqlnd\ [PHP7 relies on MySQL library]--with-gd \--with-iconv \--with-zlib \--enable-zip \--enable-inline-optimization \-- Disable-debug \--disable-rpath \--enable-shared \--enable-xml \--enable-bcmath \--enable-shmop \--enable-sysvsem \-- Enable-mbregex \--enable-mbstring \--enable-ftp \--enable-gd-native-ttf \--enable-pcntl \--enable-sockets \-- With-xmlrpc \--enable-soap \--without-pear \--with-gettext \--enable-session \ [Allow PHP Session session]--with-curl \ [Allow curl to extend]--with-jpeg-dir \--with-freetype-dir \--enable                                 -opcache \ [use Opcache cache]--enable-fpm \--enable-fastcgi \--with-fpm-user=nginx \  [PHP-FPM user]--with-fpm-group=nginx \ [php-fpm user group]--without-gdbm \--with-mcrypt=/usr/local/related/libmcrypt \ [Specify Libmcrypt location]--disable-fileinfo

The result of executing the above configuration command is as follows:

Start compiling and installing PHP 7

[Root@localhost php-7.0.0]# make clean && make && make install

PHP 7 compiled and installed successfully

Select step: Execute the Make Test command to test

This is a non-essential operation step that executes the make Test command

To view the PHP7 installation directory after a successful compilation

Due to the need to communicate with MySQL, you need to view the PHP7 installed Lib Extension library directory (/usr/local/php7/lib/php/extensions/no-debug-non-zts-20151012/) in particular. You need to make sure that there are at least mysqli.so, pdo_mysql.so two dynamic library files, as shown in.

[Root@localhost php-7.0.0]# ls-lrt/usr/local/php7/lib/php/extensions/no-debug-non-zts-20151012/

Start setting PHP7 configuration Files php.ini, php-fpm.conf, www.conf, and PHP-FPM scripts

You can use the compiled configuration file to copy to the PHP7 configuration directory (/usr/local/php7/etc/), which is recommended in GitHub. This configuration comes from the configuration of PHP.ini, PHP-FPM, and www.conf in the PHP7

###### #方法一: Directly using a configuration that was not optimized for post-compilation [Root@localhost php-7.0.0]# CP php.ini-production/usr/local/php7/etc/php.ini[ Root@localhost php-7.0.0]# Cp/root/php-7.0.0/sapi/fpm/init.d.php-fpm/etc/init.d/php-fpm[root@localhost php-7.0.0] # cp/usr/local/php7/etc/php-fpm.conf.default/usr/local/php7/etc/php-fpm.conf[root@localhost php-7.0.0]# cp/usr/ local/php7/etc/php-fpm.d/www.conf.default/usr/local/php7/etc/php-fpm.d/www.conf###### #方法二: Using https://github.com /lizer2014/mylnmp/tree/master/php configuration in the article [root@localhost php-7.0.0]# mv ~/php.ini/usr/local/php7/etc/php.ini & & MV ~/php-fpm/etc/init.d/php-fpm[root@localhost php-7.0.0]# MV ~/php-fpm.conf/usr/local/php7/etc/php-fpm.conf & amp;& MV ~/www.conf/usr/local/php7/etc/php-fpm.d/www.conf

Note: You need to modify the parameters in the php.ini configuration, Extension_dir change to your own

Extension_dir = "/usr/local/php7/lib/php/extensions/no-debug-non-zts-20151012/"

Where the/etc/init.d/php-fpm in the start function before the daemon must have the MAKE/VAR/RUN/PHP-FPM command, or restart the server will lead to failure, nginx configuration also has this problem

Add environment Variables for PHP

[Root@localhost php-7.0.0]# echo-e ' \nexport path=/usr/local/php7/bin:/usr/local/php7/sbin: $PATH \ n ' >>/etc/ Profile && Source/etc/profile

Set the PHP log directory and the PHP-FPM process files (php-fpm.sock) directory

Where the user and user groups that set the PHP-FPM process directory are Nginx, and the Session Directory of PHP sessions is created

###### #设置PHP日志目录和php-FPM Run Process ID file (php-fpm.sock) directory [root@localhost php-7.0.0]# groupadd-r nginx && useradd-r- G nginx-s/bin/false-m nginx[root@localhost php-7.0.0]# mkdir-p/var/log/php-fpm/&& mkdir-p/var/run/php-fpm && cd/var/run/&& chown-r nginx:nginx php-fpm###### #修改session的目录配置 [root@localhost run]# mkdir-p/var/l Ib/php/session[root@localhost run]# chown-r nginx:nginx/var/lib/php

Set PHP boot up and test configuration files correctly

##### #配置开机自启动, add to host SysV service [root@localhost run]# chmod +x/etc/init.d/php-fpm[root@localhost run]# chkconfig--add Php-fpm[root@localhost run]# chkconfig php-fpm on##### #测试PHP的配置文件是否正确合法 [root@localhost run]# php-fpm-t[05-dec-2015 17:33:03] Notice:configuration file/usr/local/php7/etc/php-fpm.conf test is successful

Start PHP Service

After you have done this, you can formally use PHP services. The command to start the PHP process service is as follows:

[root@localhost init.d]# service php-fpm startstarting php-fpm done  

You can then use the command ps-aux|grep PHP to see if the success (the number of php-fpm processes in the figure and the process user Nginx are determined by the values of Pm.start_servers and users in www.conf):

View PHP7 Version Information

Finally, you can view the current PHP version information by command php-v, and you can see that the current PHP7 also uses the Zend Opcache cache because php.ini configuration was added to the zend_extension=opcache.so file.

Related articles:

Mac defaults to your own installed PHP

centos6.7 Installation PHP7 Detailed introduction

Install PHP environment under Linux in detail and configure Nginx support PHP-FPM module (graphics)

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.