Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 859
Polypheme Avatar asked Feb 15 '09 18:02

Polypheme


People also ask

How do I deploy a web application locally?

Deploy an ApplicationIn the Project Explorer view, right-click {project name} and click Run As ▸ Run on Server. Ensure Choose an existing server is selected. From the table of servers, expand localhost , select the server on which to deploy the application and click Finish .


2 Answers

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.
like image 169
Bob Fanger Avatar answered Sep 20 '22 14:09

Bob Fanger


1) To solve the "different configuration on dev and live servers" problem I use this:

// Change 'localhost' to your dev server's address
define('IS_LIVE', 'localhost' != $_SERVER['HTTP_HOST']);

// Database configuration
$db_cfg = IS_LIVE?
  array(...): // Live server config
  array(...); // Dev server config

2) To keep the dev and live files synched I use Beyond Compare, a visual diff tool that allows me to compare whole directories, including remote ones via (S)FTP.

I set up a profile so that the left window shows files on dev server, the right one shows files on live server. This way I can see what differences there are between the servers (changed, missing or added files) and allows me to easily copy whole directories, files, or specific lines in files between them. Very useful.

It also lets you 'ignore' particular directories that you don't want to synch, like the ones with user generated files or logs.

like image 41
Michał Tatarynowicz Avatar answered Sep 21 '22 14:09

Michał Tatarynowicz