1分钟搞定 CentOS + Nginx + PHP(fpm) + MySQL 标准生产环境
时间:2010-04-09
来源:互联网
MySQL 5.0.89
Nginx 0.8.33 或 0.7.65 (可选)
这个可比网上流传的什么一键安装包要好得多,强烈推荐此法安装,适合所有菜鸟和高手
我服务器上全用的源代码编译安装,也好不到哪去,还很费劲
我这个装完已经包含 php 的一些常用扩展, PDO,eaccelerator,memcache,tidy等等
CentOS 最小化安装,然后先新建一个 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
CentOS i386 输入如下命令
rpm -ihv http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-3.noarch.rpm
CentOS x86_64 输入如下命令
rpm -ihv http://download.fedora.redhat.com/pub/epel/5/x86_64/epel-release-5-3.noarch.rpm
然后导入key
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL
OK,一键安装吧
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 一下,全是最新的
如果 nginx 你要用 0.7.65 最新稳定版,把
yum -y install nginx
换成
yum -y install nginx-stable
就可以了
装完你已经可以这样玩了
service mysqld start
service php-fpm start
service nginx start
别忘了设置开机启动
chkconfig --level 345 mysqld on
chkconfig --level 345 php-fpm on
chkconfig --level 345 nginx on
配置文件都在 /etc 下自己找
看看安装多自动
Dependencies Resolved
==========================================================
Package Arch Version Repository Size
==========================================================
Installing:
mysql x86_64 5.0.89-1.el5 21Andy.com 3.5 M
mysql-server x86_64 5.0.89-1.el5 21Andy.com 10 M
nginx x86_64 0.8.33-3.el5 21Andy.com 422 k
php-cli x86_64 5.3.1-2.el5 21Andy.com 2.4 M
php-eaccelerator x86_64 2:0.9.6-1.el5 21Andy.com 118 k
php-fpm x86_64 5.3.1-2.el5 21Andy.com 1.2 M
php-gd x86_64 5.3.1-2.el5 21Andy.com 110 k
php-mbstring x86_64 5.3.1-2.el5 21Andy.com 1.1 M
php-mcrypt x86_64 5.3.1-2.el5 21Andy.com 27 k
php-mysql x86_64 5.3.1-2.el5 21Andy.com 84 k
php-pdo x86_64 5.3.1-2.el5 21Andy.com 91 k
php-pear noarch 1:1.9.0-1.el5 21Andy.com 420 k
php-pecl-memcache x86_64 2.2.5-3.el5 21Andy.com 44 k
php-tidy x86_64 5.3.1-2.el5 21Andy.com 31 k
php-xml x86_64 5.3.1-2.el5 21Andy.com 115 k
php-xmlrpc x86_64 5.3.1-2.el5 21Andy.com 48 k
Installing for dependencies:
gmp x86_64 4.1.4-10.el5 base 201 k
libXaw x86_64 1.0.2-8.1 base 329 k
libXmu x86_64 1.0.2-5 base 63 k
libXpm x86_64 3.5.5-3 base 44 k
libedit x86_64 2.11-2.20080712cvs.el5 epel 80 k
libmcrypt x86_64 2.5.8-4.el5.centos extras 105 k
libtidy x86_64 0.99.0-14.20070615.el5 epel 140 k
php-common x86_64 5.3.1-2.el5 21Andy.com 554 k
sqlite2 x86_64 2.8.17-5.el5 21Andy.com 165 k
t1lib x86_64 5.1.1-7.el5 epel 208 k
Updating for dependencies:
libevent x86_64 1.4.12-1.el5 21Andy.com 129 k
Transaction Summary
==========================================================
Install 26 Package(s)
Update 1 Package(s)
Remove 0 Package(s)
作者: assad 发布时间: 2010-04-09
/etc/nginx/ 这里都是 nginx 相关的配置文件
/etc/php.ini 和 /etc/php-fpm.conf 这是 php 相关的配置文件
/etc/my.cnf 这是mysql的,不用多说吧
不懂得配置 nginx 的,我下面给个范例
先新建一个 /www 目录,网站和日志也全放在这里
# vi /etc/nginx/nginx.conf
[code language=php]
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;
}
}
[/code]
# vi /etc/nginx/server.conf
[code language=php]
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_index index.php;
include fastcgi.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|ico)$ {
expires 30d;
access_log off;
}
location ~ .*\.(js|css)?$ {
expires 30d;
access_log off;
}
[/code]
# vi /etc/php-fpm.conf
<value name="listen_address">/tmp/php-cgi.sock</value>
作者: assad 发布时间: 2010-04-09
作者: adqin1984 发布时间: 2010-04-09
作者: assad 发布时间: 2010-04-09
作者: xieaotian 发布时间: 2010-04-09
作者: 孙小二 发布时间: 2010-04-11
作者: renwenlong 发布时间: 2010-04-12
作者: assad 发布时间: 2010-04-12
作者: qqgg 发布时间: 2010-06-08
作者: uit88 发布时间: 2010-06-08
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28