5

What is the best and most efficient way to set up two versions of the same website?

I want one version that is online and open for everyone to use but I also want a developer version where I can develop and test new things instead of doing that against the ftp.

Currently I have MAMP setup on my developing machine and I use Git for version control.

In MAMP/XAMPP the location for the files are localhost/example/ and on the ftp it is the host's (Dreamhost's in this case) file structure. Something like /home/username/example.com/. That results in having multiple versions of pretty much the same file. This isn't that efficient but I can't come up with a good solution for it. Are there any?

It would be perfect if I wanted to add a new feature to the website I could do that in MAMP and when i commit the changes with Git it uploads the changes to the ftp.

2 Answers2

6

Forget about FTP.

  • Setup a bare repository on the server
  • Add it as remote to your development environment.
  • Clone the bare repo to the webspace, adapt the configuration files.
  • Add a post-commit hook on the bare repo, starting a shell script on the webspace that pulls from the bare repo.

With that, you just push your changes to remote, and it is automagically drawn into the webspace.

Any environment specific constants do not belong to the code, but into configuration files, which are added to .gitignore.

nibra
  • 678
2

what I do with XAMP is that I have on my local an entry called a.com that points to my 127.0.0.1

so i reference pages as a.com/....

Keep the same files in both the places. have some custom include that checks if the current page has a.com and makes root links differently. Something like :

if( $_SERVER['SERVER_NAME'] == 'a.com'){
    $filePath = 'images/'
    $url = "http://a.com";
    $env = 'd';
}else{
    $imgPath = '/home/sites/example/images/'
    $path2 = "http://example.com";
    $env = 'p';
}

    //now this can be an include file in other files
    //in the other files just use the previously initialized variables when making paths and URLs. This keeps the code in the main files simple and the details in one file
tgkprog
  • 610