LNMP架构是指:Linux、Nginx、Mysql、PHP。与LAMP架构相似,只不过Apache服务器由Nginx代替。php
与LAMP不一样的是,LNMP的Web服务是由Nginx提供的。其中php是做为独立的服务进程存在的:即php-fpm,而不是像LAMP同样php只是Apache的一个模块形式。css
LNMP处理请求过程:html
一、用户浏览器发起访问请求。java
二、服务器收到请求后,Nginx服务处理静态请求,如图片、css等。mysql
三、Nginx把动态请求发给php-fpm服务,由他进行处理。linux
四、php-fpm与mysql进行数据库交互。nginx
五、Nginx把静态动态请求处理结果返回给用户。web
Nginx比Apache在静态处理性能方面强不少,特别是图片多的网站用户并发能够上几万。Apache作不到这点性能。sql
一、进入src目录,下载mysql二进制包数据库
[root@localhost ~]# cd /usr/local/src/ [root@localhost src]# ls mysql-test-5.7.18-linux-glibc2.5-x86_64.tar.gz [root@localhost src]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz --2018-06-06 22:48:38-- http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz 正在解析主机 mirrors.sohu.com (mirrors.sohu.com)... 221.236.12.140 正在链接 mirrors.sohu.com (mirrors.sohu.com)|221.236.12.140|:80... 已链接。 已发出 HTTP 请求,正在等待回应... 200 OK 长度:316320366 (302M) [application/octet-stream] 正在保存至: “mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz” 100%[===========================================================================================================================>] 316,320,366 1.11MB/s 用时 4m 29s 2018-06-06 22:53:07 (1.12 MB/s) - 已保存 “mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz” [316320366/316320366]) [root@localhost src]# ls mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz mysql-test-5.7.18-linux-glibc2.5-x86_64.tar.gz
二、解压二进制安装包:
[root@localhost src]# tar xzvf mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz //省略过程 mysql-5.6.36-linux-glibc2.5-x86_64/sql-bench/graph-compare-results mysql-5.6.36-linux-glibc2.5-x86_64/sql-bench/test-connect mysql-5.6.36-linux-glibc2.5-x86_64/sql-bench/bench-init.pl mysql-5.6.36-linux-glibc2.5-x86_64/sql-bench/innotest1b mysql-5.6.36-linux-glibc2.5-x86_64/sql-bench/test-insert mysql-5.6.36-linux-glibc2.5-x86_64/sql-bench/test-select [root@localhost src]# ls mysql-5.6.36-linux-glibc2.5-x86_64 mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz mysql-test-5.7.18-linux-glibc2.5-x86_64.tar.gz [root@localhost src]# du -sh mysql-5.6.36-linux-glibc2.5-x86_64 1.1G mysql-5.6.36-linux-glibc2.5-x86_64
三、把二进制文件目录移动,并更名为mysql目录
[root@localhost src]# mv mysql-5.6.36-linux-glibc2.5-x86_64 /usr/local/mysql/ [root@localhost src]# cd /usr/local/mysql/ [root@localhost mysql]# ls bin COPYING data docs include lib man mysql-test README scripts share sql-bench support-files
四、建立mysql运行用户,建立mysql的数据存放目录
[root@localhost mysql]# useradd mysql useradd:用户“mysql”已存在 [root@localhost mysql]# mkdir /data/mysql/ [root@localhost mysql]# ls -l /data/mysql/ 总用量 0
五、配置安装mysql:
[root@localhost mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql/ FATAL ERROR: please install the following Perl modules before executing ./scripts/mysql_install_db: Data::Dumper
报错:缺乏Perl,安装他
[root@localhost mysql]# yum list |grep -i perl |grep -i dumper perl-Data-Dumper.x86_64 2.145-3.el7 base perl-Data-Dumper-Concise.noarch 2.020-6.el7 epel perl-Data-Dumper-Names.noarch 0.03-17.el7 epel perl-XML-Dumper.noarch 0.81-17.el7 base [root@localhost mysql]# yum install -y perl-Data-Dumper 已加载插件:fastestmirror base | 3.6 kB 00:00:00 epel/x86_64/metalink | 7.0 kB 00:00:00 epel | 3.2 kB 00:00:00 http://ftp.sjtu.edu.cn/centos/7.5.1804/extras/x86_64/repodata/repomd.xml: [Errno 14] curl#7 - "Failed to connect to 2001:da8:8000:6023::230: 网络不可达" 正在尝试其它镜像。 extras | 3.4 kB 00:00:00 updates | 3.4 kB 00:00:00 (1/4): updates/7/x86_64/primary_db | 2.0 MB 00:00:00 (2/4): extras/7/x86_64/primary_db | 147 kB 00:00:00 (3/4): epel/x86_64/updateinfo | 935 kB 00:00:01 (4/4): epel/x86_64/primary | 3.5 MB 00:00:07 Loading mirror speeds from cached hostfile * base: mirrors.zju.edu.cn * epel: ftp.cuhk.edu.hk * extras: mirrors.zju.edu.cn * updates: mirror.lzu.edu.cn epel 12586/12586 正在解决依赖关系 --> 正在检查事务 ---> 软件包 perl-Data-Dumper.x86_64.0.2.145-3.el7 将被 安装 --> 解决依赖关系完成 依赖关系解决 ===================================================================================================================================================================== Package 架构 版本 源 大小 ===================================================================================================================================================================== 正在安装: perl-Data-Dumper x86_64 2.145-3.el7 base 47 k 事务概要 ===================================================================================================================================================================== 安装 1 软件包 总下载量:47 k 安装大小:97 k Downloading packages: perl-Data-Dumper-2.145-3.el7.x86_64.rpm | 47 kB 00:00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction 正在安装 : perl-Data-Dumper-2.145-3.el7.x86_64 1/1 验证中 : perl-Data-Dumper-2.145-3.el7.x86_64 1/1 已安装: perl-Data-Dumper.x86_64 0:2.145-3.el7 完毕!
继续配置安装二进制文件:
[root@localhost mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql/ Installing MySQL system tables...2018-06-06 23:15:52 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2018-06-06 23:15:52 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap. 2018-06-06 23:15:52 0 [Note] ./bin/mysqld (mysqld 5.6.36) starting as process 2294 ... 2018-06-06 23:15:52 2294 [Note] InnoDB: Using atomics to ref count buffer pool pages 2018-06-06 23:15:52 2294 [Note] InnoDB: The InnoDB memory heap is disabled 2018-06-06 23:15:52 2294 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins 2018-06-06 23:15:52 2294 [Note] InnoDB: Memory barrier is not used 2018-06-06 23:15:52 2294 [Note] InnoDB: Compressed tables use zlib 1.2.3 2018-06-06 23:15:52 2294 [Note] InnoDB: Using Linux native AIO 2018-06-06 23:15:52 2294 [Note] InnoDB: Using CPU crc32 instructions 2018-06-06 23:15:52 2294 [Note] InnoDB: Initializing buffer pool, size = 128.0M 2018-06-06 23:15:52 2294 [Note] InnoDB: Completed initialization of buffer pool 2018-06-06 23:15:52 2294 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created! 2018-06-06 23:15:52 2294 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB 2018-06-06 23:15:52 2294 [Note] InnoDB: Database physically writes the file full: wait... 2018-06-06 23:15:52 2294 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB 2018-06-06 23:15:52 2294 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB 2018-06-06 23:15:52 2294 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0 2018-06-06 23:15:52 2294 [Warning] InnoDB: New log files created, LSN=45781 2018-06-06 23:15:52 2294 [Note] InnoDB: Doublewrite buffer not found: creating new 2018-06-06 23:15:52 2294 [Note] InnoDB: Doublewrite buffer created 2018-06-06 23:15:52 2294 [Note] InnoDB: 128 rollback segment(s) are active. 2018-06-06 23:15:52 2294 [Warning] InnoDB: Creating foreign key constraint system tables. 2018-06-06 23:15:52 2294 [Note] InnoDB: Foreign key constraint system tables created 2018-06-06 23:15:52 2294 [Note] InnoDB: Creating tablespace and datafile system tables. 2018-06-06 23:15:52 2294 [Note] InnoDB: Tablespace and datafile system tables created. 2018-06-06 23:15:52 2294 [Note] InnoDB: Waiting for purge to start 2018-06-06 23:15:53 2294 [Note] InnoDB: 5.6.36 started; log sequence number 0 2018-06-06 23:15:53 2294 [Note] Binlog end 2018-06-06 23:15:53 2294 [Note] InnoDB: FTS optimize thread exiting. 2018-06-06 23:15:53 2294 [Note] InnoDB: Starting shutdown... 2018-06-06 23:15:54 2294 [Note] InnoDB: Shutdown completed; log sequence number 1625977 OK Filling help tables...2018-06-06 23:15:54 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2018-06-06 23:15:54 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap. 2018-06-06 23:15:54 0 [Note] ./bin/mysqld (mysqld 5.6.36) starting as process 2316 ... 2018-06-06 23:15:54 2316 [Note] InnoDB: Using atomics to ref count buffer pool pages 2018-06-06 23:15:54 2316 [Note] InnoDB: The InnoDB memory heap is disabled 2018-06-06 23:15:54 2316 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins 2018-06-06 23:15:54 2316 [Note] InnoDB: Memory barrier is not used 2018-06-06 23:15:54 2316 [Note] InnoDB: Compressed tables use zlib 1.2.3 2018-06-06 23:15:54 2316 [Note] InnoDB: Using Linux native AIO 2018-06-06 23:15:54 2316 [Note] InnoDB: Using CPU crc32 instructions 2018-06-06 23:15:54 2316 [Note] InnoDB: Initializing buffer pool, size = 128.0M 2018-06-06 23:15:54 2316 [Note] InnoDB: Completed initialization of buffer pool 2018-06-06 23:15:54 2316 [Note] InnoDB: Highest supported file format is Barracuda. 2018-06-06 23:15:54 2316 [Note] InnoDB: 128 rollback segment(s) are active. 2018-06-06 23:15:54 2316 [Note] InnoDB: Waiting for purge to start 2018-06-06 23:15:55 2316 [Note] InnoDB: 5.6.36 started; log sequence number 1625977 2018-06-06 23:15:55 2316 [Note] Binlog end 2018-06-06 23:15:55 2316 [Note] InnoDB: FTS optimize thread exiting. 2018-06-06 23:15:55 2316 [Note] InnoDB: Starting shutdown... 2018-06-06 23:15:56 2316 [Note] InnoDB: Shutdown completed; log sequence number 1625987 OK To start mysqld at boot time you have to copy support-files/mysql.server to the right place for your system PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! To do so, start the server, then issue the following commands: ./bin/mysqladmin -u root password 'new-password' ./bin/mysqladmin -u root -h localhost.localdomain password 'new-password' Alternatively you can run: ./bin/mysql_secure_installation which will also give you the option of removing the test databases and anonymous user created by default. This is strongly recommended for production servers. See the manual for more instructions. You can start the MySQL daemon with: cd . ; ./bin/mysqld_safe & You can test the MySQL daemon with mysql-test-run.pl cd mysql-test ; perl mysql-test-run.pl Please report any problems at http://bugs.mysql.com/ The latest information about MySQL is available on the web at http://www.mysql.com Support MySQL by buying support/licenses at http://shop.mysql.com New default config file was created as ./my.cnf and will be used by default by the server when you start it. You may edit this file to change server settings [root@localhost mysql]# echo $? 0
六、安装成功后,复制配置文件到/etc/目录下
[root@localhost mysql]# cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
七、复制启动脚本到 /etc/init.d/目录下
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld [root@localhost mysql]# ls -l !$ ls -l /etc/init.d/mysqld -rwxr-xr-x 1 root root 10565 6月 6 23:20 /etc/init.d/mysqld
八、修改启动脚本,增长datadir和basedir目录
[root@localhost mysql]# vim !$ vim /etc/init.d/mysqld #!/bin/sh # Copyright Abandoned 1996 TCX DataKonsult AB & Monty Program KB & Detron HB # This file is public domain and comes with NO WARRANTY of any kind # MySQL daemon start/stop script. # Usually this is put in /etc/init.d (at least on machines SYSV R4 based # systems) and linked to /etc/rc3.d/S99mysql and /etc/rc0.d/K01mysql. # When this is done the mysql server will be started when the machine is # started and shut down when the systems goes down. # Comments to support chkconfig on RedHat Linux # chkconfig: 2345 64 36 # description: A very fast and reliable SQL database engine. # Comments to support LSB init script conventions ### BEGIN INIT INFO # Provides: mysql # Required-Start: $local_fs $network $remote_fs # Should-Start: ypbind nscd ldap ntpd xntpd # Required-Stop: $local_fs $network $remote_fs # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: start and stop MySQL # Description: MySQL is a very fast and reliable SQL database engine. ### END INIT INFO # If you install MySQL on some other places than /usr/local/mysql, then you # have to do one of the following things for this script to work: # # - Run this script from within the MySQL installation directory # - Create a /etc/my.cnf file with the following information: # [mysqld] # basedir=<path-to-mysql-installation-directory> # - Add the above to any other configuration file (for example ~/.my.ini) # and copy my_print_defaults to /usr/bin # - Add the path to the mysql-installation-directory to the basedir variable # below. # # If you want to affect other MySQL variables, you should make your changes # in the /etc/my.cnf, ~/.my.cnf or other MySQL configuration files. # If you change base dir, you must also change datadir. These may get # overwritten by settings in the MySQL configuration files. basedir=/usr/local/mysql/ datadir=/data/mysql/
九、启动mysql服务:
[root@localhost mysql]# /etc/init.d/mysqld start Starting MySQL.Logging to '/data/mysql/localhost.localdomain.err'. SUCCESS! [root@localhost mysql]# ps aux|grep mysql root 2356 0.0 0.0 113264 1640 pts/0 S 23:22 0:00 /bin/sh /usr/local/mysql//bin/mysqld_safe --datadir=/data/mysql/ --pid-file=/data/mysql//localhost.localdomain.pid mysql 2463 3.5 24.0 1300784 449564 pts/0 Sl 23:22 0:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/localhost.localdomain.err --pid-file=/data/mysql//localhost.localdomain.pid root 2487 0.0 0.0 112676 988 pts/0 R+ 23:22 0:00 grep --color=auto mysql [root@localhost mysql]# netstat -lntp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 896/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1106/master tcp6 0 0 :::22 :::* LISTEN 896/sshd tcp6 0 0 ::1:25 :::* LISTEN 1106/master tcp6 0 0 :::3306 :::* LISTEN 2463/mysqld
十、设置开机启动:
[root@localhost mysql]# chkconfig --add mysqld [root@localhost mysql]# chkconfig mysqld on [root@localhost mysql]# service mysqld stop Shutting down MySQL.. SUCCESS! [root@localhost mysql]# service mysqld start Starting MySQL. SUCCESS!
LNMP的php与LAMP的不同,须要开启php-fpm服务。 一、到src目录,下载php的源码包:
[root@localhost mysql]# cd /usr/local/src/ [root@localhost src]# ls mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz mysql-test-5.7.18-linux-glibc2.5-x86_64.tar.gz [root@localhost src]# wget http://cn2.php.net/distributions/php-5.6.32.tar.bz2 --2018-06-07 00:00:42-- http://cn2.php.net/distributions/php-5.6.32.tar.bz2 正在解析主机 cn2.php.net (cn2.php.net)... 36.51.255.144 正在链接 cn2.php.net (cn2.php.net)|36.51.255.144|:80... 已链接。 已发出 HTTP 请求,正在等待回应... 200 OK 长度:15055569 (14M) [application/octet-stream] 正在保存至: “php-5.6.32.tar.bz2” 100%[===========================================================================================================================>] 15,055,569 522KB/s 用时 35s 2018-06-07 00:01:17 (422 KB/s) - 已保存 “php-5.6.32.tar.bz2” [15055569/15055569])
二、解压源码包:
[root@localhost src]# tar xjvf php-5.6.32.tar.bz2 //省略过程 php-5.6.32/pear/install-pear-nozlib.phar php-5.6.32/pear/fetch.php php-5.6.32/pear/Makefile.frag php-5.6.32/README.SUBMITTING_PATCH
三、建立运行php-fpm服务的用户:
[root@localhost php-5.6.32]# less /etc/passwd root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin adm:x:3:4:adm:/var/adm:/sbin/nologin lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin sync:x:5:0:sync:/sbin:/bin/sync shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown halt:x:7:0:halt:/sbin:/sbin/halt mail:x:8:12:mail:/var/spool/mail:/sbin/nologin operator:x:11:0:operator:/root:/sbin/nologin games:x:12:100:games:/usr/games:/sbin/nologin ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin nobody:x:99:99:Nobody:/:/sbin/nologin systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin dbus:x:81:81:System message bus:/:/sbin/nologin polkitd:x:999:997:User for polkitd:/:/sbin/nologin postfix:x:89:89::/var/spool/postfix:/sbin/nologin sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin chrony:x:998:996::/var/lib/chrony:/sbin/nologin tcpdump:x:72:72::/:/sbin/nologin tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin mysql:x:1000:1000::/home/mysql:/bin/bash php-fpm:x:1001:1001::/home/php-fpm:/sbin/nologin
四、配置编译文件,若是以前编译过php源码包,能够先make clean,清理编译文件,恢复刚解压的状态
[root@localhost php-5.6.32]# ./configure --prefix=/usr/local/php-fpm --with-config-file-path=/usr/local/php-fpm/etc --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm --with-mysql=/usr/local/mysql/ --with-mysqli=/usr/local/mysql/bin/mysql_config --with-pdo-mysql=/usr/local/mysql/ --with-mysql-sock=/tmp/mysql.sock --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --with-pear --with-curl --with-openssl checking for cc... no checking for gcc... no configure: error: in `/usr/local/src/php-5.6.32': configure: error: no acceptable C compiler found in $PATH See `config.log' for more details
报错:缺乏gcc:安装他,再继续配置
checking libxml2 install dir... no checking for xml2-config path... configure: error: xml2-config not found. Please check your libxml2 installation.
报错:缺乏libxml2:安装,再继续配置
checking for OpenSSL support... yes checking for Kerberos support... no checking whether to use system default cipher list instead of hardcoded value... no checking for DSA_get_default_method in -lssl... no checking for X509_free in -lcrypto... no checking for RAND_egd... no checking for pkg-config... /usr/bin/pkg-config configure: error: Cannot find OpenSSL's <evp.h>
报错:缺乏openssl:安装他,再继续配置
checking for cURL in default path... not found configure: error: Please reinstall the libcurl distribution - easy.h should be in <curl-dir>/include/curl/
报错:缺乏libcurl:安装。再继续配置:
checking for T1lib support... no checking whether to enable truetype string function in GD... no checking whether to enable JIS-mapped Japanese font support in GD... no If configure fails try --with-vpx-dir=<DIR> configure: error: jpeglib.h not found.
报错:缺乏jpeblib,安装,再继续配置:
checking whether to enable JIS-mapped Japanese font support in GD... no If configure fails try --with-vpx-dir=<DIR> checking for jpeg_read_header in -ljpeg... yes configure: error: png.h not found.
报错:缺乏png,安装,继续配置:
checking for jpeg_read_header in -ljpeg... yes checking for png_write_image in -lpng... yes If configure fails try --with-xpm-dir=<DIR> configure: error: freetype-config not found.
报错:缺乏freetype,安装,继续配置:
checking for stdarg.h... (cached) yes checking for mcrypt support... yes configure: error: mcrypt.h not found. Please reinstall libmcrypt.
报错:缺乏libmcrypt,安装,继续配置:
Generating files configure: creating ./config.status creating main/internal_functions.c creating main/internal_functions_cli.c +--------------------------------------------------------------------+ | License: | | This software is subject to the PHP License, available in this | | distribution in the file LICENSE. By continuing this installation | | process, you are bound by the terms of this license agreement. | | If you do not agree with the terms of this license, you must abort | | the installation process at this point. | +--------------------------------------------------------------------+ Thank you for using PHP. config.status: creating php5.spec config.status: creating main/build-defs.h config.status: creating scripts/phpize config.status: creating scripts/man1/phpize.1 config.status: creating scripts/php-config config.status: creating scripts/man1/php-config.1 config.status: creating sapi/cli/php.1 config.status: creating sapi/fpm/php-fpm.conf config.status: creating sapi/fpm/init.d.php-fpm config.status: creating sapi/fpm/php-fpm.service config.status: creating sapi/fpm/php-fpm.8 config.status: creating sapi/fpm/status.html config.status: creating sapi/cgi/php-cgi.1 config.status: creating ext/phar/phar.1 config.status: creating ext/phar/phar.phar.1 config.status: creating main/php_config.h config.status: main/php_config.h is unchanged config.status: executing default commands
五、配置成功,编译和安装:
[root@localhost php-5.6.32]# make && make install ldl -lxml2 -lz -lm -ldl -lcrypt -o sapi/cgi/php-cgi Generating phar.php Generating phar.phar PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled. clicommand.inc directorytreeiterator.inc invertedregexiterator.inc directorygraphiterator.inc pharcommand.inc phar.inc Build complete. Don't forget to run 'make test'. Installing shared extensions: /usr/local/php-fpm/lib/php/extensions/no-debug-non-zts-20131226/ Installing PHP CLI binary: /usr/local/php-fpm/bin/ Installing PHP CLI man page: /usr/local/php-fpm/php/man/man1/ Installing PHP FPM binary: /usr/local/php-fpm/sbin/ Installing PHP FPM config: /usr/local/php-fpm/etc/ Installing PHP FPM man page: /usr/local/php-fpm/php/man/man8/ Installing PHP FPM status page: /usr/local/php-fpm/php/php/fpm/ Installing PHP CGI binary: /usr/local/php-fpm/bin/ Installing PHP CGI man page: /usr/local/php-fpm/php/man/man1/ Installing build environment: /usr/local/php-fpm/lib/php/build/ Installing header files: /usr/local/php-fpm/include/php/ Installing helper programs: /usr/local/php-fpm/bin/ program: phpize program: php-config Installing man pages: /usr/local/php-fpm/php/man/man1/ page: phpize.1 page: php-config.1 Installing PEAR environment: /usr/local/php-fpm/lib/php/ [PEAR] Archive_Tar - installed: 1.4.3 [PEAR] Console_Getopt - installed: 1.4.1 [PEAR] Structures_Graph- installed: 1.1.1 [PEAR] XML_Util - installed: 1.4.2 [PEAR] PEAR - installed: 1.10.5 Wrote PEAR system config file at: /usr/local/php-fpm/etc/pear.conf You may want to add: /usr/local/php-fpm/lib/php to your php.ini include_path /usr/local/src/php-5.6.32/build/shtool install -c ext/phar/phar.phar /usr/local/php-fpm/bin ln -s -f phar.phar /usr/local/php-fpm/bin/phar Installing PDO headers: /usr/local/php-fpm/include/php/ext/pdo/ [root@localhost php-5.6.32]# echo $? 0
六、检查php-fpm核心文件及安装目录结构:
[root@localhost ~]# ls /usr/local/php-fpm/ bin etc include lib php sbin var [root@localhost ~]# ls /usr/local/php-fpm/sbin/ php-fpm //php-fpm的核心二进制文件 [root@localhost ~]# ls /usr/local/php-fpm/var/ log run //log 存放日志的目录、run存放pid的目录
七、从源码包里拷贝配置文件php.ini到php-fpm/etc/目录下:编辑php-fpm.conf配置文件
[root@localhost ~]# cp /usr/local/src/php-5.6.32/php.ini-production /usr/local/php-fpm/etc/php.ini [root@localhost ~]# vim /usr/local/php-fpm/etc/php-fpm.conf //与php.ini不一样,要区分开 [global] pid = /usr/local/php-fpm/var/run/php-fpm.pid error_log = /usr/local/php-fpm/var/log/php-fpm.log [www] // 模块名字 listen = /tmp/php-fcgi.sock #listen=127.0.0.1:9000 //也能够监听ip地址与默认9000端口 listen.mode = 666 //当上面监听的不是ip是sock的时候才生效 user = php-fpm group = php-fpm pm = dynamic pm.max_children = 50 pm.start_servers = 20 pm.min_spare_servers = 5 pm.max_spare_servers = 35 pm.max_requests = 500 rlimit_files = 1024 #sock文件的权限是666 [root@localhost ~]# ls -l /tmp/php-fcgi.sock srw-rw-rw- 1 root root 0 6月 7 13:05 /tmp/php-fcgi.sock
八、检查配置文件语法:
[root@localhost ~]# /usr/local/php-fpm/sbin/php-fpm -t [07-Jun-2018 13:02:50] NOTICE: configuration file /usr/local/php-fpm/etc/php-fpm.conf test is successful
九、设置开机启动:
[root@localhost ~]# cp /usr/local/src/php-5.6.32/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm //拷贝启动脚本 [root@localhost ~]# chmod 755 /etc/init.d/php-fpm //修改成755的权限 [root@localhost ~]# chkconfig --add php-fpm //加入启动列表 [root@localhost ~]# chkconfig php-fpm on //设置开机启动 [root@localhost ~]# service php-fpm start //开启php-fpm服务 Starting php-fpm done [root@localhost ~]# ps aux|grep php-fpm root 1450 0.0 0.2 123652 4944 ? Ss 13:05 0:00 php-fpm: master process (/usr/local/php-fpm/etc/php-fpm.conf) php-fpm 1451 0.0 0.2 123652 4712 ? S 13:05 0:00 php-fpm: pool www php-fpm 1452 0.0 0.2 123652 4712 ? S 13:05 0:00 php-fpm: pool www php-fpm 1453 0.0 0.2 123652 4712 ? S 13:05 0:00 php-fpm: pool www php-fpm 1454 0.0 0.2 123652 4712 ? S 13:05 0:00 php-fpm: pool www php-fpm 1455 0.0 0.2 123652 4716 ? S 13:05 0:00 php-fpm: pool www php-fpm 1456 0.0 0.2 123652 4716 ? S 13:05 0:00 php-fpm: pool www php-fpm 1457 0.0 0.2 123652 4716 ? S 13:05 0:00 php-fpm: pool www php-fpm 1458 0.0 0.2 123652 4716 ? S 13:05 0:00 php-fpm: pool www php-fpm 1459 0.0 0.2 123652 4716 ? S 13:05 0:00 php-fpm: pool www php-fpm 1460 0.0 0.2 123652 4720 ? S 13:05 0:00 php-fpm: pool www php-fpm 1461 0.0 0.2 123652 4720 ? S 13:05 0:00 php-fpm: pool www php-fpm 1462 0.0 0.2 123652 4720 ? S 13:05 0:00 php-fpm: pool www php-fpm 1463 0.0 0.2 123652 4720 ? S 13:05 0:00 php-fpm: pool www php-fpm 1464 0.0 0.2 123652 4720 ? S 13:05 0:00 php-fpm: pool www php-fpm 1465 0.0 0.2 123652 4720 ? S 13:05 0:00 php-fpm: pool www php-fpm 1466 0.0 0.2 123652 4720 ? S 13:05 0:00 php-fpm: pool www php-fpm 1467 0.0 0.2 123652 4720 ? S 13:05 0:00 php-fpm: pool www php-fpm 1468 0.0 0.2 123652 4720 ? S 13:05 0:00 php-fpm: pool www php-fpm 1469 0.0 0.2 123652 4720 ? S 13:05 0:00 php-fpm: pool www php-fpm 1470 0.0 0.2 123652 4720 ? S 13:05 0:00 php-fpm: pool www root 1472 0.0 0.0 112720 972 pts/0 R+ 13:05 0:00 grep --color=auto php-fpm
Nginx是俄国人开发的一个小巧而强大的web服务,能够到官网下载: nginx.org 最新的版本是1.13,稳定版本是1.12 stable
nginx有不少的应用场景:web服务、反向代理、负载均衡等。
nginx的静态文件处理性能比Apache强不少。由于淘宝网站用nginx+tomcat来搭建java环境
nginx有一个著名的分支:淘宝网基于nginx定制开发的Tengine,他的配置文件名和服务名基本与nginx一致,是在nginx的基础上增长了一些定制化的模块,在安全限速方面有比较突出的性能,另外还支持js、css的合并,由于淘宝网站是大型的购物平台,不少商品展现的页面,含有大量的静态文件,支持这些文件的合并,可以大大减小资源的请求,提升服务器的处理效率。
nginx的核心组件+lua相关模块还可以组成一个支持lua的高性能的web容器openresty。