快速安装LNMP环境
现在,我们可以快速全自动搞定 CentOS + Nginx + PHP + MySQL 的安装了
比网上流传的什么一键安装包要好得多,强烈推荐此法安装,适合所有菜鸟和高手
这个装完已经包含 php 的一些常用扩展, PDO,eaccelerator,memcache,tidy等等
先新建一个 repo
# vi /etc/yum.repos.d/centos.21andy.com.repo放入如下内容
[21Andy.com]name=21Andy.com Packages for Enterprise Linux 5 – $basearch
baseurl=http://www.21andy.com/centos/5/$basearch/
enabled=1
gpgcheck=0
protect=1
启用 EPEL repo
i386
x86_64
rpm -ihv http://download.fedora.redhat.com/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm接着导入key
rpm –import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL好了,一键安装
# yum install nginx php-fpm mysql-server爽吧!
# APC 和 eAccelerator 有冲突,2选1
yum -y install php-pecl-apc看下我的完整安装,只要一句
yum -y install nginx mysql-server php-fpm php-cli php-pdo php-mysql php-mcrypt php-mbstring php-gd php-tidy php-xml php-xmlrpc php-pear php-pecl-memcache php-eaccelerator
最后只要 yum -y update 一下,全是最新的
别忘了开机启动
chkconfig php-fpm on
chkconfig nginx on
补充:所有的配置文件都在 /etc 目录下,包括 nginx, php-fpm, mysql 的配置文件,请自行查找设置,以下为我的 nginx 的配置范例
先新建一个 /www 目录,网站和日志也全放在这里
别忘了建日志存放目录,你在配置文件中 access_log 用到的 /www/logs
注意:fastcgi_params 要加入这一行
# vim /etc/nginx/fastcgi_params
# vi /etc/nginx/nginx.conf
user nobody nobody;worker_processes 8; #这里根据你的CPU和内存配置, 设置2到10都OK
error_log /www/logs/nginx_error.log crit;
pid /usr/local/nginx/logs/nginx.pid;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 51200;
events {
use epoll;
worker_connections 51200;
}
http {
include mime.types;
default_type application/octet-stream;
#charse gb2312; # 默认编码,可以不设置
server_names_hash_bucket_size 128;
client_header_buffer_size 16k;
large_client_header_buffers 4 16k;
client_max_body_size 8m;
sendfile on;
tcp_nopush on;
keepalive_timeout 60;
tcp_nodelay on;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 5;
gzip_types text/plain text/javascript application/x-javascript text/css application/xml;
gzip_vary on;
#limit_zone crawler $binary_remote_addr 10m;
server {
listen 80;
server_name localhost;
root /www;
location /status {
stub_status on;
access_log off;
}
location / {
# 这里是把所有不存在的文件和目录,全都转到 index.php 处理
try_files $uri $uri/ /index.php?q=$uri&$args;
}
# 这里分开放到 server.conf 是为了再开 server 的时候方便,统一调用,放到/etc/nginx/ 目录下
include server.conf;
log_format access ‘$remote_addr – $remote_user [$time_local] “$request” ‘
‘$status $body_bytes_sent “$http_referer” ‘
‘”$http_user_agent” $http_x_forwarded_for’;
access_log /www/logs/access.log access;
}
server {
listen 80;
server_name www.21andy.com 21andy.com *.21andy.com;
root /www/21andy.com;
if ($host !~* 21andy\.com$) {
return 444;
}
location / {
try_files $uri $uri/ /index.php?q=$uri&$args;
}
include server.conf; # 这里复用了,这段就省了
access_log /www/logs/21andy.com_access.log access;
}
}
# vi /etc/nginx/server.conf
index index.html index.htm index.php;#limit_conn crawler 20;
location ~ /\.ht {
deny all;
}
location ~ .*\.(sqlite|sq3)$ {
deny all;
}
location ~ .*\.php$ {
fastcgi_pass unix:/tmp/php-cgi.sock;
#fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|ico)$ {
expires 30d;
access_log off;
}
expires 30d;
access_log off;
}
转载于:https://blog.51cto.com/oakcdrom/830482
总结
以上是生活随笔为你收集整理的快速安装LNMP环境的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 关于javascript对象的proto
- 下一篇: Common Trace Format