php+nginx+mysql yum安装及坑

本文提供了一步一步的指导来安装LEMP栈(Linux、Nginx、MySQL、PHP),适用于CentOS 6。详细步骤包括配置软件源、安装各组件、设置自动启动等,并附带了解决常见问题的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值