1分钟完美安装最新 CentOS + Nginx + PHP-FPM + MySQL

boxifeng 2011-03-03

PHP 5.3.1

MySQL5.0.89

Nginx 0.8.33 或 0.7.65 (可选)

现在,我们可以快速全自动搞定 CentOS + Nginx + PHP-FPM + MySQL 的安装了

这个可比网上流传的什么一键安装包要好得多,强烈推荐此法安装,适合所有菜鸟和高手我服务器上全用的源代码编译安装,也好不到哪去,还很费劲

我这个装完已经包含 php 的一些常用扩展, PDO,eaccelerator,memcache,tidy等等

本文为 21andy.com 原创,转载请以超级链接方式注明出处 http://www.21andy.com

先新建一个 repo

# vi /etc/yum.repos.d/centos.21andy.com.repo

放入如下内容

[21Andy.com]

name=21Andy.comPackagesforEnterpriseLinux5-$basearch

baseurl=http://www.21andy.com/centos/5/$basearch/

enabled=1

gpgcheck=0

protect=1

启用 EPEL repoi386

rpm -ihv http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm

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

爽吧!

如果 nginx 你要用 0.7.65 最新稳定版,把

yum-yinstallnginx

换成

yum-yinstallnginx-stable

就可以了

本文为 21andy.com 原创,转载请以超级链接方式注明出处 http://www.21andy.com

更完整的安装

yum -y update

yum-ymysql-server

servicemysqldstart

mysqladmin-urootpasswordroot

servicemysqldstop

yum-yinstallnginxphp-fpmphp-cliphp-pdophp-mysqlphp-mcryptphp-mbstringphp-gdphp-tidyphp-xmlphp-xmlrpcphp-pearphp-pecl-memcachephp-eaccelerator

#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

安装结果,全自动

Dependencies Resolved

==========================================================

PackageArchVersionRepositorySize

==========================================================

Installing:

mysqlx86_645.0.89-1.el521Andy.com3.5M

mysql-serverx86_645.0.89-1.el521Andy.com10M

nginxx86_640.8.33-3.el521Andy.com422k

php-clix86_645.3.1-2.el521Andy.com2.4M

php-eacceleratorx86_642:0.9.6-1.el521Andy.com118k

php-fpmx86_645.3.1-2.el521Andy.com1.2M

php-gdx86_645.3.1-2.el521Andy.com110k

php-mbstringx86_645.3.1-2.el521Andy.com1.1M

php-mcryptx86_645.3.1-2.el521Andy.com27k

php-mysqlx86_645.3.1-2.el521Andy.com84k

php-pdox86_645.3.1-2.el521Andy.com91k

php-pearnoarch1:1.9.0-1.el521Andy.com420k

php-pecl-memcachex86_642.2.5-3.el521Andy.com44k

php-tidyx86_645.3.1-2.el521Andy.com31k

php-xmlx86_645.3.1-2.el521Andy.com115k

php-xmlrpcx86_645.3.1-2.el521Andy.com48k

Installingfordependencies:

gmpx86_644.1.4-10.el5base201k

libXawx86_641.0.2-8.1base329k

libXmux86_641.0.2-5base63k

libXpmx86_643.5.5-3base44k

libeditx86_642.11-2.20080712cvs.el5epel80k

libmcryptx86_642.5.8-4.el5.centosextras105k

libtidyx86_640.99.0-14.20070615.el5epel140k

php-commonx86_645.3.1-2.el521Andy.com554k

sqlite2x86_642.8.17-5.el521Andy.com165k

t1libx86_645.1.1-7.el5epel208k

Updatingfordependencies:

libevent x86_64 1.4.12-1.el5 21Andy.com 129 k

Transaction Summary

==========================================================

Install26Package(s)

Update1Package(s)

Remove 0 Package(s)

最后只要 yum -y update 一下,全是最新的别忘了开机启动

chkconfig --level 345 mysqld on

chkconfig--level345php-fpmon

chkconfig --level 345 nginx on

来看看我用虚拟机测试的强大结果http://www.21andy.com/blog/20100219/1703.html

