Hosting more than one domain on a droplet -- will setting up virtual hosts break my current mysql setup?

December 9, 2014 685 views

I have a mysql database that I currently access with a php file, in the following setup:

[my site's current url]/php/scores.php

Within the php file, I connect to the database through 'localhost'.

The problem is, I'd like to start hosting more than one domain on my droplet. I read about implementing virtual hosts. That's fine, and I can move my php files to match up to the new url subdirectories in the virtual host root folder.

However, the php files access the mysql database through 'localhost'. Once I setup virtual hosts, will that need to change? Or is mysql 'localhost' location independent of any virtual hosting setup?


1 Answer

This will not change at all. The virtualhosts you set up in your web server do not have any effect on MySQL. localhost refers to the database server being on the same server as the web script calling on it and this configuration would continue to work. A virtualhost is simply a method to let your web server know to handle traffic for different domain names differently even if that traffic comes in on the same IP address.

Have another answer? Share your knowledge.