CentOS7 安装 Apache

  1. 检查是否安装
    rpm -qa httpd

  2. 安装
    sudo yum install httpd

  3. 启动
    sudo systemctl start httpd.service

  4. 永久开启80端口
    sudo firewall-cmd --permanent --zone=public --add-port=80/tcp

  5. 重启 防火墙
    sudo systemctl restart firewalld.service

  6. 设置服务开机启动
    sudo systemctl enable httpd.service

  7. 相关操作
    状态:systemctl status httpd.service
    启动:systemctl start httpd.service
    停止:systemctl stop httpd.service
    重启:systemctl restart httpd.service
    开机 自启动:systemctl enable httpd.service
    取消 开机 自启动:sudo systemctl disable httpd.service

  8. 创建虚拟机

    • 创建虚拟主机相关目录
      网站目录:mkdir /var/www/html/magento2ce
      日志目录:sudo mkdir /var/log/httpd/magento2ce
      虚拟主机配置目录:sudo mkdir /etc/httpd/vhost-conf.d
    • 创建虚拟主机配置文件
      sudo touch /etc/httpd/vhost-conf.d/magento2ce.conf
    • 配置虚拟机
      vim /etc/httpd/vhost-conf.d/magento2ce.conf
      添加以下内容

              # 监听所有IP的80端口
              
                  # 管理员的邮件地址
                  ServerAdmin [email protected] 
      
                  # 设置虚拟机域名
                  ServerName magento2ce.com 
      
                  # 虚拟机网站根目录
                  DocumentRoot /var/www/html/magento2ce
      
                  # 错误日志
                  ErrorLog /var/log/httpd/magento2ce/error_log
      
                  # 访问日志
                  CustomLog /var/log/httpd/magento2ce/access_log common
              
              
                  Options -Indexes +Includes +FollowSymLinks +MultiViews
      
                  AllowOverride All
      
                  #允许所有请求
                  Require all granted
               
    • 自动加载虚拟机配置文件
      sudo sh -c ' echo "Include vhost-conf.d/*.conf" >> /etc/httpd/conf/httpd.conf'
    • 重启Apache
      sudo systemctl restart httpd.service
  9. 开启rewrite重写引擎
    开启重写
    sudo sh -c ' echo "LoadModule rewrite_module modules/mod_rewrite.so" >> /etc/httpd/conf/httpd.conf'
    重启Apache
    sudo systemctl restart httpd.service

你可能感兴趣的:(centos,Apache)