CentOS 7.1 Compile and install PHP7

Source: Internet
Author: User
Tags php session php website

Original: https://typecodes.com/web/centos7compilephp7.html?utm_source=tuicool&utm_medium=referral 1 create PHP users and user groups, and download PHP7 source on GitHub

First create a user named PHP 没有登录权限 and a user group named PHP, and then go to GitHub to download the PHP7 source package.

###### #新建php用户和php组 [[email protected] ~]# groupadd-r php && useradd-r-G php-s/bin/false-d/usr/local/php7-m php##### #从GitHub下载php7安装包 [[email protected] ~]# wget-c--no-check-certificate-o php7-src-master.zip https:// github.com/php/php-src/archive/master.zip##### #开始解压php7包 [[email protected] ~]# unzip-q Php7-src-master.zip & & CD php-src-master#### #安装编译php7时需要的依赖包 [[email protected] php-src-master]# yum-y install LIBXML2 libxml2-devel OpenSSL openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel
2 configuration of PHP7 compilation parameters

Once the preparation is done, the installation details of the PHP7 are formally configured. Note that you must first remove the following backslash "\" After the comment text added!!!

##### #开始生成配置文件 [[email protected] php-src-master]#./buildconfbuildconf:checking installation...buildconf: autoconf version 2.69 (OK) rebuilding aclocal.m4rebuilding configurerebuilding main/php_config.h.in##### #开始配置 [[Email  protected] php-src-master]#./configure--prefix=/usr/local/php7 \ [PHP7 installed root directory]--exec-p REFIX=/USR/LOCAL/PHP7--bindir=/usr/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=/u              Sr/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 \ [using Opcache cache]--enable-fpm--enable-fastcgi--with-fpm-user=ngi NX \ [php-fpm user]--with-fpm-group=nginx \ [php-fpm user group]--wi THOUT-GDBM--disable-fileinfo

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

3 Start compiling and installing PHP7

Relatively compiled to install MySQL with a lot of CPU and memory consumption, PHP7 compilation and installation is much easier, the whole process about 1 hours or so.

[[email protected] php-src-master]# make clean && make && make install

See on the representative has been compiled installed php7!

4 Optional steps: Execute the Make Test command to test

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

The interesting thing is that during test, a TCP connection is established with an IP address 72.52.91.14, which corresponds to the PHP website http://www.php.net.

After executing the make test command, the final result is as follows:

5 Viewing the PHP7 installation directory after 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-20141001/) in particular. You need to make sure that there are at least mysqli.so pdo_mysql.so two dynamic library files, as shown in.

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

Can be copied to the PHP7 configuration directory (/usr/local/php7/etc/) with the compiled configuration file, recommended using the configuration of PHP.ini, PHP-FPM, and www.conf in PHP7 The 3 PHP7 configuration files and PHP-FPM service control scripts are organized in this article.

###### #方法一: Direct use of post-compilation configuration without optimization [[email protected] php-src-master]# CP php.ini-production/usr/local/php7/etc/php.ini[[ Email protected] php-src-master]# Cp/root/php-src-master/sapi/fpm/init.d.php-fpm/etc/init.d/php-fpm[[email Protected] php-src-master]# Cp/usr/local/php7/etc/php-fpm.conf.default/usr/local/php7/etc/php-fpm.conf[[email Protected] php-src-master]# cp/usr/local/php7/etc/php-fpm.d/www.conf.default/usr/local/php7/etc/php-fpm.d/ www.conf###### #方法二: Use the configuration in https://typecodes.com/web/php7configure.html [[email protected] php-src-master]# MV ~/ Php.ini/usr/local/php7/etc/php.ini && MV ~/php-fpm/etc/init.d/php-fpm[[email protected] php-src-master]# MV ~ /php-fpm.conf/usr/local/php7/etc/php-fpm.conf && MV ~/www.conf/usr/local/php7/etc/php-fpm.d/www.conf
7 adding environment Variables for PHP

Add the bin directory generated by the PHP compilation to the environment variables of the current Linux system

[[Email protected] ~] # echo-e ' \nexport path=/usr/local/php7/bin:/usr/local/php7/sbin:$PATH\ n ' >>/etc/profile && source/etc/profile    
8 Set PHP log directory and PHP-FPM process files (php-fpm.sock) directory

Where, set the user and user groups of the PHP-FPM process directory as nginx , and create the Session directory for PHP sessions.

###### #设置PHP日志目录和php-FPM Run Process ID file (php-fpm.sock) directory [[email protected] ~]# mkdir-p/var/log/php-fpm/&& mkdir-p /VAR/RUN/PHP-FPM && cd/var/run/&& chown-r nginx:nginx php-fpm###### #修改session的目录配置 [[email protected] etc]# mkdir-p/var/lib/php/session[[email protected] etc]# chown-r nginx:nginx/var/lib/php
9 Set PHP boot up and test configuration files correctly
##### #配置开机自启动, add to host SYSV service [[email protected] php-src-master]# chmod +x/etc/init.d/php-fpm[[email protected] php-src-master]# chkconfig--add php-fpm[[email protected] php-src-master]# chkconfig php-fpm on##### #测试PHP的配置文件是否正确合法 [Email protected] sbin]# php-fpm-t[03-may-2015 17:50:04] notice:configuration file/usr/local/php7/etc/php-fpm.conf Test is successful
10 Starting the PHP service

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

[[Email protected] sbin]# service php-fpm startstarting php-fpm done  

The command can then be used to ps -aux|grep php 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):

11 Viewing PHP7 version information

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

CentOS 7.1 Compilation Installation PHP7

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.