Rootop 服务器运维与web架构

apache2.4基于域名的虚拟主机

Apache 2.4 官网手册:http://httpd.apache.org/docs/2.4/

今天在rhel7下配置lamp,不过这里的m代表mariadb了。需要配置apache的虚拟主机。apache2.4中虚拟主机的配置基本和2.2一样。

apache 2.4主配置文件中去掉了 NameVirtualHost *:80配置参数,默认加了一行

IncludeOptional 参数,在2.2中为Include conf.d/*.conf

# Load config files in the "/etc/httpd/conf.d" directory, if any.
IncludeOptional conf.d/*.conf

所以直接在 /etc/httpd/conf.d/ 创建一个vhost_qdsop.com.conf (以.conf 结尾的配置文件)。

其中配置文件的参数还和以前一样:

<VirtualHost *:80>
DocumentRoot /var/www/html/www
DirectoryIndex index.php index.html
ServerName www.qdsop.com
ErrorLog "|/usr/sbin/rotatelogs /var/log/httpd/www/error/%Y%m%d_error_log 86400 480"
CustomLog "|/usr/sbin/rotatelogs /var/log/httpd/www/access/%Y%m%d_access_log 86400 480" common
</VirtualHost>

如果你要调试虚拟主机配置,你会发现 Apache 的命令行参数 -S 非常有用。即输入以下命令:
/usr/local/apache2/bin/httpd -S
这个命令将会显示 Apache 是如何解析配置文件的。

附yum安装lamp:

[root@rhel7 ~]# yum install -y httpd php php-mysql php-gd php-mbstring mariadb mariadb-server
[root@rhel7 ~]# systemctl start httpd    #启动服务
[root@rhel7 ~]# systemctl enable httpd #开机启动
[root@rhel7 ~]# systemctl start mariadb
[root@rhel7 ~]# systemctl enable mariadb

rhel7 默认用firewalld作为防火墙,关闭切换到iptables
[root@rhel7 ~]# systemctl stop firewalld
[root@rhel7 ~]# systemctl disable firewalld

原创文章,转载请注明。本文链接地址: https://www.rootop.org/pages/2888.html

作者:Venus

服务器运维与性能优化

评论已关闭。