CentOS7单机部署lamp环境和apache虚拟主机

(1)apache介绍

apache : httpd.apache.org
软件包:httpd
端口服务:80/tcp(http) 443/tcp(https,http+ssl)
配置文件:
/etc/httpd/conf/httpd.conf
/etc/httpd/conf.d/*.conf
/etc/httpd/conf.d/welcome.conf //默认测试页面

(2)lamp环境安装

1.关闭防火墙和selinux

systemctl stop firewalld.service
systemctl disable firewalld.service
sed -ri '/^SELINUX=/cSELINUX=disabled' /etc/sysconfig/selinux
setenforce 0

2.安装和启动apache

yum install httpd -y
systemctl start httpd
systemctl enable httpd

3.安装php

yum install php -y 			//php作为apache的模块
yum install php-mysql -y //安装php连接mysql扩展模块
yum install gd php-gd -y
php -m //查看php有哪些扩展模块
ll /etc/httpd/modules/libphp5.so
ll /etc/httpd/conf.d/php.conf
systemctl restart httpd

4.安装mariadb

yum install mariadb-server mariadb  -y
systemctl start mariadb
systemctl enable mariadb
mysql_secure_installation //修改root默认密码
mysql -uroot -p //登录mariadb测试

5.测试apache和php

cd /var/www/html
#vim index.php
<?php
phpinfo();
?>

http://192.168.1.2

CentOS7单机部署lamp环境和apache虚拟主机

6.测试php和mariadb

cd /var/www/html
#vim index.php
<?php
$link=mysql_connect('localhost','root','mysql密码')
if($link)
echo "successfuly";
else
echo "Faile";
mysql_close();
?>

http://192.168.1.2

CentOS7单机部署lamp环境和apache虚拟主机

7.apache目录介绍

# ll /etc/httpd/
conf //配置文件目录
conf.d //配置文件目录
conf.modules.d //模块目录
logs -> ../../var/log/httpd //日志目录
modules -> ../../usr/lib64/httpd/modules //模块目录
run -> /run/httpd //httpd进程pid在这个文件

8.apache配置文件详解

ServerRoot "/etc/httpd"						//安装目录
Listen 80 //监听端口
User apache //运行apache的用户
Group apache //运行apache的用户组
DocumentRoot "/var/www/html" //站点默认主目录
IncludeOptional conf.d/*.conf //包含conf.d/*.conf的文件
<Directory "/var/www"> //设定访问控制权限,如果修改了站点主目录,这里也需要修改
AllowOverride None
# Allow open access:
Require all granted //允许所有主机访问
</Directory>

(3)虚拟主机:基于主机地址

1.配置主机地址www.test.com的虚拟主机

#vim /etc/httpd/conf.d/blog.conf
<VirtualHost *:80>
DocumentRoot "/var/www/blog"
ServerName blog.test.com
ErrorLog "/var/log/blog-error_log"
CustomLog "/var/log/blog-access_log" common
</VirtualHost>
<Directory "/var/www/blog">
AllowOverride None
Require all granted
</Directory>

2.创建目录,修改属主,准备主页

mkdir /var/www/blog
chown -R apache.apache /var/www/blog
echo "blog.test.com" >>/var/www/blog/index.html

3.检查配置文件和重启服务

httpd -t
systemctl restart httpd

4.修改windows的hosts文件

编辑:C:\Windows\System32\drivers\etc\hosts添加一下记录
192.168.111.151 blog.test.com

5.使用浏览器测试访问

CentOS7单机部署lamp环境和apache虚拟主机

上一篇:leecode刷题(13) -- 字符串中的第一个唯一字符


下一篇:Linux学习笔记之阿里云ECS部署LAMP环境