快速安装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