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

  • Posted December 9, 2014

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?



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

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.

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.