LNMP是Linux、Nginx、MySQL、PHP的缩写,是指在Linux环境下由Nginx、MySQL、PHP构建的Web后台运行环境,是一种流行先进、便捷轻便、高性能的一后台环境。
我们今天介绍如何在支持yum源安装的系统上部署LNMP环境。
Nginx安装和启动
安装
yum install nginx
启动和停止
service nginx start
service nginx stop
#或者
systemctl start nginx
systemctl stop nginx
目录位置
运行文件: /usr/sbin/nginx
配置文件目录: /etc/nginx
日志文件目录: /var/nginx
MySQL安装
参见文档:
https://blog.51cto.com/livestreaming/2128571
PHP安装
参见文档:
https://blog.51cto.com/livestreaming/2092166
https://blog.51cto.com/livestreaming/2092162
Nginx配置支持PHP
以下配置打epoll、sendfile,可以多更好的并发和静态文件响应性能。
#使用deamon用户运行,注意对应目录的读写权限设置。
user daemon;
#开启四个进程
worker_processes 4;
worker_rlimit_nofile 5120;
events {
use epoll;
worker_connections 5000;
}
http {
include mime.types;
#default_type application/octet-stream;
access_log off;
#文件缓存优化
open_file_cache max=2000 inactive=60s;
open_file_cache_valid 60s;
open_file_cache_min_uses 2;
open_file_cache_errors on;
output_buffers 2 32k;
client_max_body_size 1m;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
charset utf-8;
sendfile on;
root /var/www/;
index index.php index.html index.htm;
error_page 500 502 503 504 404 403 /error.html;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}