Create a user named php with no logon permission and a user group named php to create php users and user groups
First, create a user named php with no logon permission and a user group named php.
####### Create a php user and a php Group [root @ localhost ~] # Groupadd-r php & useradd-r-g php-s/bin/false-d/usr/local/php7-M php
Compile and install the dependencies required by php 7
Compile and install the libmcrypt, mhash, and mcrypt binary source code packages
The reason for compiling and installing libmcrypt is that the yum installation may report an error.
###### Compile and install the libmcrypt-2.5.7 [root @ localhost ~] # Tar libmcrypt-2.5.7.tar.gz zxvf [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 co libmcrypt-2.5.7 *
###### Compile and install the 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 co mhash-0.9.9.9 *
###### Compile and install the 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 co mcrypt-2.6.8 *
###### Install [root @ localhost ~] with other yum dependencies # Yum-y install libxml2 libxml2-devel openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel
PHP 7 compilation parameter configuration
Note: you must first remove the comments added after the backslash !!!
###### Generate the configuration file [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 ##### start to configure [root @ localhost php-7.0.0] #. /configure \ -- prefix =/usr/local/php7 \ [root directory for 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 \ [PHP7 configuration Directory] -- with-mysql-sock =/var/run/mysql. sock \ [PHP7 Unix socket communication file] -- with-mcrypt =/usr/include \ -- with-mhash \ -- with-openssl \ -- with-mysql = shared, mysqlnd \ [PHP7 dependent mysql database] -- with-mysqli = shared, mysqlnd \ [PHP7 dependent mysql database] -- with-pdo-mysql = shared, mysqlnd \ [PHP7 dependent mysql database] -- 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] -- with-curl \ [allow curl extension] -- 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 execution result of the preceding configuration command is as follows:
Start setting the PHP7 configuration file php. ini, php-fpm.conf, www. conf, and php-fpm script
You can copy the compiled configuration file to the PHP7 configuration Directory (/usr/local/php7/etc/). We recommend that you use the configuration in github. This configuration comes from php. ini, php-fpm, and www. conf in PHP7.
####### Method 1: directly use the configuration without optimization after 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-f Pm. d/www. conf ###### Method 2: Use https://github.com/lizer2014/mylnmp/tree/master/php to configure the [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 & mv ~ /Www. conf/usr/local/php7/etc/php-fpm.d/www. conf
Note: You need to modify the parameter in the php. ini configuration, and change extension_dir to your own
extension_dir = "/usr/local/php7/lib/php/extensions/no-debug-non-zts-20151012/"
In the/etc/init. the make/var/run/php-fpm command must be run before the Daemon of the start function in d/php-fpm; otherwise, restart the server will cause startup failure, and the configuration in nginx will also cause this problem.
Add php environment variables
[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 PHP log directory and php-fpm process file (php-fpm.sock) Directory
Set the user and user group of the php-fpm process directory to nginx and create the php session directory.
####### Set the PHP log directory and the php-fpm running 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 ####### modify the session directory configuration [root @ localhost run] # mkdir-p/var/lib/php/session [root @ localhost run] # chown-R nginx: nginx/var/lib/php
Set PHP startup and test whether the configuration file is correct
###### Configure automatic startup and add it to the 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 ##### test PHP configuration whether the file is correct and legal [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 the php service
After completing the above operations, you can officially use the php service. The command to start the php process service is as follows:
[root@localhost init.d]# service php-fpm startStarting php-fpm done
Then you can run the ps-aux | grep php command to check whether the process is successful (the number of php-fpm processes in the figure and the nginx of the process user are both composed of www. pm in conf. start_servers and user values are determined respectively ):
Related articles:
Mac uses its own installed php by default
Centos6.7 php7 installation details
Describes how to install the php environment in Linux and Configure Nginx to support the php-fpm module)
The above is a detailed description of the sample code (figure) for compiling and installing PHP 7 in CentOS7. For more information, see other related articles in the first PHP community!