以下是在CentOS上搭建域名网站的指南:
购买域名,并在域名注册商管理面板中配置DNS解析,将域名指向服务器IP地址。确保服务器能正常联网。
安装Apache、MySQL和PHP,可使用命令sudo yum install httpd mariadb-server mariadb php php-mysql
。安装完成后,启动相关服务并设置为开机自启,如sudo systemctl start httpd
等。
以Apache为例,编辑配置文件/etc/httpd/conf.d/yourdomain.conf
,添加虚拟主机配置,指定域名、网站根目录等。然后创建网站目录并设置权限,如sudo mkdir -p /var/www/yourdomain.com/public_html
等。
使用命令sudo firewall-cmd --permanent --add-service=http --add-service=https
开放HTTP和HTTPS端口,再执行sudo firewall-cmd --reload
使配置生效。
通过FTP或SCP等工具将网站文件上传到指定目录,如/var/www/yourdomain.com/public_html
。
在浏览器中输入服务器IP地址或域名,查看网站是否能正常访问。
使用Let’s Encrypt免费获取证书,安装Certbot并生成安装证书,命令为sudo yum install epel-release certbot python2 - certbot - apache
和sudo certbot --apache
。