小鱼干货分享 - centos6.4安装php+nginx(请先安装mysql)

1.切换到root用户

su root

2.安装需要的repositories

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

3.创建nginx下载源

vi /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1

4.安装Nginx, PHP 5.5 and PHP-FPM

yum --enablerepo=remi,remi-php55 install php-devel
yum --enablerepo=remi,remi-php55 install nginx php-fpm php-common

5.安装PHP5.5 拓展

yum --enablerepo=remi,remi-php55 install php-pecl-apc php-cli php-pear php-pdo php-mysqlnd php-pgsql php-pecl-mongo php-sqlite php-pecl-memcache php-pecl-memcached php-gd php-mbstring php-mcrypt php-xml

6.开启服务器

关闭apache

/etc/init.d/httpd stop  或 service httpd stop

启动Nginx

/etc/init.d/nginx start  或 service nginx start 或 /etc/init.d/nginx restart  或 service nginx restart

启动PHP-FPM

/etc/init.d/php-fpm start 或 service php-fpm start 或 /etc/init.d/php-fpm start 或 service php-fpm start

7.设置开机自动启动
启动nging

chkconfig httpd off
chkconfig --add nginx
chkconfig --levels 235 nginx on
启动php-fpm
chkconfig --add php-fpm
chkconfig --levels 235 php-fpm on

8.配置Nginx和PHP-FPM

     /site/ldapi/public 是index.php的存放位置

mkdir -p /site/ldapi/public
mkdir /etc/nginx/sites-enabled
vi /etc/nginx/nginx.conf

在这一句后面“include /etc/nginx/conf.d/*.conf”加上

## Load virtual host conf files. ##
include /etc/nginx/sites-enabled/*;

创建 vim /etc/nginx/sites-enabled/ld.com

vim ld.com
server {
        listen 80;
        server_name ld.com;
#        access_log  /var/log/nginx/localhost.access.log;
        root /site/ldapi/public;
        index index.php index.html index.htm;

        location / {
             try_files $uri $uri/ /index.php$is_args$args;
        }

        location ~ .*\.php(.*)$ {
                include        /etc/nginx/fastcgi_params;
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_split_path_info ^(.+\.php)(.*)$;
                fastcgi_param  SCRIPT_FILENAME /site/ldapi/public$fastcgi_script_name;
        }
}

增加 ld.com域名到 /etc/hosts


9. 测试Nginx and PHP-FPM

cd /site/ldapi/public
vim info.php

输入以下代码

<?php 
    phpinfo();

浏览器运行一下:

http://ld.com/info.php

如果得到 403 forbidden error, 可能是 SELinux 导致, 运行一下:

setenforce 0

开启防火墙

nano -w /etc/sysconfig/iptables

添加以下句子:

-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

重启防火墙

service iptables restart


/etc/init.d/iptables restart


你可能感兴趣的:(PHP,nginx,centos6,php-fpm)