/ 中存储网

CentOS系统安装配置Nginx+MySQL+PHP+fastcgi+memcache环境

2014-02-15 08:05:01 来源:IT技术网

一、更新 yum

yum -y update

二、利用yum升级各种程序库

1.LANG=C

2.yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers

三、安装nginx 

由于centos没有默认的nginx软件包,需要启用REHL的附件包

1.rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-3.noarch.rpm

2.yum -y install nginx

设置开机启动

chkconfig nginx on

配置nginx

nginx.conf配置文件如下:

user nginx;

worker_processes 1;

error_log /var/log/nginx/error.log;

pid /var/run/nginx.pid;

events{

worker_connections 1024;

}

http {

include /etc/nginx/mime.types;

default_type application/octet-stream;

access_log /var/log/nginx/access.log ;

sendfile on;

#tcp_nopush on;

#keepalive_timeout 0;

keepalive_timeout 65;

gzip on;

# Load config files from the /etc/nginx/conf.d directory

include /etc/nginx/conf.d/*.conf;

server {

listen 80;

server_name _;

root /usr/share/nginx/html;

include common_www;

}

}

common_www文件如下

index index.html index.htm;

error_page 404 /404.html;

location = /404.html {

root /usr/share/nginx/html;

}

error_page 500 502 503 504 /50x.html;

location = /50x.html {

root /usr/share/nginx/html;

}

location ~ /.php$ {

root html;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

include fastcgi_params;

}

location ~ //.ht {

deny all;

}

四、安装php,memcache 

yum -y install php-cli php-pdo php-mcrypt php-mbstring php-json php-fastcgi php-cgi php-gd php-tidy php-xml php-xmlrpc php-pear php-pecl-memcache php-eaccelerator

# APC 和 eAccelerator 有冲突,2选1

yum -y install php-pecl-apc

五、安装spawn-fcgi来运行php-cgi

yum install spawn-fcgi

六、下载spawn-fcgi 的启动脚本 

wget http://bash.cyberciti.biz/dl/419.sh.zip

unzip 419.sh.zip

mv 419.sh /etc/init.d/php_cgi

chmod +x /etc/init.d/php_cgi

启动php_cgi

/etc/init.d/php_cgi start

查看进程

netstat -tulpn | grep :9000

若出现如下代表一切正常

tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 4352/php-cgi

下载地址:419.sh.zip

  安装mysql 

yum -y install mysql-server  ← 安装MySQL

yum -y install php-mysql  ← 安装php-mysql

vi /etc/my.cnf

在[mysqld]一节加入

default-character-set = utf

在末尾加入以下章节

[mysql]

default-character-set = utf8

然后开始启动mysql

chkconfig mysqld on  ← 设置MySQL服务随系统启动自启动

chkconfig –list mysqld  ← 确认MySQL自启动

mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off  ← 如果2–5为on的状态就OK

/etc/rc.d/init.d/mysqld start  ← 启动MySQL服务

设置初始密码

mysqladmin -u root password 123456