CentOS的Nginx下安装高版本php+mysql

1. 首先安装 Remi Repository

## Install Remi & Epel Repository on RHEL/CentOS 6.4-6.0 - 32 Bit ##
rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm 

## Install Remi & Epel Repository on RHEL/CentOS 6.4-6.0 - 64 Bit ## (6.5也可用)
rpm -Uvh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm 

## Install Remi Repository on RHEL/CentOS 5.9-5.0 - 32 Bit ##
rpm -Uvh http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-5.rpm

## Install Remi Repository on RHEL/CentOS 5.9-5.0 - 64 Bit ##
rpm -Uvh http://dl.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-5.rpm

2. 安装mysql

yum --enablerepo=remi,remi-test install mysql mysql-server

3. 配置mysql的root密码并开机启用mysql,这里密码我用123456

service mysqld start
/usr/bin/mysqladmin -u root password '123456'
chkconfig mysqld on

4. 安装php,php-fpm和php扩展

yum --enablerepo=remi,remi-test install php php-fpm php-common php-mysql php-gd php-mbstring php-xml

5. 启动php-fpm并设置为开机启动

service php-fpm start
chkconfig php-fpm on

回到你nginx的配置文件,也就是nginx.conf,如果你不是编译安装的也有可能是/etc/nginx/conf.d/的default.conf,把下面这部分的#号(注释)都去掉。

location ~ \.php$ {
    root           html;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    include        fastcgi_params;
}

然后重新加载nginx配置文件

/etc/init.d/nginx reload

注意:

这时如果你访问php文件出现file not found错误,请返回nginx配置文件,将下面这部分的文字

fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;

替换成下面

fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

然后重新加载nginx配置文件,刷新浏览即可恢复正常

/etc/init.d/nginx reload

提示:

如果想让conf包含其他的conf,可以写追加

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

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注