Search code examples
phpversion-controldeploymentftpweb-deployment-project

Web app deployment Best Practices : how to manage local & live files?


I am writing php web applications, and simply deploy them via FTP. To make it work, I often have some tweaking/debugging to do given that I have little control over the (free) web server hosting me, so what's working in my local environment might not work live.

For example I keep a separate php file containing class_db_myapp.php which extends a class_db.php with specific DB parameters : db name, username, password which won't be the same local and live. (For information : Lately I started using git for version control)

As my app evolves, some files get renamed / deleted / created. When comes the time to upload a new version, I have to either rely on my memory to know what I have to upload / delete or simply delete all / upload all. But in the second case I need to avoid erasing the class_db_myapp.php file...

I haven't come up with a proper solution to this.

What are the best practices in this domain?

I may have missed an existing discussion on this subject, if so please point me to it.

Thank you.


Solution

  • If the ftp server supports symbolic links you can use the following technique:

    1. Make the public_html folder a symlink to the folder containing the current version. ("version1" for example)
    2. Upload the new version in a new folder.
    3. When the upload is completed, modify the symlink so the new version becomes active.

    If something went wrong you can easily revert to the previous version by modifying the symlink again.

    For database and other settings that are different in the live environment, there are several options:

    • Create a file containing environment: "live" or "local" and put "if statement" in the code based on the environment setting.
    • If you're able to dectect the enviroment in php, use that instead of a file.
    • Place all settings in a file outside the "versionX" folders.