centos 云服务器 配置php环境变量,云服务器(Centos)上配置Apache环境

1、清除系统垃圾

yum clean all

2、执行系统更新

yum -y update

3、安装apache

yum -y install httpd

4、设置Apache的开机自启

systemctl enable httpd.service

5、创建开机启动,将server启动起来

systemctl start httpd.service

6、配置虚拟主机(一般情况下,我们对于Apache的使用都是通过不同的虚拟主机来配置的,并不会在一个服务器上只部署一个网站)

(创建目录)mkdir -p /var/www/yourname.com/public_html

(设置目录权限)chown -R apache:apache /var/www/yourname.com/public_html

chmod -R 755 /var/www

(创建首页文件)nano /var/www/yourname.com/public_html/index.html

(文件index.html内容如下,可自行修改)

Rayue's Blog

Welcome to my world! Come in please!

(修改Apache的配置文件)mkdir /etc/httpd/sites-available

mkdir /etc/httpd/sites-enabled

nano /etc/httpd/conf/httpd.conf

(在文件httpd.conf最后加上一行)IncludeOptional sites-enabled/*.conf

(创建配置文件yourname.com.conf,内容如下)nano /etc/httpd/sites-available/yourname.com.conf

ServerName yourname.com

DocumentRoot /var/www/yourname.com/public_html

ErrorLog /var/www/yourname.com/error.log

CustomLog /var/www/yourname.com/requests.log combined

(创建软连接)ln -s /etc/httpd/sites-available/yourname.com.conf /etc/httpd/sites-enabled/yourname.com.conf

7、重启Apache

apachectrl restart

8、打开浏览器,输入yourname.com(你的域名)进行访问