阅读量:124
在CentOS上配置LAMP(Linux, Apache, MySQL, PHP)虚拟主机涉及多个步骤,以下是详细的步骤说明:
-
环境准备:
- 安装CentOS 7.x 64位操作系统。
- 配置网络,可以使用NetworkManager图形工具或手动编辑配置文件。
-
关闭防火墙和SELinux:
- 临时关闭firewalld:
systemctl stop firewalld - 永久关闭firewalld:
systemctl disable firewalld - 关闭SELinux(需重启):
vi /etc/selinux/config SELINUX=disabled reboot
- 临时关闭firewalld:
-
安装必要的软件包:
- 安装编译工具:
yum install gcc gcc-c++ make - 安装Apache、MySQL、PHP及其相关模块:
yum install httpd mariadb-server php php-mysqlnd
- 安装编译工具:
-
配置Apache:
- 编辑Apache配置文件:
vi /usr/local/apache/conf/httpd.conf - 在配置文件中添加以下内容:
Listen 80 ServerName your_domain_or_ip DocumentRoot /var/www/htmlOptions Indexes FollowSymLinks AllowOverride All Require all granted - 启动并启用Apache服务:
systemctl start httpd systemctl enable httpd
- 编辑Apache配置文件:
-
配置MySQL:
- 启动MySQL服务:
systemctl start mariadb - 设置MySQL开机自启动:
systemctl enable mariadb - 运行安全安装脚本以配置MySQL:
mysql_secure_installation
- 启动MySQL服务:
-
配置虚拟主机(可选):
- 创建新的虚拟主机配置文件:
vi /usr/local/apache/conf/extra/httpd-vhosts.conf - 添加以下内容(替换
your_domain为实际域名)::80 > ServerName your_domain DocumentRoot /var/www/your_domainOptions Indexes FollowSymLinks AllowOverride All Require all granted - 重启Apache以应用配置:
systemctl restart httpd
- 创建新的虚拟主机配置文件:
通过以上步骤,您可以在CentOS上成功配置LAMP虚拟主机。