能否在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.
Organize your directory structure
- Log into Plesk’s File Manager and navigate to the
httpdocsfolder (your web root). - Create two separate folders to hold your full project code: let’s name them
app1_rootandapp2_root. Upload all files from your first project toapp1_root, and all files from your second project toapp2_root. - Next, create two public-facing folders in
httpdocs:app1andapp2. Move all contents ofapp1_root/publicintohttpdocs/app1, and do the same forapp2_root/public→httpdocs/app2.
- Log into Plesk’s File Manager and navigate to the
Update the project entry points (
index.php)- Open
httpdocs/app1/index.phpand 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 outapp1_rootforapp2_root.
- Open
Set up URL rewriting (Windows-specific
Web.config)- Each public subfolder (
app1andapp2) needs aWeb.configfile 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>
- Each public subfolder (
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.
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.
- Head to Plesk’s "Domains" section, click "Add Domain", and create your subdomain (e.g.,
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 itspublicfolder contents intohttpdocs, and updateindex.phpto point toapp1_root.
- Use the exact method from Sancho Almeda’s guide you followed before: place your main project’s core files outside
Deploy your subdomain project
- Upload your second project’s full code to a folder like
app2_root(either inside or outsidehttpdocs—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.phpto 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.configfile from Scenario 1 toapp2_root/publicfor URL rewriting.
- Upload your second project’s full code to a folder like
Key Tips to Avoid Issues
- File Permissions: Make sure the
IIS_IUSRSuser (Windows web server user) has read/write access to your projects’storageandbootstrap/cachefolders—this prevents runtime errors. - Secure
.envFiles: Keep each project’s.envfile in its root folder (e.g.,app1_root/.env), not in the publichttpdocsdirectories—never expose sensitive configs to the web. - Composer Dependencies: If your projects use Composer, run
composer installin 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

