php进阶-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 
# 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 文件中增加两个项目的虚拟主机,并配置项目地址。
具体配置如下:

# 第一个项目

    DocumentRoot "C:\PHP_Project\www" 
    ServerName project1.local 
    ServerAlias a.test1.com 
    ErrorLog "logs/project1_error.log" 
    CustomLog "logs/project1_access.log" common 
    
        Options Indexes FollowSymLinks
        
        AllowOverride All 
        Require all granted
    

 
# 第二个项目

    DocumentRoot "C:\PHP_Project\www1" 
    ServerName project2.local 
    ServerAlias a.test2.com 
    ErrorLog "logs/project2_error.log"
    CustomLog "logs/project2_access.log" common
    
        Options Indexes FollowSymLinks
        AllowOverride All 
        Require all granted
    

替换掉原先的这一段:

DocumentRoot "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

四、打开防火墙和安全组

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

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

五、公网验证

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

你可能感兴趣的:(PHP,php,apache,开发语言,运维)