By tysonibele
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?
Thanks!
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!
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.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.