I'm new to having a local copy of a website with MAMP and uploading any changes to the production site (using Coda). I'm struggling on how I prevent specific local settings (DB, local path etc.) in my PHP files overwriting the production server settings and crashing it? I'd rather not have to publish a config file to the production site, then go have to update all the settings again for the production environment, but can only guess I have to do it?
When pointing to the database, always point to "localhost", so no matter what environment you're working on, it will always use the database on the same server where your files are.
Thanks. Yes I had been using the relative paths for the images, which was lucky but I've found that I have some problems with the $_SERVER['DOCUMENT_ROOT'], that I use to reference some resources outside of the web root, being unavoidably very different on both locations.
It was hardcoded when I worked only remotely on the site, but now I find I need to set it for the development site in my config file, then upload to production, then re-edit remotely to fix it for the new server.
Personally I keep all of my global domain variables in a separate file called site.config. This holds all of the PHP constants that change between local server and my hosting.
Great, thanks guys. I like to keep my sites as 'portable' as possible, so as they could be picked up from one host and dropped onto another with very little fuss/downtime etc. I've spent years just working on them 'live', but trying to take a more considered approach now with development/production stages. :D
I'm struggling on how I prevent specific local settings (DB, local path etc.) in my PHP files overwriting the production server settings and crashing it?
I'd rather not have to publish a config file to the production site, then go have to update all the settings again for the production environment, but can only guess I have to do it?
I will do something like this:
If you don't use any of that anywhere (when calling your CSS, Javascripts, etc.) the both local and production won't get in eachother's way:
When pointing to the database, always point to "localhost", so no matter what environment you're working on, it will always use the database on the same server where your files are.
Hope that makes sense!
It was hardcoded when I worked only remotely on the site, but now I find I need to set it for the development site in my config file, then upload to production, then re-edit remotely to fix it for the new server.
Then you just don't upload it.