CentOS 7 LNMP 环境搭建(四、PHP7 安装)

本文详细介绍了如何在服务器上安装并配置Nginx、MySQL及PHP7,通过一系列命令实现LNMP环境的快速部署。文章提供了具体的安装步骤及Nginx配置示例,并指导如何启动与设置服务开机自启。

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

Nginx以及MySQL安装请看上面的博客


PHP7安装

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

这里写图片描述

安装PHP7以及需要的插件

yum install php71w php71w-fpm php71w-cli php71w-common php71w-devel php71w-gd php71w-pdo php71w-mysql php71w-mbstring php71w-bcmath

这里写图片描述

启动php-fpm

systemctl start php-fpm

这里写图片描述

开机启动设置

systemctl enable php-fpm
systemctl daemon-reload

这里写图片描述

修改nginx根目录
修改 /etc/nginx/conf.d/default.conf

用以下代码替换

server {
    listen       80;
    server_name  localhost;
    location / {
        root   /www;
        index  index.html index.htm index.php;
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
    location ~ \.php$ 
    { 
        root /www; fastcgi_pass 127.0.0.1:9000; 
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
        include fastcgi_params;
    }
}

上面的root /www; 代表你html的路径,这是已经修改到/www的路径

ps:具体nginx配置会发新的一个博客,感谢关注。

重启Nginx使修改生效

service nginx restart

(如果前面安装完成nginx后可能没重启,直接重启服务器就ok)

这里写图片描述

经过NMP这三部的安装后,至此LNMP的搭建就完成了!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值