Centos 安装nginx + php + mysql

一.更新最快的源


yum -y install yum-fastestmirror  

yum -y update


添加源,在/etc/yum.repo.d目录(centos 6.*为/etc/yum.repos.d目录)下创建一个文件alt.ru.repo,添加如下内容:


[CentALT]  
name=CentALT Packages for Enterprise Linux 5 - $basearch  
baseurl=http://centos.alt.ru/repository/centos/5/$basearch/  
enabled=1  
gpgcheck=0




二.安装mysql


yum -y install mysql mysql-server mysql-devel


三.安装php


yum -y install php php-devel php-mysql php-cgi php-mbstring php-gd php-fastcgi php-pear php-pear-DB php-fpm php-cli php-pdo php-mcrypt  php-tidy php-xml php-xmlrpc  php-pecl-memcache php-eaccelerator


如出现以下错误:

Error: Missing Dependency: libt1.so.5()(64bit) is needed by package ***


运行如下命令:

rpm -Uvh http://rpms.arrfab.net/centos/5/x86_64/t1lib-5.1.0-9.el5.af.x86_64.rpm


如出现:

The program package-cleanup is found in the yum-utils package.


运行如下命令

yum install yum-utils

# 清除可能存在的重复包 
package-cleanup --dupes 
# 清除可能存在的损坏包 
package-cleanup --problems 


打开/etc/php.ini,将cgi.fix_pathinfo=1前的注释去掉,并将值改为0:

cgi.fix_pathinfo=0



四.安装nginx

yum -y install nginx


配置多域名:

在/etc/nginx目录下新建文件夹vhosts

新建 www.domain.com

粘贴以下内容:

server {
        listen  80;
        server_name  www.domain.com;

        access_log  /var/log/domain.access.log  main;

        location / {
            root   /wwwroot/www.domain.com;
            index  index.php index.html index.htm;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/share/nginx/html;
        }

       # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        location ~ .php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /wwwroot/www.domain.com/$fastcgi_script_name;
            include        fastcgi_params;
        }

        location ~ /.ht {
            deny  all;
        }
}


在nginx.conf中加入以下语句

include /etc/nginx/vhosts/*;


重启nginx


五.将服务加入启动项,并启动各个服务

chkconfig mysqld on  
chkconfig php-fpm on  
chkconfig nginx on




原文地址:https://www.cnblogs.com/itfenqing/p/4429463.html