以下是在CentOS 7/8上快速搭建Web服务器(LAMP/LEMP)的最新一键安装方法:
curl -s https://raw.githubusercontent.com/teddysun/lamp/master/lamp.sh | bash
或者:
wget --no-check-certificate https://lamp.sh/lamp.sh && chmod +x lamp.sh && ./lamp.sh
curl -s https://raw.githubusercontent.com/teddysun/lamp/master/lemp.sh | bash
或者:
wget --no-check-certificate https://lamp.sh/lemp.sh && chmod +x lemp.sh && ./lemp.sh
# CentOS 7+ 安装命令
yum install -y wget && wget -O install.sh http://download.bt.cn/install/install_6.0.sh && sh install.sh
# 安装Webmin
cat <<EOF > /etc/yum.repos.d/webmin.repo
[Webmin]
name=Webmin Distribution Neutral
baseurl=https://download.webmin.com/download/yum
enabled=1
gpgcheck=1
gpgkey=https://download.webmin.com/download/yum/RPM-GPG-KEY-webmin
EOF
yum install webmin -y
如果一键脚本不适用,可以使用以下分步命令:
yum install httpd -y
systemctl start httpd
systemctl enable httpd
# MariaDB (推荐)
yum install mariadb-server mariadb -y
systemctl start mariadb
systemctl enable mariadb
mysql_secure_installation
# CentOS 7
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-mysqlnd php-gd php-xml php-mbstring -y
# CentOS 8
dnf install php php-mysqlnd php-gd php-xml php-mbstring -y
# 创建测试页面
echo "<?php phpinfo(); ?>" > /var/www/html/info.php
# 重启服务
systemctl restart httpd
然后在浏览器中访问:http://你的服务器IP/info.php
安装完成后,请执行以下安全措施:
1. 配置防火墙:
bash
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reload
2. 删除测试页面:
bash
rm -f /var/www/html/info.php
3. 定期更新系统:
bash
yum update -y
这些方法提供了从最简单到最灵活的不同选择,您可以根据自己的需求选择最适合的方式。