2、搭建一个LNMP环境
LNMP代表的就是:Linux系统下Nginx+MySQL+PHP这种网站服务器架构。Nginx性能稳定、功能丰富、运维简单、处理静态文件速度快且消耗系统资源极少。作为 Web 服务器:相比 Apache,Nginx 使用更少的资源,支持更多的并发连接,体现更高的效率。作为负载均衡服务器:Nginx 既可以在内部直接支持 Rails 和 PHP,也可以支持作为 HTTP代理服务器对外进行服务。Nginx 用C编写,不论是系统资源开销还是CPU使用效率都比Perlbal要好的多。作为邮件代理服务器:Nginx同时也是一个非常优秀的邮件代理服务器(最早开发这个产品的目的之一也是作为邮件代理服务器),Last/fm 描述了成功并且美妙的使用经验。Nginx 安装非常的简单,配置文件非常简洁(还能够支持perl语法)。Nginx支持平滑加载新的配置,还能够在不间断服务的情况下进行软件版本的升级。
(1)首先安装Mysql5
yum install mysql mysql-server
chkconfig --levels 235 mysqld on
/etc/init.d/mysqld start下面运行mysql_secure_installation命令,它会执行几个设置:
a)为root用户设置密码
b)删除匿名账号
c)取消root用户远程登录
d)删除test库和对test库的访问权限
e)刷新授权表使修改生效
通过这几项的设置能够提高mysql库的安全。具体操作过程这里笔者不赘述了如图3。

(2)安装Nginx
yum install nginx
Then we create the system startup links for nginx and start it:
chkconfig --levels 235 nginx on
/etc/init.d/nginx start
测试一下如图4:

图4
测试一下
(3)安装配置php 模块
yum install php-fpm php-cli php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-magickwand php-magpierss php-mbstring php-mcrypt php-mssql php-shout php-snmp php-soap php-tidy php-pecl-apc
修改配置文件/etc/php.ini 设置cgi.fix_pathinfo=0
[...]
cgi.fix_pathinfo=0
[...](4)修改 nginx配置文件
vi /etc/nginx/nginx.conf修改为:
[...]
worker_processes 4;
[...]
keepalive_timeout 2;
[...]vi /etc/nginx/conf.d/default.conf修改为:
[...]
server {
listen 80;
server_name _;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.php index.html index.htm;
}
error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# 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 /usr/share/nginx/html;
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$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;
}}
重新加载:
/etc/init.d/nginx reload编写一个php文件测试
vi /usr/share/nginx/html/info.php
<?php
phpinfo();
?>
如图5:

图5 编写一个php文件测试