补充:所有的配置文件都在 /etc 目录下,包括 nginx, php-fpm, mysql 的配置文件,请自行查找设置,以下为我的 nginx 的配置范例

先新建一个 /www 目录,网站和日志也全放在这里别忘了建日志存放目录,你在配置文件中 access_log 用到的 /www/logs

注意:fastcgi_params 要加入这一行# vim /etc/nginx/fastcgi_params

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

# vi /etc/nginx/nginx.conf

user nobody nobody;

worker_processes8;#这里根据你的CPU和内存配置,设置2到10都OK

error_log/www/logs/nginx_error.logcrit;

pid/usr/local/nginx/logs/nginx.pid;

#Specifiesthevalueformaximumfiledescriptorsthatcanbeopenedbythisprocess.

worker_rlimit_nofile51200;

events{

useepoll;

worker_connections51200;

}

http{

includemime.types;

default_typeapplication/octet-stream;

#charsegb2312;#默认编码,可以不设置

server_names_hash_bucket_size128;

client_header_buffer_size16k;

large_client_header_buffers416k;

client_max_body_size8m;

sendfileon;

tcp_nopushon;

keepalive_timeout60;

tcp_nodelayon;

fastcgi_connect_timeout300;

fastcgi_send_timeout300;

fastcgi_read_timeout300;

fastcgi_buffer_size64k;

fastcgi_buffers464k;

fastcgi_busy_buffers_size128k;

fastcgi_temp_file_write_size128k;

gzipon;

gzip_min_length1k;

gzip_buffers416k;

gzip_http_version1.0;

gzip_comp_level5;

gzip_typestext/plaintext/javascriptapplication/x-javascripttext/cssapplication/xml;

gzip_varyon;

#limit_zonecrawler$binary_remote_addr10m;

server{

listen80;

server_namelocalhost;

root/www;

location/status{

stub_statuson;

access_logoff;

}

location/{

#这里是把所有不存在的文件和目录,全都转到index.php处理

try_files$uri$uri//index.php?q=$uri&$args;

}

#这里分开放到server.conf是为了再开server的时候方便,统一调用,放到/etc/nginx/目录下

includeserver.conf;

log_formataccess'$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.logaccess;

}

server{

listen80;

server_namewww.21andy.com21andy.com*.21andy.com;

root/www/21andy.com;

if($host!~*21andy\.com$){

return444;

}

location/{

try_files$uri$uri//index.php?q=$uri&$args;

}

includeserver.conf;#这里复用了,这段就省了

access_log/www/logs/21andy.com_access.logaccess;

}

}

# vi /etc/nginx/server.conf

index index.html index.htm index.php;

#limit_conncrawler20;

location~/\.ht{

denyall;

}

location~.*\.(sqlite|sq3)${

denyall;

}

location~.*\.php${

fastcgi_passunix:/tmp/php-cgi.sock;

#fastcgi_pass127.0.0.1:9000;

fastcgi_indexindex.php;

includefastcgi_params;

}

location~.*\.(gif|jpg|jpeg|png|bmp|swf|ico)${

expires30d;

access_logoff;

}

location~.*\.(js|css)?${

expires30d;

access_logoff;

}

本行以下内容可以略过php-fpm 也可以用以下设置,但建议用上面的,比较稳定

location ~ \.php$ {

root/www;

fastcgi_pass127.0.0.1:9000;

fastcgi_indexindex.php;

#下面这一行要加在/etc/nginx/fastcgi_params里

#fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;

includefastcgi_params;

}

不管是使用 php-cgi.sock 或 9000 端口方法,nginx 和 php-fpm 都要同时设置成一样的

nginx的设置上面已经提过,记得同时修改php-fpm.conf相应的地方

# vi /etc/php-fpm.conf
<value name="listen_address">127.0.0.1:9000</value>

<value name="listen_address">unix:/tmp/php-cgi.sock</value>

Tags: centos, mysql, nginx, php-fpm, RPM, 安装

本文地址: http://www.21andy.com/blog/20100219/1701.html

相关推荐