1. 程式人生 > >php+nginx+mysql yum安裝及坑

php+nginx+mysql yum安裝及坑

Step One—Install the Required Repositories

sudo yum install epel-release

Step Two—Install MySQL

sudo yum install mysql-server
sudo /etc/init.d/mysqld restart
sudo /usr/bin/mysql_secure_installation

Step Three—Install nginx

sudo yum install nginx
sudo /etc/init.d/nginx start

Step Four—Install PHP

sudo yum install php
 yum install php-fpm php-mysql php-curl php-gd php-mbstring php-xml php-xmlrpc php-zip libmemcached php-pecl-memcache

Step Five—update to php7

yum remove php* 
rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm
yum install php70w-xml php70w-common php70w-fpm php70w-opcache php70w-gd php70w-mysqlnd php70w-mbstring php70w-pecl-redis  php70w-devel
php -v

Step Six—Configure php

 sudo vi /etc/php.ini
Find the line, cgi.fix_pathinfo=1, and change the 1 to 0.
cgi.fix_pathinfo=0

Step Seven—Configure nginx

sudo vi /etc/nginx/conf.d/default.conf
#
# The default server
#


server {
    listen       80 default_server;
    listen       [::]:80 default_server;
    server_name  _;
    root         /home/bmwuser;
index index.html index.htm index.php;
    # Load configuration files for the default server block.
    include /etc/nginx/default.d/*.conf;


    location / {
    }
location ~ [^/]\.php(/|$)
        {
            try_files $uri =404;
            fastcgi_pass  127.0.0.1:9000;
            fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi.conf;
        }
    error_page 404 /404.html;
        location = /40x.html {
    }


    error_page 500 502 503 504 /50x.html;
        location = /50x.html {
    }


}

Step Eight—Configure php

sudo vi /etc/php-fpm.d/www.conf
[...]
; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
;	will be used.
; RPM: apache Choosed to be able to access some dir as httpd
user = nginx
; RPM: Keep a group allowed to write in log dir.
group = nginx
[...]
sudo service php-fpm restart

Step Nine—Set Up Autostart

sudo chkconfig --levels 235 mysqld on
sudo chkconfig --levels 235 nginx on
sudo chkconfig --levels 235 php-fpm on

坑1:403 Forbidden
坑2:No input file 
可能是訪問的資料夾沒有訪問許可權 ls -l 檢視資料夾許可權 
chmod -R 777 檔名

參考連結:https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-centos-6