美文网首页PHP学习Centos相关我爱编程
CentOS云服务器,配置Apache多域名虚拟机【最新教程】,

CentOS云服务器,配置Apache多域名虚拟机【最新教程】,

作者: 我爱余倩 | 来源:发表于2017-07-31 13:57 被阅读66次

    一、前言:

    1. 安装了Apache的云服务器,可以参考之前教程:'CentOS云服务器,配置FTP+LAMP【最新教程 10.23更新】,亲身失败百次的总结'
    2. Windows下安装 'Xshell'
    3. 使用 vi 指令

    二、步骤:

    1. Xshell 连接好云服务器(Xshell入门教程);
    2. 打开到 apache 配置存放目录:
      • cd /etc/httpd
    3. 可以看到 'httpd' 目录下有 'conf''conf.d' 两个文件夹;
    4. 'conf.d' 文件夹下新建 'vhost.conf'
      • vi conf.d/vhost.conf
    5. 'vhost.conf' 里面输入下面内容并保存:
      <VirtualHost *:80>                     ##此处端口要在 httpd.conf 设置监听
      ServerName "example.com"               ##此处填写你已经解析好A记录的域名
      DocumentRoot "/var/www/html/example"   ##此处填写你的网站根目录
      DirectoryIndex index.php index.html    ##此处填写访问网站时默认打开的文件
      </VirtualHost>
      
    6. 'conf' 文件夹下修改 'httpd.conf‘’ 为以下内容:
      #..................................others....................................
      
      # !!!!!-----------默认端口无修改---------!!!!!!
      Listen 80
      
      # !!!!!-----------将下面内容---------!!!!!!
      # Example:
      # LoadModule foo_module modules/mod_foo.so
      # !!!!!-----------修改为---------!!!!!!
      LoadModule rewrite_module modules/mod_rewrite.so
      Include conf.modules.d/*.conf
      
      #..................................others....................................
      
      # !!!!!-----------将下面内容---------!!!!!!
      # ServerName www.example.com:80
      # !!!!!-----------修改为---------!!!!!!
      ServerName localhost:80
      
      #..................................others....................................
      
      # !!!!!-----------在前面添加 '#'---------!!!!!!
      #DocumentRoot "/var/www/html"
      
      #..................................others....................................
      
      # !!!!!-----------将下面内容---------!!!!!!
      #<Directory "/var/www/html">
      #   Options Indexes FollowSymLinks
      #   AllowOverride None
      #   Require all granted
      #</Directory>
      # !!!!!-----------修改为---------!!!!!!
      <Directory "/var/www/html/example">
         Options Indexes FollowSymLinks
         AllowOverride all
         Allow from all
         Order allow,deny
         Require all granted
      </Directory>
      
      #..................................others....................................
      
    7. '/var/www/html' 新建 'example' 文件夹:
      • mkdir /var/www/html/example
    8. 'example' 文件夹下新建 'index.php'
      • vi /var/www/html/example/index.php
    9. 'index.php' 里面输入以下内容并保存:
      <?php
      phpinfo();
      ?>
      
    10. 修改 'example' 文件夹及其子文件的权限:
      • chmod 777 /var/www/html/example -R
    11. 重启 apache:
      • systemctl restart httpd.service
    12. 在浏览器输入 'example.com' 可以看到PHP的信息:
    13. 要配置更多个域名的虚拟机,只需在重复步骤 '5 ~ 12' 即可

    四、结语

    1. 本教程面向新手,更多教程会在日后给出。
    2. 随着系统升级,软件更新,以后的配置可能有所变化,在下会第一时间测试并且更新教程;
    3. 欢迎联系在下,讨论建议都可以,之后会发布其它的教程。

    相关文章

      网友评论

      本文标题:CentOS云服务器,配置Apache多域名虚拟机【最新教程】,

      本文链接:https://www.haomeiwen.com/subject/zuallxtx.html