安装Apache2.4与php7.4

将Apache2.4的安装目录中的bin目录添加至环境变量

安装apache服务

通过命令行httpd安装Apache服务,将Apache服务添加到系统服务

httpd -k install -n "Apache2.4"

安装成功后出现 The 'Apache2.4' service is successfully installed.

启动apache服务

httpd -k start
或者
net start Apache2.4

也可以通过bin目录下的ApacheMonitor.exe进行可视化操作,开启apache服务。

Apache中添加PHP

打开Apache/conf/httpd.conf文件,并添加以下配置

LoadModule php7_module "{{可以填入绝对路径}}Apache/php-7.4.24/php7apache2_4.dll"
AddType application/x-httpd-php  .php
#configure the path to php.ini
PHPIniDir "{{php.ini所在目录的绝对路径}}"

Apache修改站点目录,开启虚拟主机配置及目录权限

Options Indexes FollowSymLinks 目录下没有index.html或index.php会显示目录文件

Options FollowSymLinks 禁止显示目录文件

DocumentRoot "${SRVROOT}/htdocs"
#站点文档目录
<Directory "${SRVROOT}/htdocs">
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>
#根目录
<Directory />
    AllowOverride none
    Require all denied
</Directory>
#默认主页修改
<IfModule dir_module>
    DirectoryIndex index.php index.html
</IfModule>
#开启虚拟主机配置文件
# Virtual hosts
Include conf/extra/httpd-vhosts.conf

Apache虚拟主机文件配置

同时在windows的hosts文件中配置好主机名,即可访问。

#重新配置站点目录权限,覆盖httpd.conf中的目录权限配置
<Directory "${SRVROOT}/htdocs">
    Options FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>
#配置多个虚拟主机
<VirtualHost *:80>
    DocumentRoot "${SRVROOT}/htdocs/test1.com"
    ServerName test1.com
    ErrorLog "logs/dummy-host2.example.com-error.log"
    CustomLog "logs/dummy-host2.example.com-access.log" common
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "${SRVROOT}/htdocs/test2.com"
    ServerName test2.com
    ErrorLog "logs/dummy-host2.example.com-error.log"
    CustomLog "logs/dummy-host2.example.com-access.log" common
</VirtualHost>

标签: php

添加新评论