在CentOS Minimal上部署网站可以通过多种方式实现,以下是一个基本的步骤指南,假设你想通过Apache HTTP服务器来部署一个简单的静态网站。
首先,确保你已经安装了CentOS Minimal。你可以从CentOS官方网站下载ISO镜像并进行安装。
安装完成后,更新系统以确保所有软件包都是最新的:
sudo yum update -y
使用yum安装Apache HTTP服务器:
sudo yum install httpd -y
启动Apache服务并设置开机自启:
sudo systemctl start httpd
sudo systemctl enable httpd
确保防火墙允许HTTP(端口80)和HTTPS(端口443)流量:
sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload
将你的网站文件放置在Apache的默认文档根目录/var/www/html
下。例如,如果你有一个名为index.html
的文件,可以将其放在该目录下:
sudo cp /path/to/your/index.html /var/www/html/
打开浏览器并访问你的服务器IP地址或域名,你应该能够看到你的网站。
如果你想通过HTTPS提供服务,可以使用Let’s Encrypt免费获取SSL证书并配置Apache:
安装Certbot和Nginx插件:
sudo yum install certbot python3-certbot-apache -y
获取并安装SSL证书:
sudo certbot --apache -d yourdomain.com -d www.yourdomain.com
按照提示完成证书安装和配置。
如果你需要在网站上运行PHP脚本,可以安装PHP及其相关模块:
sudo yum install php php-mysqlnd php-gd php-mbstring php-xml php-pear php-bcmath -y
重启Apache服务以应用更改:
sudo systemctl restart httpd
现在,你可以在/var/www/html
目录下创建一个名为info.php
的文件,并添加以下内容来测试PHP:
<?php
phpinfo();
?>
访问http://yourserverip/info.php
,你应该能够看到PHP信息页面。
通过以上步骤,你应该能够在CentOS Minimal上成功部署一个基本的网站。根据你的具体需求,可能还需要进行更多的配置和优化。