实测 CentOS 7.*和 8版本的系统能正常配置。
首先安装nginx和php ,安装默认版本的nginx,php默认安装7
yum install nginx php
然后输入 y 确定安装
启动nginx
systemctl start nginx.service
查看nginx状态
systemctl status nginx
这里第四条一般会报错,提示…Failed …,逐条运行下面的代码可以解决
mkdir -p /etc/systemd/system/nginx.service.d
printf "[Service]\nExecStartPost=/bin/sleep 0.1\n">/etc/systemd/system/nginx.service.d/override.conf
systemctl daemon-reload
systemctl restart nginx.service
设置nginx开机启动
systemctl enable nginx.service
查询开机启动是否设置成功,显示 enbaled 则设置开机启动成功
systemctl is-enabled nginx.service;echo $?
启动php-fpm
systemctl start php-fpm
设置php开机启动
systemctl enable php-fpm
安装PHP各种库,如果怕麻烦 直接用*来安装所有
yum install php-*
安装mysql和其服务
yum install mysql
yum install mysql-server
启动MySQL
service mysqld start
设置开机启动
systemctl enable mysqld
禁用防火墙(否则打不开页面)
systemctl disable firewalld.service
查看防火墙状态, 如果显示inactive则关闭成功, 如果显示绿色active状态则说明防火墙没有成功关闭。
systemctl status firewalld.service
此时在浏览器访问服务器的ip地址,正常情况下会显示Nginx测试页面, 代表LNMP环境配置成功。
如果要安装composer, 可以复制下面的代码在Linux命令中执行。
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '906a84df04cea2aa72f40b5f787e49f22d4c2f19492ac310e8cba5b96ac8b64115ac402c8cd292b8a03482574915d1a8') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"