LNMP架构介绍
和LAMP唯一不同的是,LNMP中的N指的是Nginx(类似于Apache的一种web服务软件)。目前这种环境的应用也非常多。Nginx设计的初衷是提供一种快速、高效、多并发的Web服务软件。在静态页面的处理上,Nginx较Apache更胜一筹,但在动态页面的处理上,Nginx并不比Apache有优势。但是目前还是有很多爱好者对Nginx比较热衷。随着Nginx技术的不断成熟,它在Web服务软件领域的地位也会越来越高。
并且php是作为一个独立服务存在的,这个服务叫做php-fpm。Nginx直接处理静态请求,动态请求会转发给php-fpm。
MySQL安装
1. 删除之前安装的mysql
[[email protected] ~]# ps aux |grep mysql //查看服务是否启动
root 2233 0.0 0.0 112680 972 pts/0 R+ 19:16 0:00 grep --color=auto mysql
[[email protected] ~]# rm -rf /usr/local/mysql
[[email protected] ~]# rm -rf /etc/init.d/mysqld
2.安装mysql过程
[[email protected] ~]# cd /usr/local/src/
[[email protected] ~]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz
[[email protected] src]# tar zxvf mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz
[[email protected] src]# mv mysql-5.6.35-linux-glibc2.5-x86_64 /usr/local/mysql
[[email protected] src]# cd /usr/local/mysql/
[[email protected] mysql]# ls
bin COPYING data docs include lib man mysql-test README scripts share sql-bench support-files
[[email protected] mysql]# ls /data/
mariadb mydata mysql wwwroot
[[email protected] mysql]# id mysql
uid=1000(mysql) gid=1000(mysql) 组=1000(mysql)
[[email protected] mysql]# rm -rf /data/mysql/* //由于之前创建个,删除
[[email protected] mysql]# useradd mysql
[[email protected] mysql]# mkdir /data/
[[email protected] mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
[[email protected] mysql]# echo $?
0
[[email protected] mysql]# cp support-files/my-default.cnf /etc/my.cnf
[[email protected] mysql]# vim /etc/my.cnf
定义如下:
datadir=/data/mysql
socket=/tmp/mysql.sock
[[email protected] mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[[email protected] mysql]# vim /etc/init.d/mysqld
定义如下:
basedir=/usr/local/mysql
datadir=/data/mysql
[[email protected] mysql]# /etc/init.d/mysqld start //启动mysql
Starting MySQL.Logging to '/data/mysql/gary-tao.err'.
. SUCCESS!
[[email protected] mysql]# ps aux |grep mysql //查看服务是否启动
root 2317 0.1 0.1 113268 1592 pts/0 S 19:40 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/gary-tao.pid
mysql 2452 4.1 45.1 973060 451828 pts/0 Sl 19:40 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/gary-tao.err --pid-file=/data/mysql/gary-tao.pid --socket=/tmp/mysql.sock
root 2480 0.0 0.0 112680 976 pts/0 R+ 19:41 0:00 grep --color=auto mysql
[[email protected] mysql]# chkconfig --add mysqld //把启动脚本加入系统服务
[[email protected] mysql]# chkconfig mysqld on //设定开机启动mysql
[[email protected] mysql]# service mysqld start //启动服务
Starting MySQL SUCCESS!
PHP安装
Nginx的PHP安装和上一章的PHP安装是有区别的,因为Nginx中的PHP是以fastcgi的方式给合Nginx的,可以理解为Nginx代理了PHP的fastcgi,而httpd是把PHP作为自己的模块来调用的。
1. 因为之前安装过php,这次重新安装的话直接在源码包目录下执行命令:make clean,删除之前编译过的文件内容,回到之前的解压的状态。
[[email protected] ~]# cd /usr/local/src/
[[email protected] src]# ls
apr-1.6.3 apr-util-1.6.1.tar.gz mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz php-5.6.30.tar.gz phpredis-develop
apr-1.6.3.tar.gz httpd-2.4.29 mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz php-7.1.6 phpredis-develop.zip
apr-util-1.6.1 httpd-2.4.29.tar.gz php-5.6.30 php-7.1.6.tar.bz2
[[email protected] src]# cd php-5.6.30
[[email protected] php-5.6.30]# ls
acinclude.m4 configure.in libs makerpm php.ini-production README.STREAMS stamp-h.in
aclocal.m4 CREDITS libtool meta_ccld README.EXT_SKEL README.SUBMITTING_PATCH stub.c
build ext LICENSE missing README.GIT-RULES README.TESTING tests
buildconf EXTENSIONS ltmain.sh mkinstalldirs README.input_filter README.TESTING2 travis
buildconf.bat footer main modules README.MAILINGLIST_RULES README.UNIX-BUILD-SYSTEM TSRM
CODING_STANDARDS generated_lists makedist netware README.md README.WIN32-BUILD-SYSTEM UPGRADING
config.guess genfiles Makefile NEWS README.namespaces run-tests.php UPGRADING.INTERNALS
config.log header Makefile.frag pear README.NEW-OUTPUT-API sapi vcsclean
config.nice include Makefile.fragments php5.spec README.PARAMETER_PARSING_API scripts win32
config.status INSTALL Makefile.gcov php5.spec.in README.REDIST.BINS server-tests-config.php Zend
config.sub install-sh Makefile.global php.gif README.RELEASE_PROCESS server-tests.php
configure libphp5.la Makefile.objects php.ini-development README.SELF-CONTAINED-EXTENSIONS snapshot
[[email protected] php-5.6.30]# make clean
find . -name \*.gcno -o -name \*.gcda | xargs rm -f
find . -name \*.lo -o -name \*.o | xargs rm -f
find . -name \*.la -o -name \*.a | xargs rm -f
find . -name \*.so | xargs rm -f
find . -name .libs -a -type d|xargs rm -rf
rm -f libphp5.la sapi/cli/php sapi/cgi/php-cgi libphp5.la modules/* libs/*
备注,如果是第一次安装的话按如下操作即可:
安装到指定目录 cd /usr/local/src/
下载源码包 wget http://cn2.php.net/distributions/php-5.6.30.tar.gz
解压源码包 tar zxf php-5.6.30.tar.gz
2.创建账号
该账号用来运行php-fpm服务的,在LNMP环境中,PHP以一个服务php-fpm的形式出现,独立存在于Linux系统中,方便管理。
[[email protected] php-5.6.30]# useradd -s /sbin/nologin php-fpm
3.安装PHP
[[email protected] php-5.6.30]# ./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
编译参数和跟之前的文章不同,这里多了一个--enable-fpm,如果不加该参数,则不会有php-fpm执行文件生成,更不能启动php-fpm服务。
报错:
解决办法:
yum install -y libcurl-devel
注意:如果是第一次安装PHP,会有很多依赖包需要安装,这时你看错误提示,缺少什么包就安装什么包。
4.编译PHP
[[email protected] php-5.6.30]# make
[[email protected] php-5.6.30]# make clean && make
报错如下图:
解决办法:
#vim Makefile //在大概105行,-lcrypt后面加“-lpthread"
解决办法:
#make clean && make
5.安装PHP
[[email protected] php-5.6.30]# make install
6.修改配置文件:
[[email protected]ry-tao php-5.6.30]# ls /usr/local/php-fpm/etc/
pear.conf php-fpm.conf.default
[[email protected] php-5.6.30]# cp php.ini-production /usr/local/php-fpm/etc/php.ini //拷贝配置文件 (production是生成环境下用的,development是开发环境下用的)
[[email protected] php-5.6.30]# ls /usr/local/php-fpm/etc/
pear.conf php-fpm.conf.default php.ini
[[email protected] etc]# vim /usr/local/php-fpm/etc/php-fpm.conf
添加如下内容:
[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.mode = 666 //监听的是sock时这行才生效,用来定义sock文件的权限是666
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
7.检测配置
[[email protected] etc]# /usr/local/php-fpm/sbin/php-fpm -t //报以下是正常的。
[02-Jan-2018 20:02:02] NOTICE: configuration file /usr/local/php-fpm/etc/php-fpm.conf test is successful
8.拷贝启动脚本
[[email protected] etc]# cd /usr/local/src/php-
php-5.6.30/ php-5.6.30.tar.gz php-7.1.6/ php-7.1.6.tar.bz2
[[email protected] etc]# cd /usr/local/src/php-5.6.30/ //进入到源码包目录
[[email protected] php-5.6.30]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm //拷贝启动脚本到指定目录下
9.修改启动脚本权限及添加服务到开机启动
[[email protected] php-5.6.30]# chmod 755 /etc/init.d/php-fpm //更改权限
[[email protected] php-5.6.30]# chkconfig --add php-fpm //
[[email protected] php-5.6.30]# chkconfig php-fpm on //设置开机启动
[[email protected] etc]# service php-fpm start //启动php命令
Starting php-fpm done
[[email protected] etc]# ps aux |grep php-fpm //查看进程
root 58306 0.1 0.4 123560 4968 ? Ss 20:38 0:00 php-fpm: master process (/usr/local/php-fpm/etc/php-fpm.conf)
php-fpm 58307 0.0 0.4 123560 4704 ? S 20:38 0:00 php-fpm: pool www
php-fpm 58308 0.0 0.4 123560 4704 ? S 20:38 0:00 php-fpm: pool www
php-fpm 58309 0.0 0.4 123560 4704 ? S 20:38 0:00 php-fpm: pool www
php-fpm 58310 0.0 0.4 123560 4704 ? S 20:38 0:00 php-fpm: pool www
php-fpm 58311 0.0 0.4 123560 4708 ? S 20:38 0:00 php-fpm: pool www
php-fpm 58312 0.0 0.4 123560 4708 ? S 20:38 0:00 php-fpm: pool www
php-fpm 58313 0.0 0.4 123560 4708 ? S 20:38 0:00 php-fpm: pool www
php-fpm 58314 0.0 0.4 123560 4708 ? S 20:38 0:00 php-fpm: pool www
php-fpm 58315 0.0 0.4 123560 4708 ? S 20:38 0:00 php-fpm: pool www
php-fpm 58316 0.0 0.4 123560 4708 ? S 20:38 0:00 php-fpm: pool www
php-fpm 58317 0.0 0.4 123560 4708 ? S 20:38 0:00 php-fpm: pool www
php-fpm 58318 0.0 0.4 123560 4708 ? S 20:38 0:00 php-fpm: pool www
php-fpm 58319 0.0 0.4 123560 4712 ? S 20:38 0:00 php-fpm: pool www
php-fpm 58320 0.0 0.4 123560 4712 ? S 20:38 0:00 php-fpm: pool www
php-fpm 58321 0.0 0.4 123560 4712 ? S 20:38 0:00 php-fpm: pool www
php-fpm 58322 0.0 0.4 123560 4712 ? S 20:38 0:00 php-fpm: pool www
php-fpm 58323 0.0 0.4 123560 4712 ? S 20:38 0:00 php-fpm: pool www
php-fpm 58324 0.0 0.4 123560 4712 ? S 20:38 0:00 php-fpm: pool www
php-fpm 58325 0.0 0.4 123560 4712 ? S 20:38 0:00 php-fpm: pool www
php-fpm 58326 0.0 0.4 123560 4712 ? S 20:38 0:00 php-fpm: pool www
root 58329 0.0 0.0 112680 976 pts/0 R+ 20:38 0:00 grep --color=auto php-fpm
原文地址:http://blog.51cto.com/ccj168/2085888