【简易】Linux(Centos 7.6)下搭建Apache 服务器搭建及配置(可实现多站点)

本小妞迷上赌 提交于 2020-04-23 04:55:11

基础环境:

设置SELINUX状态:

[root@localhost ~]# sed -ri '/^SELINUX=/cSELINUX=disabled' /etc/selinux/config
[root@localhost ~]# setenforce 0

查询SELINUX状态:

[root@localhost ~]# getenforce
Disabled

关闭防火墙:

[root@localhost ~]# systemctl stop firewalld.service
[root@localhost ~]# systemctl disable firewalld.service

[root@localhost ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
   Active: inactive (dead)
     Docs: man:firewalld(1)

12月 15 22:08:38 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewall daemon...

安装lnmp环境:

[root@localhost ~]# yum -y install httpd php php-mysql php-gd gd mariadb-server mariadb
[root@localhost ~]# 

开启 httpd mariadb和设置开机启动

[root@localhost ~]# systemctl start httpd mariadb

[root@localhost ~]# systemctl enable httpd mariadb

数据库密码设置:

[root@localhost ~]# mysql_secure_installation 

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

-----进入数据库-----
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)

MariaDB [(none)]> 

安装配置站点:

单站点

[root@localhost ~]# vim /etc/httpd/conf.d/shop.conf

<VirtualHost *:80>
	ServerName www.hjjshop.top
	ServerAlias hjjshop.com
	DocumentRoot "/webroot/womai"
</VirtualHost>

<Directory "/webroot/womai">
	Require all granted
</Directory>

多站点

[root@localhost ~]# vim /etc/httpd/conf.d/shop.conf

<VirtualHost *:80>
	ServerName www.hjjshop.top
	ServerAlias hjjshop.com
	DocumentRoot "/webroot/womai"
</VirtualHost>

<Directory "/webroot/womai">
	Require all granted
</Directory>

<VirtualHost *:80>
	ServerName shop.hjjshop.com
	ServerAlias shop.hjjshop.com
	DocumentRoot "/webroot/web"
</VirtualHost>

<Directory "/webroot/web">
	Require all granted
</Directory>

httpd -S 查询语法是否错误 , 报错:

[root@localhost conf.d]# httpd -t
AH00112: Warning: DocumentRoot [/webroot/womai] does not exist
[root@localhost conf.d]# 

解决 手动创建目录 /webroot/womai

[root@localhost conf.d]# mkdir -p /webroot/womai
[root@localhost conf.d]# mkdir -p /webroot/web

//再次检查
[root@localhost conf.d]# httpd -t
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message
Syntax OK //语法ok

重启httpd

[root@localhost conf.d]# systemctl restart httpd

上传 源码到 /webroot/womai

测试

在Windows下解析测试域名

在浏览器访问: http://www.hjjshop.top/http://shop.hjjshop.top/

OK~~

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!