views:

46

answers:

2

Recently I've been getting more and more into web development and as such have a few questions. I have a few websites that are on a production LAMP server and I've been trying to copy them to my local computer running xampp 1.7.1 on XP Pro. The problem I've been having is mostly path issues. I mainly develop for wordpress, joomla, magento, mediawiki. When I copy the site locally I end up having to change config files and/ or database fields to reflect the local path. The problem I always have is anytime I upload files that contain local paths back up to the server I have to change the paths back to the production paths or I get 'object not found' errors. Remembering the correct paths for each install and what files need to have path updates is a real pain. Is there something I'm missing? Is there an easier way to make sure the paths are correct whether I'm on production or development without having to manually change them every time I upload or download the file or database?

+1  A: 

Yes, what you're missing is an automated deployment system. For linux, there is capistrano, and other such ones, that you may look at (note: I've written one for Windows, but it's not useful for you).

Noon Silk
A: 

Ideally, you should have a line of code in your main config file which is able to determine what server the code is running on. I use something like the following:

if(__FILE__ === '/home/peter/web_projects/my-project/config.php') {
    // set up configuration for development environment
    define('DEV', true);
    [etc]
}
else {
    // code is running on the live server
    define('DEV', false);
    [etc]
}

This allows me to have the same config.php on my development machine as well as live, and any other files can just check the DEV constant to know if they are local or live.

too much php