John Davidson

php - Share assets folder between two subdomain's document roots

0 comments
Message:


I have two web apps that share the same assets (js, css, img etc.) but use different subdomains/document roots.


I'm trying to figure out how i can share one assets folder between the two document roots, so i can avoid having to change the assets folder for each subdomain after i apply changes to the assets.


Thanks for your time.


Current Structure:


www/html
├─ subdomain1
│ └─ assets
│ └─ index.php
└─ subdomain2
└─ assets
└─ index.php

Desired Structure:


www/html
├─ assets
├─ subdomain1
│ └─ index.php
└─ subdomain2
└─ index.php

VHost Confs:


subdomain one:


<VirtualHost *:80>
ServerName www.one.mydomain.com
ServerAlias one.mydomain.com
ServerAdmin [email protected]
DocumentRoot /var/www/html/subdomain1/

<Directory /var/www/html/subdomain1/>
Options -Indexes +FollowSymLinks
AllowOverride All
DirectoryIndex index.php
</Directory>

ErrorLog /var/www/html/logs/subdomain1-error.log
CustomLog /var/www/html/logs/subdomain1-access.log combined
</VirtualHost>

subdomain two:


<VirtualHost *:80>
ServerName www.two.mydomain.com
ServerAlias two.mydomain.com
ServerAdmin [email protected]
DocumentRoot /var/www/html/subdomain2/

<Directory /var/www/html/subdomain2/>
Options -Indexes +FollowSymLinks
AllowOverride All
DirectoryIndex index.php
</Directory>

ErrorLog /var/www/html/logs/subdomain2-error.log
CustomLog /var/www/html/logs/subdomain2-access.log combined
</VirtualHost>


My Answer:
To share an assets folder between two subdomains in PHP, you can create a symbolic link from one subdomain's assets folder to the other subdomain's assets folder.

Here's how you can do it:

1. Connect to your server using SSH or FTP.

2. Navigate to the root directory of the subdomain from which you want to share the assets folder.

3. Create a symbolic link to the assets folder of the other subdomain using the following command:

bash
ln -s /path/to/other/subdomain/assets /path/to/current/subdomain/assets


Replace `/path/to/other/subdomain/assets` with the actual path to the assets folder of the other subdomain, and `/path/to/current/subdomain/assets` with the path to the assets folder of the current subdomain.

4. Verify that the symbolic link has been created successfully by listing the contents of the current subdomain's assets folder:

bash
ls -l /path/to/current/subdomain/assets


You should see a symbolic link pointing to the assets folder of the other subdomain.

5. Now, any files or assets placed in the assets folder of the other subdomain will be accessible from the assets folder of the current subdomain as well.

By creating a symbolic link, you can easily share assets between two subdomains without duplicating files and consuming extra storage space.

Rate this post

4 of 5 based on 3213 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us