LNMP代表的就是:Linux系统下Nginx+MySQL+PHP这种网站服务器架构。 Nginx是一个小巧而高效的Linux下的Web服务器软件,是由 Igor Sysoev 为俄罗斯访问量第二的Rambler 站点开发的,已经在一些俄罗斯的大型网站上运行多年,相当的稳定。Nginx性能稳定、功能丰富、运维简单、处理静态文件速度快且消耗系统资源极少。
本案环境与说明: 环境 1
2
3
| [iyunv@bright ~]# cat /etc/centos-release && uname -r
CentOS release 6.6 (Final)
2.6.32-504.el6.x86_64
|
软件版本: 1
2
3
4
| mysql-5.7.6-m16-linux-glibc2.5-x86_64.tar.gz
nginx-1.7.8.tar.gz
libmcrypt-2.5.6.tar.gz
php-5.6.6.tar.gz
|
文中所用软件下载地址: http://mirrors.sohu.com/ http://mirrors.cnnic.cn/apache/ ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt
Nginx 安装前的准备
wget http://mirrors.sohu.com/mysql/My ... bc2.5-x86_64.tar.gz
wget http://mirrors.sohu.com/php/php-5.6.6.tar.gz
wget ftp://mcrypt.hellug.gr/pub/crypt ... mcrypt-2.5.6.tar.gz
wget http://mirrors.sohu.com/nginx/nginx-1.7.8.tar.gz
安装MySQL
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
| [iyunv@bright ~]# useradd -s /sbin/nologin mysql
[iyunv@bright ~]# tar zxvf mysql-5.7.6-m16-linux-glibc2.5-x86_64.tar.gz
[iyunv@bright ~]# cd /usr/local/
[iyunv@bright local]# mv /root/mysql-5.7.6-m16-linux-glibc2.5-x86_64 .
[iyunv@bright local]# ln -s mysql-5.7.6-m16-linux-glibc2.5-x86_64 mysql
[iyunv@bright local]# cd mysql
[iyunv@bright mysql]# mkdir /data/mysql
[iyunv@bright mysql]# chown -R root .
[iyunv@bright mysql]# chown -R mysql /data/mysql
[iyunv@bright mysql]# chgrp -R mysql .
[iyunv@bright mysql]# bin/mysql_install_db --user=mysql --datadir=/data/mysql
[iyunv@bright mysql]# cp support-files/my-default.cnf /etc/my.cnf
cp:是否覆盖"/etc/my.cnf"? y
[iyunv@bright mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[iyunv@bright mysql]# chmod 755 /etc/init.d/mysqld
[iyunv@bright mysql]# vim /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/data/mysql
[iyunv@bright mysql]# chkconfig --add mysqld
[iyunv@bright mysql]# chkconfig mysqld on
[iyunv@bright mysql]# service mysqld start
Starting MySQL. SUCCESS!
|
安装PHP
1.环境配置
1
2
3
4
5
6
7
8
9
| rpm -q libxml2-devel libjpeg-turbo libpng-devel freetype-devel gd-devel libmcrypt-devel openssl-devel
libxml2-devel-2.7.6-14.el6_5.2.x86_64
libjpeg-turbo-1.2.1-3.el6_5.x86_64
libpng-devel-1.2.49-1.el6_2.x86_64
freetype-devel-2.3.11-14.el6_3.1.x86_64
package gd-devel is not installed
package libmcrypt-devel is not installed
openssl-devel-1.0.1e-30.el6.x86_64
[iyunv@bright ~]# yum install gd-devel
|
本案为配置扩展源,libmcrypt-devel使用tar包安装
1
2
3
4
| [iyunv@bright ~]# tar zxvf libmcrypt-2.5.6.tar.gz
[iyunv@bright ~]# cd libmcrypt-2.5.6
[iyunv@bright libmcrypt-2.5.6]# ./configure --prefix=/usr/local/libmcrypt
[iyunv@bright libmcrypt-2.5.6]# make && make install
|
2.安装php
1
2
3
4
5
6
7
8
9
10
11
12
| [iyunv@bright src]# tar zxvf php-5.6.6.tar.gz
[iyunv@bright src]# useradd -s /sbin/nologin php-fpm
[iyunv@bright src]# cd php-5.6.6
[iyunv@bright src]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm --with-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=/usr/local/libmcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --disable-ipv6 --with-curl
[iyunv@bright php-5.6.6]# make && make install
[iyunv@bright php-5.6.6]# cp php.ini-production /usr/local/php/etc/php.ini
[iyunv@bright php-5.6.6]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[iyunv@bright php-5.6.6]# mv /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
[iyunv@bright php-5.6.6]# chmod 755 /etc/init.d/php-fpm
[iyunv@bright php-5.6.6]# chkconfig --add php-fpm
[iyunv@bright php-5.6.6]# chkconfig php-fpm on
[iyunv@bright php-5.6.6]# service php-fpm start
|
安装nginx
1.环境检查
1
2
| [iyunv@bright nginx-1.7.8]# rpm -q pcre-devel
pcre-devel-7.8-6.el6.x86_64
|
2.安装
1
2
3
4
| [iyunv@bright src]# tar nginx-1.7.8.tar.gz
[iyunv@bright src]# cd nginx-1.7.8
[iyunv@bright nginx-1.7.8]# ./configure --prefix=/usr/local/nginx --with-pcre
[iyunv@bright nginx-1.7.8]# make && make install
|
3.启动
1
2
3
4
5
6
| [iyunv@bright conf]# /usr/local/nginx/sbin/nginx #启动服务
[iyunv@bright conf]# ps -aux | grep nginx
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ
root 11541 0.0 0.0 24304 668 ? Ss 00:45 0:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody 11542 0.0 0.1 24728 1248 ? S 00:45 0:00 nginx: worker process
root 11544 0.0 0.0 103256 840 pts/0 S+ 00:45 0:00 grep nginx
|
4.配置解析php
1
2
3
4
5
6
7
8
9
10
11
12
| [iyunv@bright ~]# vi /usr/local/nginx/conf/nginx.conf #找如下内容并修改fastcgi_param行
# 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 /scripts$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
include fastcgi_params;
}
[iyunv@bright ~]# /usr/local/nginx/sbin/nginx -s reload
|
5.测试
1
2
3
4
5
| [iyunv@bright ~]# cat /usr/local/nginx/html/1.php
<?php
phpinfo();
?>
[iyunv@bright ~]# curl localhost/1.php
|
|