CentOS 71 compile and install PHP7

Source: Internet
Author: User
Tags mcrypt php compiler php website
1 Create PHP users and user groups, and download PHP7 source on GitHub
First create a user named PHP with no login rights and a user group named PHP, and then go to GitHub to download the PHP7 source package.
###### #新建php用户和php组
[Root@typecodes ~]# groupadd-r php && useradd-r-G php-s/bin/false-d/usr/local/php7-m php
##### #从GitHub下载php7安装包
[Root@typecodes ~]# wget-c--no-check-certificate-o php7-src-master.zip https://github.com/php/php-src/archive/ Master.zip
##### #开始解压php7包
[Root@typecodes ~]# unzip-q php7-src-master.zip && cd Php-src-master
# # # #安装编译php7时需要的依赖包
[Root@typecodes php-src-master]# yum-y install libxml2 libxml2-devel OpenSSL openssl-devel curl-devel libjpeg-devel LIBP Ng-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!!!
##### #开始生成配置文件
[Root@typecodes php-src-master]#./buildconf
Buildconf:checking installation ...
buildconf:autoconf version 2.69 (OK)
Rebuilding ACLOCAL.M4
Rebuilding configure
Rebuilding main/php_config.h.in
##### #开始配置
[Root@typecodes php-src-master]#./configure \
--PREFIX=/USR/LOCAL/PHP7 \ [root directory of PHP7 installation]
--EXEC-PREFIX=/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 \ [configuration directory of PHP7]
--with-mysql-sock=/var/run/mysql/mysql.sock \ [PHP7 UNIX socket communication file]
--with-mcrypt=/usr/include \
--with-mhash \
--WITH-OPENSSL \
--WITH-MYSQLI=SHARED,MYSQLND \ [PHP7 dependent MySQL library]
--WITH-PDO-MYSQL=SHARED,MYSQLND \ [PHP7 dependent 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 sessions session]
--with-curl \ [Allow Curl extension]
--with-jpeg-dir \
--with-freetype-dir \
--enable-opcache=no \ [using Opcache cache]
--ENABLE-FPM \
--with-fpm-user=nginx \ [user of php-fpm]
--with-fpm-group=nginx \ [php-fpm user Group]
--WITHOUT-GDBM \
--disable-fileinfo
Copy the following run directly
./configure--PREFIX=/USR/LOCAL/PHP7--EXEC-PREFIX=/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--with-mysql-sock=/var/run/mysql/mysql.sock--with-mcrypt=/ Usr/include--with-mhash--with-openssl--with-mysqli=shared,mysqlnd--with-pdo-mysql=shared,mysqlnd--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--with-curl--with-jpeg-dir--with-freetype-dir--enable-opcache=no--enable-fpm--with-fpm-user= Nginx--with-fpm-group=nginx--without-gdbm--disable-fileinfo
Error message: Configure:error:mcrypt.h not found. Please reinstall Libmcrypt
Workaround: Download libmcrypt-2.5.8.tar.gz and compile the installation
Download Address: http://sourceforge.net/projects/mcrypt/files/Libmcrypt/
If you recompile the Libmcrypt remember the installation directory, then the PHP compiler entry--with-mcrypt= your Libmcrypt installation directory
./configure--PREFIX=/USR/LOCAL/PHP7--EXEC-PREFIX=/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--with-mysql-sock=/var/run/mysql/mysql.sock--with-mcrypt=/ usr/local/libmcrytp/--with-mhash--with-openssl--with-mysqli=mysqlnd--with-pdo-mysql=mysqlnd--WITH-GD-- With-iconv--with-zlib--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-- With-curl--with-jpeg-dir--with-freetype-dir--enable-opcache--enable-fpm--with-fpm-user=nginx--with-fpm-group= Nginx--without-gdbm--disable-fileinfo
A problem was encountered at compile time: Don ' t know how to define struct flock on the This system, set--enable-opcache=no
Workaround: (I end up with these methods still not solved)
First, yum Groupinstall "Development Tools".
Second, the editor/etc/ld.so.conf joins the/usr/local/lib, in executes the ldconfig-v
Hint: I see libmysqlclient.so in/usr/lib, so when I edit/etc/ld.so.conf, I need to see if there exists this
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.
At compile time, the--enable-opcache=no set to No, remove the--enable-zip, where the installation is completed, you need to separate the two as an extension installation
[Root@typecodes php-src-master]# make clean && make && make install
If you encounter an error, refer to: http://blog.chinaunix.net/uid-20776139-id-5421615.html
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.
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 two dynamic library files of mysqli.so, pdo_mysql.so.
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.
###### #方法一: Directly using a configuration that has not been optimized for compilation
[Root@typecodes php-src-master]# CP Php.ini-production/usr/local/php7/etc/php.ini
[Root@typecodes php-src-master]# CP/PHP-SRC-MASTER/SAPI/FPM/INIT.D.PHP-FPM/ETC/INIT.D/PHP-FPM
[Root@typecodes php-src-master]# cp/usr/local/php7/etc/php-fpm.conf.default/usr/local/php7/etc/php-fpm.conf
[Root@typecodes php-src-master]# cp/usr/local/php7/etc/php-fpm.d/www.conf.default/usr/local/php7/etc/php-fpm.d/ Www.conf
###### #方法二: Using the configuration in the Https://typecodes.com/web/php7configure.html article
[Root@typecodes php-src-master]# mv ~/php.ini/usr/local/php7/etc/php.ini && MV ~/PHP-FPM/ETC/INIT.D/PHP-FPM
[Root@typecodes 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
[Root@typecodes ~]# 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
The user and user groups that set the PHP-FPM process directory are Nginx, and the Session Directory for PHP sessions is created.
###### #设置PHP日志目录和php-FPM Run Process ID file (php-fpm.sock) directory
[Root@typecodes ~]# mkdir-p/var/log/php-fpm/&& mkdir-p/var/run/php-fpm && cd/var/run/&& cho Wn-r Nginx:nginx PHP-FPM
###### #修改session的目录配置
[Root@typecodes etc]# mkdir-p/var/lib/php/session
[Root@typecodes etc]# chown-r nginx:nginx/var/lib/php
9 Set PHP boot up and test configuration files correctly
##### #配置开机自启动, add to host SYSV service
[Root@typecodes php-src-master]# chmod +x/etc/init.d/php-fpm
[Root@typecodes php-src-master]# chkconfig--add php-fpm
[Root@typecodes php-src-master]# chkconfig php-fpm on
##### #测试PHP的配置文件是否正确合法
[Root@typecodes 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:
[Root@typecodes sbin]# Service php-fpm start
Starting php-fpm Done
11 Installing Opcache
Tutorial: http://blog.jjonline.cn/linux/135.html
Tutorial: http://blog.ich8.com/post/4142
Tutorial: http://my.oschina.net/u/919580/blog/406900 practice proves that this is available
Installation:
Linux
Install Zend Opcache (pecl version):
Remove Eaccelerator, XCache, APC:
Yum Remove Php-eaccelerator Php-xcache PHP-APCU
Skipped if not used.
To perform an upgrade on the system:
Yum Update
Installing Zend Opcache (pecl version)
Yum install Php-pecl-zendopcache PS: But the php-pecl-zendopcache extension is still not found on CENTOS7, so the following cannot continue
The configuration file for the Opcache generated at the time of installation is located in the default/ETC/PHP.D directory:
Opcache-default.blacklist
Opcache.ini
This configuration file is basically the recommended setting in the README, only a few places need to be modified.
Vi/etc/php.d/opcache.ini
Modify and save the following recommended configurations:
Opcache.memory_c>opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
Opcache.revalidate_freq=60
Opcache.fast_shutdown=1
Opcache.enable_cli=1
You do not need to modify the php.ini configuration to restart the Apache service for it to take effect:
Service httpd Restart
Check to see if it started correctly:
Php-v
The output is similar to the following:
PHP 7 (CLI) (built:apr 11 2013 11:04:35)
Copyright (c) 1997-2013 the PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
With Zend Opcache v7.0.1, Copyright (c) 1999-2013, by Zend Technologies

The above describes the CentOS 71 compilation installation PHP7, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • Related Article

    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.