Treehouse: Grow your CSS skills. Land your dream job.

development and production websites confusion

  • # December 16, 2011 at 4:57 am

    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?

    # December 16, 2011 at 7:22 am

    Use relative paths everywhere would be my suggestion. I avoid absolute paths as much as possible, so instead of pointing to an image like this:

    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!

    # December 16, 2011 at 7:28 am

    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, 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.

    # December 16, 2011 at 7:59 am

    are you using WordPress?

    # December 16, 2011 at 8:00 am

    No, bespoke sites.

    # December 16, 2011 at 9:50 am

    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.

    Then you just don’t upload it.

    # December 16, 2011 at 11:04 am

    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

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.