CentOS 7.1 Compile and install php7____php

Source: Internet
Author: User
Tags configuration php fpm openssl php session php error php error log php website zend
1 Create PHP users and user groups, and download PHP7 source code in GitHub

First create a user named PHP with no logon 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 libpng-devel freetype-devel Libmcrypt-devel
2 Configuration of PHP7 compilation parameters

After the preparation is done, the formal configuration of the PHP7 installation details is started. Note that the operation must first be the following backslash "\" added after the annotation text removed ...

##### #开始生成配置文件 [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 p hp-src-master]#./configure \--prefix=/usr/local/php7 \ [PHP7 installed root directory]--exec-prefix=/usr/loca L/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=/usr/include \ --with-mhash \--with-openssl \--with-mysql=shared,mysqlnd \ [PHP7 dependent MySQL library]--wit                       H-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 \--ena Ble-xml \--enable-bcmath \--enable-shmop \--enable-sysvsem \--enable-mbregex \--enable-mbstring \--enable-ftp \--en 
Able-gd-native-ttf \--enable-pcntl \--enable-sockets \--with-xmlrpc \--enable-soap \--without-pear \--with-gettext \                                           --enable-session \ [Allow PHP session sessions]--with-curl \ [Allow curl extensions]--with-jpeg-dir \--with-freetype-dir \--enable-opcache \ [Use OPCA Che cache]--enable-fpm \--enable-fastcgi \--with-fpm-user=nginx \ [PHP-FPM users]--with-fpm-g
 Roup=nginx \ [php-fpm user Group]--without-gdbm \--disable-fileinfo

The result of executing the configuration command above is shown in the following illustration:

3 start compiling and installing PHP7

Compared to compiling a large amount of CPU and memory consumption to install MySQL, PHP7 's compilation installation is much easier and the whole process is about 1 hours.

[Root@typecodes php-src-master]# make && make && make install

See the following figure on behalf of the compiler has been installed PHP7.

4 Optional steps: Execute the Make Test command for testing

This is an unnecessary procedure to perform 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.

When you finish executing the make Test command, the final result is as follows:

5 View the PHP7 installation directory after successful compilation

Because of the need to communicate with MySQL, you need to specifically view the Lib Extended Library directory (/USR/LOCAL/PHP7/LIB/PHP/EXTENSIONS/NO-DEBUG-NON-ZTS-20141001/) after the PHP7 installation. You need to ensure that there are at least two dynamic library files mysqli.so, pdo_mysql.so, as shown in the following illustration.

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

You can copy the compiled configuration file to the PHP7 configuration directory (/usr/local/php7/etc/) and recommend that you use the configuration of PHP.ini, PHP-FPM, and www.conf in PHP7 The 3 PHP7 configuration files and PHP-FPM service control scripts are sorted out in this paper.

###### #方法一: Direct use of a configuration that is not optimized after compilation
[Root@typecodes php-src-master]# CP Php.ini-production/usr/local/php7/etc/php.ini
[root@typecodes php-src-master]# cp/root/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 https://typecodes.com/web/php7configure.html 
[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 PHP's Environment variables

Add the PHP build-generated Bin directory to the current Linux system's environment variables

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

The user and user groups that set up the PHP-FPM process directory are nginx and the PHP session sessions directory 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/&& chown-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 up PHP startup and test configuration file is correct
##### #配置开机自启动, 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
###### Test whether PHP's configuration file is valid
[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 completing the above operation, you can formally use the PHP service. The command to start the PHP process service is as follows:

[Root@typecodes sbin]# Service php-fpm start
starting php-fpm  done

You can then use the command ps-aux|grep PHP to see if the success (the number of PHP-FPM processes and process user Nginx in the figure is determined by the values of pm.start_servers and user in www.conf respectively):

11 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 is added to the zend_extension=opcache.so file.

According to the previous configure compilation parameters set, the PHP7 configuration file after installation path is/usr/local/php7/etc. There will be two profiles in this directory: Php-fpm.conf and PHP.ini, and a folder PHP-FPM.D (containing www.conf files).

Therefore, this article mainly on these three PHP configuration files are briefly described, the specific configuration process is shown in the appendix at the end of this article.

1 configuration php.ini

PHP.ini is the core configuration file for PHP running:

##### #避免PHP信息暴露在http头中
expose_php = off

##### #避免暴露php调用mysql的错误信息
display_errors = off

###### Open the PHP error log after the display_errors is turned off (the path is configured in php-fpm.conf)
log_errors = on

##### #设置PHP的扩展库路径
extension_dir = "/ usr/local/php7/lib/php/extensions/no-debug-non-zts-20141001/"

##### #设置PHP的opcache和mysql动态库
zend_ extension=opcache.so
extension=mysqli.so
extension=pdo_mysql.so

##### #设置PHP的时区
Date.timezone = PRC

##### #开启opcache
[Opcache]
; Determines if Zend opcache is enabled
opcache.enable=1

##### #设置PHP脚本允许访问的目录 (needs to be configured according to the actual situation)
; Open_ Basedir =/usr/share/nginx/html;

2 Configuration php-fpm.conf

Php-fpm.conf is the configuration file for the PHP-FPM process service:

##### #设置错误日志的路径
error_log =/var/log/php-fpm/error.log
##### configuration in #引入www. conf file
include=/usr/local/ Php7/etc/php-fpm.d/*.conf

3 Configuration www.conf (under PHP-FPM.D directory)

Www.conf This is the extended configuration file for the PHP-FPM process service:

##### #设置用户和用户组
user = Nginx
group = nginx

##### configuration in #根据nginx. conf fastcgi_pass Php-fpm.sock; set up PHP monitor
listen = 127.0.0.1:9000   # #不建议使用
listen =/var/run/php-fpm/php-fpm.sock

# ### #开启慢日志
slowlog =/var/log/php-fpm/$pool-slow.log
request_slowlog_timeout = 10s

###### Set PHP's Session directory (both user and user group are nginx)
Php_value[session.save_handler] = files
Php_value[session.save_path] = /var/lib/php/session

4 Appendix

As already explained in the previous article, all of this configuration on Nginx, MySQL, and PHP is currently hosted on GitHub and Coding.net, with the following addresses:

GitHub address: HTTPS://GITHUB.COM/VFHKY/MYLNMP;

Coding Address: Https://coding.net/u/vfhky/p/mylnmp/git.

Article Source: http://www.tuicool.com/articles/NjmQNj6

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.