Windows下Apache部署多个php项目

简介: 在 Windows 系统下,使用 Apache 服务器发布多个 PHP 项目是一项常见的任务。本文将介绍如何在 Windows 操作系统下使用 Apache 发布多个 PHP 项目。在 Windows 操作系统下使用 Apache 发布多个 PHP 项目可能有一些挑战,但是只要您按照本文的步骤进行操作,您就可以成功地完成这项任务。希望本文能够对您有所帮助。

一、安装 Apache

如果没有安装 Apache,可以参考我之前的文章 Windows用Apache发布php网站 进行安装;


二、准备好两个可运行的php项目

项目放到预发布的文件夹里,一会需要填写项目路径;


三、修改 httpd.conf 文件

接下来,您需要修改 Apache 的主配置文件 httpd.conf。具体步骤如下:

1. 增加监听端口

找到 Listen:60 (这是我的 Apache 端口);

在下面加入一个新的监听端口 Listen:61 (这是我要增加的第二个项目的 Apache 端口);

#
# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, instead of the default. See also the <VirtualHost># directive.
#
# Change this to Listen on specific IP addresses as shown below to 
# prevent Apache from glomming onto all bound IP addresses.
#
#Listen 12.34.56.78:80
Listen 60
Listen 61
#
# Dynamic Shared Object (DSO) Support
#

2. 增加虚拟主机(VirtualHost)

在 httpd.conf 文件中增加两个项目的虚拟主机,并配置项目地址。

具体配置如下:

# 第一个项目
<VirtualHost*:60>    DocumentRoot "C:\PHP_Project\www" <!--这里换成你的A项目目录-->    ServerName project1.local <!--服务名,用不到就随便填-->    ServerAlias a.test1.com <!--域名,用不到就随便填-->    ErrorLog "logs/project1_error.log" <!--日志地址-->    CustomLog "logs/project1_access.log" common <!--日志地址--><Directory"C:\PHP_Project\www"><!--这里换成你的A项目目录-->        Options Indexes FollowSymLinks
<!--对于php项目很关键,All表示开启url重写,方便未来做伪静态-->        AllowOverride All 
        Require all granted
</Directory></VirtualHost># 第二个项目
<VirtualHost*:61>    DocumentRoot "C:\PHP_Project\www1" <!--这里换成B项目目录-->    ServerName project2.local 
    ServerAlias a.test2.com 
    ErrorLog "logs/project2_error.log"
    CustomLog "logs/project2_access.log" common
<Directory"C:\PHP_Project\www1">        Options Indexes FollowSymLinks
        AllowOverride All 
        Require all granted
</Directory></VirtualHost>

替换掉原先的这一段:

DocumentRoot "C:\PHP_Project\www"
<Directory"C:\PHP_Project\www">    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.4/mod/core.html#options
    # for more information.
    #
    Options Indexes FollowSymLinks
    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    AllowOverride All
    #
    # Controls who can get stuff from this server.
    #
    Require all granted
</Directory>

四、打开防火墙和安全组

打开防火墙端口拦截:[控制面板->系统与安全->防火墙->高级设置->出入站规则]里开放60、61端口,如果主机上无法直接改出入站规则,在云管理面板上一般可以修改。

打开安全组端口拦截:安全组在云管理面板上,修改时容易遗漏。


五、公网验证

我们客户端浏览器输入ip:port可以访问,就说明我们发布成功,60、61分别部署的项目都可以各自访问了,至此,Windows下Apache部署多个php项目的配置完成。

目录
相关文章
|
12天前
|
关系型数据库 MySQL PHP
unbuntu搭建LAMP(Apache2+PHP+MySQL+phpmyadmin)
unbuntu搭建LAMP(Apache2+PHP+MySQL+phpmyadmin)
|
20天前
|
存储 文件存储 数据安全/隐私保护
Windows部署开源文件管理器File Browser并实现远程访问本地文件
Windows部署开源文件管理器File Browser并实现远程访问本地文件
52 1
|
20天前
|
安全 Linux 数据安全/隐私保护
Windows 部署 Elasticsearch + kibana 8.0 指南
Windows 部署 Elasticsearch + kibana 8.0 指南
33 0
|
20天前
|
安全 Linux 网络安全
Linux _ apache服务器部署 不同域名—访问不同网站(多网站)
Linux _ apache服务器部署 不同域名—访问不同网站(多网站)
|
20天前
|
开发框架 JavaScript 安全
WIndows Server 2016 部署 Web服务(简单篇)
WIndows Server 2016 部署 Web服务(简单篇)
|
20天前
|
安全 测试技术 网络安全
WIndows Server 2016 部署 PKI + 证书
WIndows Server 2016 部署 PKI + 证书
|
20天前
|
存储 文件存储 Windows
WIndows 2016 部署WDS
WIndows 2016 部署WDS
|
20天前
|
网络安全 API Apache
如何在win系统部署Apache服务并实现无公网ip远程访问
如何在win系统部署Apache服务并实现无公网ip远程访问
|
20天前
|
人工智能 安全 机器人
AI电销机器人系统源码部署:freeswitch安装Windows
在Windows上安装FreeSWITCH:访问官网下载安装程序,运行并按提示安装;选择安装路径和组件;等待安装完成;配置FreeSWITCH,修改设置;启动服务;测试其功能;如遇问题,参考官方文档或进行调试故障排除。记得定期更新维护以保证稳定安全。

推荐镜像

更多