准备环境

确保拥有一台云服务器实例,操作系统为CentOS 7.6。通过SSH工具连接到服务器,使用root或具有sudo权限的账户登录。个人总结了一些,可以参考下:直接搜索“好淘云”,里面有近期基本上最合适划算的云服务器了。

更新系统软件包至最新版本:

yum update -y

安装Web服务器(Nginx/Apache)

Nginx安装
执行以下命令安装Nginx:

yum install epel-release -y
yum install nginx -y
systemctl start nginx
systemctl enable nginx

Apache安装
若选择Apache,运行以下命令:

yum install httpd -y
systemctl start httpd
systemctl enable httpd

配置防火墙

开放HTTP(80)和HTTPS(443)端口:

firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reload

安装数据库(MySQL/MariaDB)

MariaDB安装
CentOS 7.6默认提供MariaDB:

yum install mariadb-server mariadb -y
systemctl start mariadb
systemctl enable mariadb
mysql_secure_installation

安装PHP

安装PHP及常用扩展:

yum install php php-mysql php-fpm -y
systemctl start php-fpm
systemctl enable php-fpm

修改Nginx或Apache配置以支持PHP解析。以Nginx为例,编辑/etc/nginx/conf.d/default.conf,添加:

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;
}

部署网站文件

将网站文件上传至/var/www/html目录(Apache)或/usr/share/nginx/html(Nginx)。确保权限正确:

chown -R apache:apache /var/www/html
chmod -R 755 /var/www/html

域名与SSL证书

域名解析
在域名管理平台将域名A记录指向云服务器IP地址。

SSL证书安装
使用Let's Encrypt免费证书:

yum install certbot python2-certbot-nginx -y
certbot --nginx -d yourdomain.com

测试与访问

重启Web服务:

systemctl restart nginx

浏览器访问域名,检查网站是否正常运行。

更多推荐