You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

能否在Plesk Windows共享主机httpdocs中部署两个PHP项目?

Hey there! Great to hear the previous Laravel deployment guide worked well for you—good news, you absolutely can deploy two PHP projects (like Laravel apps) on your Plesk Windows shared host using a similar approach. Let’s break down the two most common scenarios and how to set them up properly:

Scenario 1: Two projects via subpaths on your main domain (e.g., yourdomain.com/app1 & yourdomain.com/app2)

This works if you want both apps accessible under your primary domain, each with a unique subfolder path.

  1. Organize your directory structure

    • Log into Plesk’s File Manager and navigate to the httpdocs folder (your web root).
    • Create two separate folders to hold your full project code: let’s name them app1_root and app2_root. Upload all files from your first project to app1_root, and all files from your second project to app2_root.
    • Next, create two public-facing folders in httpdocs: app1 and app2. Move all contents of app1_root/public into httpdocs/app1, and do the same for app2_root/public → httpdocs/app2.
  2. Update the project entry points (index.php)

    • Open httpdocs/app1/index.php and adjust the paths to point back to your project’s root folder:
      require __DIR__ . '/../app1_root/vendor/autoload.php';
      $app = require_once __DIR__ . '/../app1_root/bootstrap/app.php';
      
    • Repeat this for httpdocs/app2/index.php, swapping out app1_root for app2_root.
  3. Set up URL rewriting (Windows-specific Web.config)

    • Each public subfolder (app1 and app2) needs a Web.config file to handle clean URLs (critical for frameworks like Laravel). If your project doesn’t include one, create a file in each folder with this content:
      <?xml version="1.0" encoding="UTF-8"?>
      <configuration>
          <system.webServer>
              <rewrite>
                  <rules>
                      <rule name="Remove trailing slash" stopProcessing="true">
                          <match url="^(.*)/$" ignoreCase="false" />
                          <conditions>
                              <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                          </conditions>
                          <action type="Redirect" redirectType="Permanent" url="/{R:1}" />
                      </rule>
                      <rule name="Rewrite to index.php" stopProcessing="true">
                          <match url="^" ignoreCase="false" />
                          <conditions>
                              <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                              <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                          </conditions>
                          <action type="Rewrite" url="index.php" />
                      </rule>
                  </rules>
              </rewrite>
          </system.webServer>
      </configuration>
      

Scenario 2: One project on main domain, one on a subdomain (e.g., yourdomain.com & app2.yourdomain.com)

This is cleaner for fully independent apps, as each gets its own dedicated domain.

  1. Add the subdomain in Plesk

    • Head to Plesk’s "Domains" section, click "Add Domain", and create your subdomain (e.g., app2.yourdomain.com).
    • When configuring the subdomain, you’ll set its document root later—hold off on that for now.
  2. Deploy your main domain project

    • Use the exact method from Sancho Almeda’s guide you followed before: place your main project’s core files outside httpdocs (e.g., app1_root), move its public folder contents into httpdocs, and update index.php to point to app1_root.
  3. Deploy your subdomain project

    • Upload your second project’s full code to a folder like app2_root (either inside or outside httpdocs—outside is more secure).
    • Go back to Plesk’s subdomain settings, and set its document root to app2_root/public (the public folder of your second project).
    • Update app2_root/public/index.php to point to the correct project root path, e.g.:
      require __DIR__ . '/../vendor/autoload.php';
      $app = require_once __DIR__ . '/../bootstrap/app.php';
      
    • Add the same Web.config file from Scenario 1 to app2_root/public for URL rewriting.

Key Tips to Avoid Issues

  • File Permissions: Make sure the IIS_IUSRS user (Windows web server user) has read/write access to your projects’ storage and bootstrap/cache folders—this prevents runtime errors.
  • Secure .env Files: Keep each project’s .env file in its root folder (e.g., app1_root/.env), not in the public httpdocs directories—never expose sensitive configs to the web.
  • Composer Dependencies: If your projects use Composer, run composer install in each project’s root folder (use Plesk’s built-in Terminal tool if your host allows it, or install dependencies locally before uploading).

内容的提问来源于stack exchange,提问作者Santosh Randive

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.09 19:27:36