Explain
Installation of LNMP environments usually starts with mysql/mariadb installation, followed by nginx installation, followed by php installation.
Install dependency packages
[root@localhost ~]# yum -y install gcc [root@localhost ~]# yum -y install gcc++ [root@localhost ~]# yum -y install gcc-c++ [root@localhost ~]# yum -y install wget [root@localhost ~]# yum -y install make [root@localhost ~]# yum -y install libxml2 [root@localhost ~]# yum -y install libxml2-devel [root@localhost ~]# yum -y install openssl [root@localhost ~]# yum -y install openssl-devel [root@localhost ~]# yum -y install curl-devel [root@localhost ~]# yum -y install libjpeg-devel [root@localhost ~]# yum -y install libpng-devel [root@localhost ~]# yum -y install freetype-devel [root@localhost ~]# yum -y install bison [root@localhost ~]# yum -y install autoconf
Create Users and User Groups
Create php user groups
> Establish php user group(-r Option is what it means to create a system user group) [root@localhost ~]# groupadd -r php
Create users and join the php system user group
> Adding new users > -r: Adding System Users( This refers to the system user to be created php ) > -g: Specify the user group to be created( This refers to adding users to a new system php reach php System User Group ) > -s: Login for a new account shell( `/sbin/nologin` This is set to the system user to be created php Can't be used to log in to the system ) > -d: Home directory of new account( Here you specify the system user to be created php The home directory is `/usr/local/php` ) > -M: Do not create the user's home directory( That is to say, the system user to be created php Not at all. `/home` Create under the directory `php` Home catalogue ) [root@localhost ~]# useradd -r -g php -s /sbin/nologin -d /usr/local/php -M php
Download php7.1 and unzip it
> download [root@localhost ~]# wget -c https://github.com/php/php-src/archive/php-7.1.6.tar.gz > decompression [root@localhost ~]# tar -zxvf php-7.1.6.tar.gz
Download and install php dependencies
PHP parser re2c
> download [root@localhost ~]# wget -c https://github.com/skvadrik/re2c/releases/download/0.16/re2c-0.16.tar.gz > decompression [root@localhost ~]# tar -zxvf re2c-0.16.tar.gz > Enter the decompressed source directory to compile and install [root@localhost ~]# cd re2c-0.16 [root@localhost re2c-0.16]# ./configure [root@localhost re2c-0.16]# make && make install
Encryption Support Extended Library libmcrypt
Libmcrypt must be installed before using php mcrypt
> download [root@localhost ~]# wget -c https://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz > decompression [root@localhost ~]# tar -zxvf libmcrypt-2.5.8.tar.gz > Enter the decompressed source directory to compile and install [root@localhost ~]# cd libmcrypt-2.5.8 [root@localhost libmcrypt-2.5.8]# ./configure [root@localhost libmcrypt-2.5.8]# # make && make install
Encryption Extension Library mhash
> download [root@localhost ~]# wget -c https://downloads.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz > decompression [root@localhost ~]# tar -zxvf mhash-0.9.9.9.tar.gz > Enter the decompressed source directory to compile and install [root@localhost mhash-0.9.9.9]# cd mhash-0.9.9.9 [root@localhost mhash-0.9.9.9]# ./configure [root@localhost mhash-0.9.9.9]# make && make install
Encryption Extension Library mcrypt
> download [root@localhost ~]# wget -c https://sourceforge.net/projects/mcrypt/files/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz > decompression [root@localhost ~]# tar -zxvf mcrypt-2.6.8.tar.gz > Because it is compiling mcrypt When you do, you won't find it. libmcrypt Link libraries can not be compiled because Libmcrypt Link libraries in/usr/local/lib Under folders > So, compiling mcrypt When joining LD_LIBRARY_PATH=/usr/local/lib Import indirect Libraries > Enter the decompressed source directory to compile and install [root@localhost ~# cd mcrypt-2.6.8 [root@localhost mcrypt-2.6.8]# ./configure LD_LIBRARY_PATH=/usr/local/lib [root@localhost mcrypt-2.6.8]# make && make install
Compile php7.1
By the end of the directory, all the preparations have been completed, and the next step is to compile php7.1!
View the Specific Contents of Source Directory Files
[root@localhost php-src-php-7.1.6]# ll total 1252 -rw-rw-r--. 1 root root 82506 Jun 7 04:05 acinclude.m4 drwxrwxr-x. 2 root root 78 Jun 7 04:05 appveyor drwxrwxr-x. 2 root root 4096 Jun 7 04:05 build -rwxrwxr-x. 1 root root 772 Jun 7 04:05 buildconf -rw-rw-r--. 1 root root 334 Jun 7 04:05 buildconf.bat -rw-rw-r--. 1 root root 11982 Jun 7 04:05 CODING_STANDARDS -rw-rw-r--. 1 root root 42938 Jun 7 04:05 config.guess -rw-rw-r--. 1 root root 35987 Jun 7 04:05 config.sub -rw-rw-r--. 1 root root 46774 Jun 7 04:05 configure.in -rw-rw-r--. 1 root root 3163 Jun 7 04:05 CONTRIBUTING.md -rw-rw-r--. 1 root root 91 Jun 7 04:05 CREDITS drwxrwxr-x. 75 root root 4096 Jun 7 04:05 ext -rw-rw-r--. 1 root root 20917 Jun 7 04:05 EXTENSIONS -rw-rw-r--. 1 root root 137 Jun 7 04:05 footer -rwxrwxr-x. 1 root root 581 Jun 7 04:05 genfiles -rw-rw-r--. 1 root root 1143 Jun 7 04:05 header -rw-rw-r--. 1 root root 87836 Jun 7 04:05 INSTALL -rw-rw-r--. 1 root root 3218 Jun 7 04:05 LICENSE -rw-rw-r--. 1 root root 199728 Jun 7 04:05 ltmain.sh drwxrwxr-x. 3 root root 4096 Jun 7 04:05 main -rwxrwxr-x. 1 root root 4129 Jun 7 04:05 makedist -rw-rw-r--. 1 root root 1088 Jun 7 04:05 Makefile.frag -rw-rw-r--. 1 root root 2485 Jun 7 04:05 Makefile.gcov -rw-rw-r--. 1 root root 7236 Jun 7 04:05 Makefile.global -rw-rw-r--. 1 root root 5317 Jun 7 04:05 makerpm drwxrwxr-x. 2 root root 40 Jun 7 04:05 netware -rw-rw-r--. 1 root root 135093 Jun 7 04:05 NEWS drwxrwxr-x. 2 root root 65 Jun 7 04:05 pear -rw-rw-r--. 1 root root 1489 Jun 7 04:05 php.spec.in -rw-rw-r--. 1 root root 2523 Jun 7 04:05 php.gif -rw-rw-r--. 1 root root 71064 Jun 7 04:05 php.ini-development -rw-rw-r--. 1 root root 71096 Jun 7 04:05 php.ini-production -rw-rw-r--. 1 root root 7010 Jun 7 04:05 README.EXT_SKEL -rw-rw-r--. 1 root root 5026 Jun 7 04:05 README.GIT-RULES -rw-rw-r--. 1 root root 5417 Jun 7 04:05 README.input_filter -rw-rw-r--. 1 root root 3426 Jun 7 04:05 README.MAILINGLIST_RULES -rw-rw-r--. 1 root root 1608 Jun 7 04:05 README.md -rw-rw-r--. 1 root root 6040 Jun 7 04:05 README.namespaces -rw-rw-r--. 1 root root 5237 Jun 7 04:05 README.NEW-OUTPUT-API -rw-rw-r--. 1 root root 7528 Jun 7 04:05 README.PARAMETER_PARSING_API -rw-rw-r--. 1 root root 19766 Jun 7 04:05 README.REDIST.BINS -rw-rw-r--. 1 root root 12934 Jun 7 04:05 README.RELEASE_PROCESS -rw-rw-r--. 1 root root 5086 Jun 7 04:05 README.SELF-CONTAINED-EXTENSIONS -rw-rw-r--. 1 root root 15355 Jun 7 04:05 README.STREAMS -rw-rw-r--. 1 root root 8126 Jun 7 04:05 README.SUBMITTING_PATCH -rw-rw-r--. 1 root root 6695 Jun 7 04:05 README.TESTING -rw-rw-r--. 1 root root 4958 Jun 7 04:05 README.TESTING2 -rw-rw-r--. 1 root root 4261 Jun 7 04:05 README.UNIX-BUILD-SYSTEM -rw-rw-r--. 1 root root 109 Jun 7 04:05 README.WIN32-BUILD-SYSTEM -rwxrwxr-x. 1 root root 82234 Jun 7 04:05 run-tests.php drwxrwxr-x. 10 root root 4096 Jun 7 04:05 sapi drwxrwxr-x. 4 root root 99 Jun 7 04:05 scripts -rwxrwxr-x. 1 root root 2104 Jun 7 04:05 server-tests-config.php -rwxrwxr-x. 1 root root 52726 Jun 7 04:05 server-tests.php -rwxrwxr-x. 1 root root 108 Jun 7 04:05 snapshot -rw-rw-r--. 1 root root 10 Jun 7 04:05 stamp-h.in -rw-rw-r--. 1 root root 1 Jun 7 04:05 stub.c drwxrwxr-x. 10 root root 4096 Jun 7 04:05 tests drwxrwxr-x. 3 root root 33 Jun 7 04:05 travis drwxrwxr-x. 3 root root 4096 Jun 7 04:05 TSRM -rw-rw-r--. 1 root root 23356 Jun 7 04:05 UPGRADING -rw-rw-r--. 1 root root 3418 Jun 7 04:05 UPGRADING.INTERNALS -rwxrwxr-x. 1 root root 159 Jun 7 04:05 vcsclean drwxrwxr-x. 3 root root 4096 Jun 7 04:05 win32 drwxrwxr-x. 4 root root 4096 Jun 7 04:05 Zend
You can see that there is no configuration file in the directory, but there is a file named buildconf.
Well, that's it. We need to run this file to generate the configuration file.
Generate the configuration file configure in the php source directory
> Function `buildconf` file, generate `configure` file [root@localhost php-src-php-7.1.6]# ./buildconf You should not run buildconf in a release package. use buildconf --force to override this check. > Unfortunately, It didn't succeed., And prompt: You should not run buildconf in a release package. # You shouldn't run the buildconf file in the distribution package. use buildconf --force to override this check. # Rewrite this check using the buildconf file. > Then join it according to its requirements. `--force` Option rewrite check [root@localhost php-src-php-7.1.6]# ./buildconf --force Forcing buildconf Removing configure caches buildconf: checking installation... buildconf: autoconf version 2.69 (ok) rebuilding aclocal.m4 rebuilding configure rebuilding main/php_config.h.in > This time it's kind of like buildconf File rewrite checks succeeded, Look at the source directory. `configure` file
The directory after the source directory configuration file is generated
[root@localhost php-src-php-7.1.6]# ll total 4260 -rw-rw-r--. 1 root root 82506 Jun 7 04:05 acinclude.m4 -rw-r--r--. 1 root root 312883 Jun 18 04:43 aclocal.m4 drwxrwxr-x. 2 root root 78 Jun 7 04:05 appveyor drwxr-xr-x. 2 root root 51 Jun 18 04:43 autom4te.cache drwxrwxr-x. 2 root root 4096 Jun 7 04:05 build -rwxrwxr-x. 1 root root 772 Jun 7 04:05 buildconf -rw-rw-r--. 1 root root 334 Jun 7 04:05 buildconf.bat -rw-r--r--. 1 root root 0 Jun 18 04:43 buildmk.stamp -rw-rw-r--. 1 root root 11982 Jun 7 04:05 CODING_STANDARDS -rw-rw-r--. 1 root root 42938 Jun 7 04:05 config.guess -rw-rw-r--. 1 root root 35987 Jun 7 04:05 config.sub -rwxr-xr-x. 1 root root 2758685 Jun 18 04:43 configure -rw-rw-r--. 1 root root 46774 Jun 7 04:05 configure.in -rw-rw-r--. 1 root root 3163 Jun 7 04:05 CONTRIBUTING.md -rw-rw-r--. 1 root root 91 Jun 7 04:05 CREDITS drwxrwxr-x. 75 root root 4096 Jun 7 04:05 ext -rw-rw-r--. 1 root root 20917 Jun 7 04:05 EXTENSIONS -rw-rw-r--. 1 root root 137 Jun 7 04:05 footer -rw-r--r--. 1 root root 1776 Jun 18 04:43 generated_lists -rwxrwxr-x. 1 root root 581 Jun 7 04:05 genfiles -rw-rw-r--. 1 root root 1143 Jun 7 04:05 header -rw-rw-r--. 1 root root 87836 Jun 7 04:05 INSTALL -rw-r--r--. 1 root root 0 Jun 18 04:43 install-sh -rw-rw-r--. 1 root root 3218 Jun 7 04:05 LICENSE -rw-rw-r--. 1 root root 199728 Jun 7 04:05 ltmain.sh drwxrwxr-x. 3 root root 4096 Jun 18 04:43 main -rwxrwxr-x. 1 root root 4129 Jun 7 04:05 makedist -rw-rw-r--. 1 root root 1088 Jun 7 04:05 Makefile.frag -rw-rw-r--. 1 root root 2485 Jun 7 04:05 Makefile.gcov -rw-rw-r--. 1 root root 7236 Jun 7 04:05 Makefile.global -rw-rw-r--. 1 root root 5317 Jun 7 04:05 makerpm -rw-r--r--. 1 root root 0 Jun 18 04:43 missing -rw-r--r--. 1 root root 0 Jun 18 04:43 mkinstalldirs drwxrwxr-x. 2 root root 40 Jun 7 04:05 netware -rw-rw-r--. 1 root root 135093 Jun 7 04:05 NEWS drwxrwxr-x. 2 root root 65 Jun 7 04:05 pear -rw-rw-r--. 1 root root 1489 Jun 7 04:05 php7.spec.in -rw-rw-r--. 1 root root 2523 Jun 7 04:05 php.gif -rw-rw-r--. 1 root root 71064 Jun 7 04:05 php.ini-development -rw-rw-r--. 1 root root 71096 Jun 7 04:05 php.ini-production -rw-rw-r--. 1 root root 7010 Jun 7 04:05 README.EXT_SKEL -rw-rw-r--. 1 root root 5026 Jun 7 04:05 README.GIT-RULES -rw-rw-r--. 1 root root 5417 Jun 7 04:05 README.input_filter -rw-rw-r--. 1 root root 3426 Jun 7 04:05 README.MAILINGLIST_RULES -rw-rw-r--. 1 root root 1608 Jun 7 04:05 README.md -rw-rw-r--. 1 root root 6040 Jun 7 04:05 README.namespaces -rw-rw-r--. 1 root root 5237 Jun 7 04:05 README.NEW-OUTPUT-API -rw-rw-r--. 1 root root 7528 Jun 7 04:05 README.PARAMETER_PARSING_API -rw-rw-r--. 1 root root 19766 Jun 7 04:05 README.REDIST.BINS -rw-rw-r--. 1 root root 12934 Jun 7 04:05 README.RELEASE_PROCESS -rw-rw-r--. 1 root root 5086 Jun 7 04:05 README.SELF-CONTAINED-EXTENSIONS -rw-rw-r--. 1 root root 15355 Jun 7 04:05 README.STREAMS -rw-rw-r--. 1 root root 8126 Jun 7 04:05 README.SUBMITTING_PATCH -rw-rw-r--. 1 root root 6695 Jun 7 04:05 README.TESTING -rw-rw-r--. 1 root root 4958 Jun 7 04:05 README.TESTING2 -rw-rw-r--. 1 root root 4261 Jun 7 04:05 README.UNIX-BUILD-SYSTEM -rw-rw-r--. 1 root root 109 Jun 7 04:05 README.WIN32-BUILD-SYSTEM -rwxrwxr-x. 1 root root 82234 Jun 7 04:05 run-tests.php drwxrwxr-x. 10 root root 4096 Jun 7 04:05 sapi drwxrwxr-x. 4 root root 99 Jun 7 04:05 scripts -rwxrwxr-x. 1 root root 2104 Jun 7 04:05 server-tests-config.php -rwxrwxr-x. 1 root root 52726 Jun 7 04:05 server-tests.php -rwxrwxr-x. 1 root root 108 Jun 7 04:05 snapshot -rw-rw-r--. 1 root root 10 Jun 7 04:05 stamp-h.in -rw-rw-r--. 1 root root 1 Jun 7 04:05 stub.c drwxrwxr-x. 10 root root 4096 Jun 7 04:05 tests drwxrwxr-x. 3 root root 33 Jun 7 04:05 travis drwxrwxr-x. 3 root root 4096 Jun 7 04:05 TSRM -rw-rw-r--. 1 root root 23356 Jun 7 04:05 UPGRADING -rw-rw-r--. 1 root root 3418 Jun 7 04:05 UPGRADING.INTERNALS -rwxrwxr-x. 1 root root 159 Jun 7 04:05 vcsclean drwxrwxr-x. 3 root root 4096 Jun 7 04:05 win32 drwxrwxr-x. 4 root root 4096 Jun 7 04:05 Zend
Now there are configure files in the source directory
Formal compilation of php7.1
If you use this list of compilation options, remove the comments behind the backslash, and no blank characters can follow.
[root@localhost php-src-php-7.1.6]# ./configure \ --prefix=/usr/local/php \ [php Installation root directory] --exec-prefix=/usr/local/php \ [php The directory where the execution file is located] --bindir=/usr/local/php/bin \ [php/bin Catalog] --sbindir=/usr/local/php/sbin \ [php/sbin Catalog] --includedir=/usr/local/php/include \ [php Contains the directory where the file is located] --libdir=/usr/local/php/lib/php \ [php/lib Catalog] --mandir=/usr/local/php/php/man \ [php/man Catalog] --with-config-file-path=/usr/local/php/etc \ [php Configuration directory] --with-mysql-sock=/var/run/mysql/mysql.sock \ [php Of Unix socket Communication files] --with-mcrypt \ [yes php The key cryptographic support extended libraries. linux The library does not open by default in the environment] --with-mhash \ [Mhash Non-reversible based on the principle of Discrete Mathematics php Encryption extends the library, which does not open by default] --with-openssl \ [OpenSSL Is a Secure Socket Layer Cryptographic Library] --with-mysqli=shared,mysqlnd \ [php rely on mysql library] --with-pdo-mysql=shared,mysqlnd \ [php rely on mysql library] --with-gd \ [gd library] --with-iconv \ [Close iconv Function, Conversion between Character Sets] --with-zlib \ [zlib Function library for data compression] --enable-zip \ [Open the pair zip Support] --enable-inline-optimization \ [Optimizing Threads] --disable-debug \ [Close debugging mode] --disable-rpath \ [Close additional runtime files] --enable-shared \ [Enabling dynamic libraries] --enable-xml \ [open xml extend] --enable-bcmath \ [Open Picture Size Adjustment,be used zabbix This module is used for monitoring] --enable-shmop \ [Shared memory] --enable-sysvsem \ [Memory Sharing Scheme] --enable-mbregex \ [Open character encoding for multi-byte regular expressions.] --enable-mbstring \ [Open multibyte string functions] --enable-ftp \ [open ftp] --enable-gd-native-ttf \ [open gd Library original font] --enable-pcntl \ [PHP Implementation of process control support Unix Multiprocess Creation in Mode] --enable-sockets \ [Open Suite Words] --with-xmlrpc \ [open xml-rpc Of c language] --enable-soap \ [Open Simple Object Access Protocol Simple Object Access Protocol] --without-pear \ [open php Extension and Application Library] --with-gettext \ [Open account php Find messages in the current domain] --enable-session \ [allow php Conversation session] --with-curl \ [allow curl extend] --with-jpeg-dir \ [Appoint jpeg Installation directory yum It will be found automatically without re-specifying after installation] --with-freetype-dir \ [Appoint freetype Installation directory yum It will be found automatically without re-specifying after installation] --enable-opcache \ [Open Use opcache cache] --enable-fpm \ [open fpm] --with-fpm-user=nginx \ [php-fpm Users] --with-fpm-group=nginx \ [php-fpm User groups] --without-gdbm \ [Database functions use extensible hashes and are similar to standards UNIX dbm Work] --enable-fast-install \ [Optimize for Fast Installation] --disable-fileinfo
There may be an error prompt asking to open -- enable-opcache=on
> Error prompt configure: error: Don't know how to define struct flock on this system, set --enable-opcache=no > Solutions Edit/etc/ld.so.conf Join / usr/local/lib Execute ldconfig to reload it once
Run make test
This step is not necessary. If you want to run it, it may keep you waiting for a long time.
Function
[root@localhost php-src-php-7.1.6]# make test
Result
You may have found a problem in PHP. This report can be automatically sent to the PHP QA team at http://qa.php.net/reports and http://news.php.net/php.qa.reports This gives us a better understanding of PHP's behavior. If you don't want to send the report immediately you can choose option "s" to save it. You can then email it to qa-reports@lists.php.net later. Do you want to send this report now? [Yns]: Y Please enter your email address. (Your address will be mangled so that it will not go out on any mailinglist in plain text): warnerwu@126.com Posting to http://qa.php.net/buildtest-process.php Thank you for helping to make PHP better.
This result makes test complete!
Compile and install the php directory
[root@localhost php-src-php-7.1.6]# ll /usr/local/php total 0 drwxr-xr-x. 2 root root 100 Jun 18 05:57 bin drwxr-xr-x. 3 root root 49 Jun 18 05:57 etc drwxr-xr-x. 3 root root 16 Jun 18 05:57 include drwxr-xr-x. 3 root root 16 Jun 18 05:57 lib drwxr-xr-x. 4 root root 26 Jun 18 05:57 php drwxr-xr-x. 2 root root 20 Jun 18 05:57 sbin drwxr-xr-x. 4 root root 26 Jun 18 05:57 var
Configure php
Modify the php configuration file to add the php configuration file
> take php Under the source code compilation directory `php.ini-production` copy to php Installation directory `etc` Under the catalogue [root@localhost php-src-php-7.1.6]# cp php.ini-production /usr/local/php/etc/php.ini
Modify the php configuration file. Modify the location of the php extension directory
> modify `php.ini` configuration file, Set up php Extended installation directory location [root@localhost php-src-php-7.1.6]# vim /usr/local/php/etc/php.ini > find `extension_dir` Modify the extended directory location as follows: extension_dir = "../lib/php/extensions/no-debug-non-zts-20160303/" > The location of the extended directory described above is used `Relative Path` Of course, you can also use it. `Absolute Path` as: extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20160303/"
Modify the time zone of the server where the php configuration file is modified
> modify `php.ini` configuration file, Set up php Installed server time zone [root@localhost php-src-php-7.1.6]# vim /usr/local/php/etc/php.ini > find `timezone` Modify the time zone as follows: date.timezone = PRC > PRC It's English. People's Republic of China, You should know that.! The People's Republic of China
Add php-fpm management related configuration files to the system configuration directory / etc/init.d
> take php Under the source code compilation directory `sapi/fpm/init.d.php-fpm` File Copy to System Configuration `/etc/init.d` Subdirectory renamed `php-fpm` [root@localhost php-src-php-7.1.6]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
Add php-fpm configuration file
> take php Installation directory `/usr/local/php/etc/php-fpm.conf.default` Copy files in the same directory and rename them `php-fpm.conf` [root@localhost php-src-php-7.1.6]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
Add www.conf configuration file
> take php Installation directory `/usr/local/php/etc/php-fpm.d/www.conf.default` Copy files in the same directory and rename them `www.conf` [root@localhost php-src-php-7.1.6]# cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
Add php installation directory to system environment variables
> Create and open files php.sh [root@localhost php-src-php-7.1.6]# vim /etc/profile.d/php.sh > Add the following: export PATH=$PATH:/usr/local/php/bin/:/usr/local/php/sbin/ > Save and exit :wq! > Use source Effective immediately, just added php environment variable [root@localhost php-src-php-7.1.6]# source /etc/profile.d/php.sh
Set up the PHP log directory and the ID file directory of the php-fpm running process
The ID file of the running process of php-fpm is php-fpm.sock.
The users and user groups that set the php-fpm process directory are nginx.
Since I created it when I installed nginx, I won't create it here, just enumerate it.
> Adding System User Groups nginx (If you haven't created a system user group nginx Please create) [root@localhost php-src-php-7.1.6]# groupadd -r nginx > Create new system users nginx, And add to the system user group nginx, Settings do not allow this user name to log in shell (If you haven't created a system user nginx Please create) [root@localhost php-src-php-7.1.6]# useradd -r -g nginx -s /sbin/nologin -d /usr/local/nginx -M nginx > Explain how to create system users above nginx What does the option mean? -r: Adding System Users( This refers to the system user to be created nginx ) -g: Specify the user group to be created( This refers to adding users to a new system nginx reach nginx System User Group ) -s: Login for a new account shell( `/sbin/nologin` This is set to the system user to be created nginx Can't be used to log in to the system ) -d: Home directory of new account( Here you specify the system user to be created nginx The home directory is `/usr/local/nginx` ) -M: Do not create the user's home directory( That is to say, the system user to be created nginx Not at all. `/home` Create under the directory `nginx` Home catalogue ) > Establish `php-fpm` Log directory [root@localhost php-src-php-7.1.6]# mkdir -p /var/log/php-fpm/ > Establish `php-fpm` Progressive ID(php-fpm.sock)File Running Directory [root@localhost php-src-php-7.1.6]# mkdir -p /var/run/php-fpm > modify `php-fpm` Progressive ID(php-fpm.sock)Users and Groups of File Running Directory [root@localhost php-src-php-7.1.6]# chown -R nginx:nginx /var/run/php-fpm/
Modify session directory configuration
> Establish `session` Storage catalogue [root@localhost php-src-php-7.1.6]# mkdir -p /var/lib/php/session > modify `session` Users and groups that store directories [root@localhost php-src-php-7.1.6]# chown -R nginx:nginx /var/lib/php > Revision again `php.ini` file [root@localhost php-src-php-7.1.6]# vim /usr/local/php/etc/php.ini > find `session.save_path` Modified to the following: session.save_path = "/var/lib/php/session" > Save and exit :wq!
Set php boot-up
> Modify the system configuration directory `php-fpm` File executable permissions [root@localhost php-src-php-7.1.6]# chmod +x /etc/init.d/php-fpm > Configure the system under the directory `php-fpm` add to `system service` [root@localhost php-src-php-7.1.6]# chkconfig --add php-fpm > Set up `php-fpm` `system service` Start for startup [root@localhost php-src-php-7.1.6]# chkconfig php-fpm on
Check whether php-fpm system service started successfully
> use chkconfig Command to check if the service is running successfully [root@localhost php-src-php-7.1.6]# chkconfig --list | grep php-fpm Note: This output shows SysV services only and does not include native systemd services. SysV configuration data might be overridden by native systemd configuration. If you want to list systemd services use 'systemctl list-unit-files'. To see services enabled on particular target use 'systemctl list-dependencies [target]'. php-fpm 0:off 1:off 2:on 3:on 4:on 5:on 6:off > It can be seen that the service has been opened at runtime Level 2 to 5. > You can also disable it. `php-fpm` Start-up [root@localhost php-src-php-7.1.6]# chkconfig php-fpm off > use chkconfig Command to check if the service is running successfully [root@localhost php-src-php-7.1.6]# chkconfig --list | grep php-fpm Note: This output shows SysV services only and does not include native systemd services. SysV configuration data might be overridden by native systemd configuration. If you want to list systemd services use 'systemctl list-unit-files'. To see services enabled on particular target use 'systemctl list-dependencies [target]'. php-fpm 0:off 1:off 2:off 3:off 4:off 5:off 6:off > It can be seen that the service has been shut down at runtime Level 2 to 5.
Testing PHP configuration file is correct
[root@localhost php-src-php-7.1.6]# php-fpm -t [18-Jun-2017 13:02:33] NOTICE: configuration file /usr/local/php/etc/php-fpm.conf test is successful
The above hint is that the test configuration file passes without any problems and can be used formally with the php service.
Start the php system service
> Use `systemctl start` + `service name` Start System Services [root@localhost php-src-php-7.1.6]# systemctl start php-fpm.service
View the service status of php system
> Use `systemctl status` + `service name` View System Service Status [root@localhost php-src-php-7.1.6]# systemctl status php-fpm.service ● php-fpm.service - LSB: starts php-fpm Loaded: loaded (/etc/rc.d/init.d/php-fpm; bad; vendor preset: disabled) Active: active (running) since Sun 2017-06-18 13:05:26 EDT; 2min 46s ago Docs: man:systemd-sysv-generator(8) Process: 105210 ExecStart=/etc/rc.d/init.d/php-fpm start (code=exited, status=0/SUCCESS) Memory: 11.0M CGroup: /system.slice/php-fpm.service ├─105212 php-fpm: master process (/usr/local/php/etc/php-fpm.conf) ├─105213 php-fpm: pool www ├─105214 php-fpm: pool www └─105215 php-fpm: pool www Jun 18 13:05:19 localhost.localdomain systemd[1]: Starting LSB: starts php-fpm... Jun 18 13:05:24 localhost.localdomain php-fpm[105210]: Starting php-fpm done Jun 18 13:05:26 localhost.localdomain systemd[1]: Started LSB: starts php-fpm.
You can see a green active running indicating that the system service php-fpm is already working.
Have you ever felt more and more comfortable since RedHat went to 7?
CLI Views php Version Information
[root@localhost php-src-php-7.1.6]# php -v PHP 7.1.6 (cli) (built: Jun 18 2017 05:55:31) ( NTS ) Copyright (c) 1997-2017 The PHP Group Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
Modify the nginx configuration file to use the nginx reverse php interpreter
Modify the nginx configuration file to use the nginx reverse PHP interpreter, php-fpm, which is actually cgi
> Explain what I'm installing. nginx Put the configuration file in `/etc/nginx/` Under the catalogue > Modify the configuration file as follows: server { listen 80; server_name www.nginx.dev; #charset koi8-r; access_log logs/nginx.dev.access.log main; location / { root /data/www/html; index index.php index.html index.htm; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /data/www/html; } location ~ ^/(images|javascript|js|css|flash|media|static)/ { expires 30d; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { # root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /data/www/html/$fastcgi_script_name; include fastcgi_params; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # location ~ /\.ht { deny all; } } > create a file [root@localhost php-src-php-7.1.6]# touch /data/www/html/index.php > Editing documents [root@localhost php-src-php-7.1.6]# vim /data/www/html/index.php > Input content <?php phpinfo(); > Save out :wq! > Reload nginx To configure [root@localhost php-src-php-7.1.6]# systemctl reload nginx.service
Browser access
So far, PHP 7.1 has been compiled and installed successfully, and has established a relationship with nginx.
As for nginx and php-fpm and how they work, you can refer to them. Detailed Operating Principle of Nginx+Php-fpm