Could I host different projects with different languages on the same droplet using different routes of the same domain?

August 14, 2018 1.7k views
Apache

That’s what I was trying to do (using Apache 16)
I have two enabled config files.

<VirtualHost *:80>
    ServerAdmin admin@something.com
    ServerName mydomain.com/project_1
    ServerAlias www.mydomain.com/project_1
    DocumentRoot /var/www/project1/public_html
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

And the other one (for an entirely different project) would be:

<VirtualHost *:80>
    ServerAdmin admin@something.com
    ServerName mydomain.com/project_2
    ServerAlias www.mydomain.com/project_2
    DocumentRoot /var/www/project2/public_html
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

I’ve tried it and it didn’t really work.

Do I need to change my domain droplet records to make it work? Because there’s no option for routes there..

I assume I did something stupid and that this question is very unprofessional, but still, I would love to get some help please :)

1 Answer

Hello friend!

Great question! What you would do here is use only one of these, and make it like this:

<VirtualHost *:80>
    ServerAdmin admin@something.com
    ServerName mydomain.com
    ServerAlias www.mydomain.com
    DocumentRoot /var/www
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Now create these two folders:
/var/www/project1
/var/www/project2

So traffic to mydomain.com/project1 or www.mydomain.com/project1 loads the contents of /var/www/project1, and so on for each project you need :)

Kind Regards,
Jarland

Have another answer? Share your knowledge.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!