I have two domains on my LAMP server, however my second domain points to my first virtual host.

Hi All,

I currently have two domains pointing to my digital ocean LAMP Server. I have a directory for each domain in the /var/www directory. /var/www/domain1 and /var/www/domain2. I also kept the /var/www/html directory as default.

I have created a .config file for each directory in /etc/apache2/sites-available/ domain1.config and domain2.config. See below:

<VirtualHost * :80>
ServerName domain1
ServerAlias www.domain1
ServerAdmin webmaster@localhost
Errorlog $(APACHE LOG DIR}/error.log
Customlog $(APACHE LOG DIR}/access.log combined

<VirtualHost * :80>
ServerName domain2
ServerAlias www.domain2
ServerAdmin webmaster@localhost
Errorlog $(APACHE LOG DIR}/error.log
Customlog $(APACHE LOG DIR}/access.log combined

I then enable both virtual hosts with:

sudo a2ensite domain1
sudo a2ensite domain2 
sudo systemctl reload apache2

when I type in my browser the correct website is served. However, if I type the domain1 website is served.

The only way I can get website to run is by turning off the first virtual host

sudo a2dissite domain1
sudo systemctl reload apache2

Now if I type the correct website is displayed.

What can I do to enable both sites?

Submit an answer
Answer a question...

This textbox defaults to using Markdown to format your answer.

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

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bobby Iliev
Site Moderator
Site Moderator badge
August 28, 2022

Hi there,

Usually I’ve seen this happen when the new directory does not have read and write permissions for the Apache user.

You could run the following command to change the owner of the files and the directories for your new website:

sudo chown -R www-data:www-data /var/www/domain2

That way the Apache user should now have read and write access and should be able to display the content of that directory.

Make sure to also clear the cache of your browser after you’ve changed the ownership.

If this still does not work, I could suggest checking your Apache logs for any errors:

tail -100 /var/log/apache2/error.log

Let me know how it goes!