下面给你一份**在 CentOS 上部署 LNMP(Linux + Nginx + MySQL/MariaDB + PHP)**的常用实操流程,适用于 CentOS 7 / 8(Stream)。
# 更新系统
yum update -y
# 关闭 SELinux(生产建议配置规则,而不是关闭)
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
# 防火墙放行端口
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reload
yum install epel-release -y
yum install nginx -y
dnf install nginx -y
systemctl start nginx
systemctl enable nginx
浏览器访问服务器 IP,看到 Nginx 欢迎页即成功。
yum install mariadb-server mariadb -y
systemctl start mariadb
systemctl enable mariadb
mysql_secure_installation
rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
yum install mysql-server -y
systemctl start mysqld
systemctl enable mysqld
# 查看初始密码
grep 'temporary password' /var/log/mysqld.log
mysql_secure_installation
yum install epel-release yum-utils -y
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm -y
yum-config-manager --enable remi-php74
yum install php php-fpm php-mysqlnd php-json php-gd php-mbstring -y
dnf install php php-fpm php-mysqlnd php-json php-gd php-mbstring -y
systemctl start php-fpm
systemctl enable php-fpm
编辑站点配置:
vi /etc/nginx/conf.d/default.conf
示例配置:
server {
listen 80;
server_name your_domain_or_ip;
root /usr/share/nginx/html;
index index.php index.html;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
nginx -t
systemctl restart nginx
echo "<?php phpinfo(); ?>" > /usr/share/nginx/html/info.php
访问:
http://服务器IP/info.php
chown -R nginx:nginx /usr/share/nginx/html
vi /etc/php.ini
upload_max_filesize = 50M
post_max_size = 50M
systemctl restart php-fpm
wget http://soft.vpser.net/lnmp/lnmp1.9.tar.gz
tar zxf lnmp1.9.tar.gz
cd lnmp1.9
./install.sh
如果你告诉我:
我可以给你更精准的配置方案。