温馨提示×

centos lamp虚拟主机配置

小樊
58
2025-04-12 21:44:14
栏目: 云计算

在CentOS上配置LAMP(Linux, Apache, MySQL, PHP)虚拟主机涉及多个步骤,以下是详细的步骤说明:

  1. 环境准备

    • 安装CentOS 7.x 64位操作系统。
    • 配置网络,可以使用NetworkManager图形工具或手动编辑配置文件。
  2. 关闭防火墙和SELinux

    • 临时关闭firewalld:
      systemctl stop firewalld 
    • 永久关闭firewalld:
      systemctl disable firewalld 
    • 关闭SELinux(需重启):
      vi /etc/selinux/config SELINUX=disabled reboot 
  3. 安装必要的软件包

    • 安装编译工具:
      yum install gcc gcc-c++ make 
    • 安装Apache、MySQL、PHP及其相关模块:
      yum install httpd mariadb-server php php-mysqlnd 
  4. 配置Apache

    • 编辑Apache配置文件:
      vi /usr/local/apache/conf/httpd.conf 
    • 在配置文件中添加以下内容:
      Listen 80 ServerName your_domain_or_ip DocumentRoot /var/www/html <Directory /var/www/html> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> 
    • 启动并启用Apache服务:
      systemctl start httpd systemctl enable httpd 
  5. 配置MySQL

    • 启动MySQL服务:
      systemctl start mariadb 
    • 设置MySQL开机自启动:
      systemctl enable mariadb 
    • 运行安全安装脚本以配置MySQL:
      mysql_secure_installation 
  6. 配置虚拟主机(可选):

    • 创建新的虚拟主机配置文件:
      vi /usr/local/apache/conf/extra/httpd-vhosts.conf 
    • 添加以下内容(替换your_domain为实际域名):
      <VirtualHost *:80> ServerName your_domain DocumentRoot /var/www/your_domain <Directory /var/www/your_domain> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> </VirtualHost> 
    • 重启Apache以应用配置:
      systemctl restart httpd 

通过以上步骤,您可以在CentOS上成功配置LAMP虚拟主机。

0