[web] development environment

Started by
14 comments, last by BeanDog 14 years, 10 months ago
I'm a bit at a loss here as to how I should go about setting up a usable development environment for websites/web applications. Right now I'm doing all my PHP development simply by SSH'ing into my host server and then visiting the script I'm writing on the web to see if it works. Obviously, this is a less than optimal (incredibly slow and frustrating!) solution. So, how do people do this? Should I just install Apache/MySQL on my development machine and write/test the scripts locally? I could write some script to upload all the files to my webserver when I'm done, which would hopefully make getting my projects off my local machine and onto my webserver as transparent and efficient as possible. That's just an idea. Are there any sort of standard practices in web development? Things to keep in mind, precautions, etc?
Advertisement
My approach is like so (when working alone or in a team):

Run Apache on my dev machine and develop locally (it's a huge time-saver), but connect to remote database (which I manage via phpMyAdmin).

This is because without a database change-management tool, it can be a hassle making sure everyone's database schema is up to date if it's still changing.

To move code around, I'd recommend setting up source control (such as SVN) on your host machine if at all possible (if you can SSH in, I'd think so).

On your local dev machine, you work on a checked out copy of your code.

On your host, the live site is the latest version exported from SVN (export is a single command but you could wrap it in a script).

Whenever you want to update the live site, you just check in your code, connect to your server and run the export script.

This also makes it easier to run a couple of versions of the site on your host. For example, you could have a staging site and a live site both running.
Quote:Should I just install Apache/MySQL on my development machine and write/test the scripts locally?


Yes. Anything else would be maddening.

I personally run linux as my desktop OS, so i run Apache et al right off the desktop. That works great because most hosted machines are using linux as well. "When in Rome" as they say.

For Windows, there are meta packages you can install that automatically set up Apache, PHP, Perl, MySQL for you in 5 minutes. I'm not familiar with the current offerings, so i'll let someone else fill in if you need a Windows setup.

Quote:Should I just install Apache/MySQL on my development machine and write/test the scripts locally?


That's possible, but I prefer a separate development server. Grab any old PC you have, install Linux, install Apache, PHP (Perl and Python come pre-installed), MySQL, sshd and Subversion or Git. Also install the xdebug PHP extension and set up remote debugging/

On your local machine, install a decent editor or IDE that speaks SSH and the DBGp protocol. I much prefer (g)Vim with the DBGp plugin.

Now you can work remotely in the same way as you work locally and you have a complete PHP debugging environment. Keep your websites in Subversion and deploy directly from there.

<hr />
Sander Marechal<small>[Lone Wolves][Hearts for GNOME][E-mail][Forum FAQ]</small>

cbotman: I was wondering about how I'd manage to keep my databases identical, your idea to connect to the database is a good idea, I'll keep that in mind.

leivoia: My dev machine is running Linux, so I shouldn't need any Windows instructions. I can't imagine the headache trying to do this stuff in Windows anyway, it seems like Linux is really the only way to go when you're developing for a Linux based server with Apache, etc.

Sander: That's a good idea. I actually *just* bought a great new dev machine, and I'm looking for something to put my old dev machine use. I could install Ubuntu server and Apache etc on it and then develop over my LAN. Is there any real advantage to developing on a separate development server, besides simply not cluttering up your local machine?
Quote:Original post by SamithIs there any real advantage to developing on a separate development server, besides simply not cluttering up your local machine?


I'd say no, it's only going to add overheads in my opinion.

By the way, PHP/MySQL development is almost identical between Windows and Linux these days. I develop on Windows and host on Linux.

You don't even need to worry about the different directory separator in file paths.

Quote:Is there any real advantage to developing on a separate development server, besides simply not cluttering up your local machine?


Yes. First off, you can keep it running 24/7. Forward port 22 and 80 to your server and you can always access development versions of your sites, access your subversion repositories, etcetera.

Second, you can set weird configuration settings that you wouldn't want to make on your own machine. Does your webhost use SELinux and it's casuing you nightmares? Enable SELinux on your server and debug your websites, without having to enable it on your local machine (and cause all kinds of side effect that you don't want).

Third, you can create a setup that works better. For example, LVM on mdadm RAID5 or RAID6 is pretty nice for a webserver and subversion repository. There's not so much risk when a disk dies (but you should still make backups!) and you can achieve it relatively cheaply with e.g. 80GB drives you still have. I really, really wouldn't want to run my desktop on a RAID6. That would be painfully slow.

There are also many advantages of having a home server that have nothing to do with programming at all. For example, I use my home server for my backups. I have a script on all my other machines at home to rsync to the server when they shut down or reboot. Automatic backups without thinking about it. Great!

I also added a big RAID array to my server to store all my music and installed mpd (music player daemon) and icecast2 to play them randomly 24/7 and hooked the server line-out to the line-in of my stereo. I can listen to my music 24/7 anywhere in the world :-)

<hr />
Sander Marechal<small>[Lone Wolves][Hearts for GNOME][E-mail][Forum FAQ]</small>

Quote:Original post by Sander
Quote:Is there any real advantage to developing on a separate development server, besides simply not cluttering up your local machine?


Yes. First off, you can keep it running 24/7. Forward port 22 and 80 to your server and you can always access development versions of your sites, access your subversion repositories, etcetera.

Second, you can set weird configuration settings that you wouldn't want to make on your own machine. Does your webhost use SELinux and it's casuing you nightmares? Enable SELinux on your server and debug your websites, without having to enable it on your local machine (and cause all kinds of side effect that you don't want).

Third, you can create a setup that works better. For example, LVM on mdadm RAID5 or RAID6 is pretty nice for a webserver and subversion repository. There's not so much risk when a disk dies (but you should still make backups!) and you can achieve it relatively cheaply with e.g. 80GB drives you still have. I really, really wouldn't want to run my desktop on a RAID6. That would be painfully slow.

There are also many advantages of having a home server that have nothing to do with programming at all. For example, I use my home server for my backups. I have a script on all my other machines at home to rsync to the server when they shut down or reboot. Automatic backups without thinking about it. Great!

I also added a big RAID array to my server to store all my music and installed mpd (music player daemon) and icecast2 to play them randomly 24/7 and hooked the server line-out to the line-in of my stereo. I can listen to my music 24/7 anywhere in the world :-)


You make some compelling arguments :). When I get home from work tonight I think I'll set up that old laptop as a server.

Thanks for the advice, everyone!
Quote:Original post by Sander
Quote:Is there any real advantage to developing on a separate development server, besides simply not cluttering up your local machine?

Second, you can set weird configuration settings that you wouldn't want to make on your own machine.

I agree. And not only can you set it to a weird configuration, it also serves as an intermediate step between a live server and your own local machine. That's why I like to configure my development server to mimic the live environment as much as possible. This quickly points out not so obvious problems like differences in character encoding, user permissions, port settings etc. Having to figure that out once everything is already live is a nightmare, especially if downtime is an issue (like in the case of having to deal with 'real' clients).
Quote:Original post by WanMaster
That's why I like to configure my development server to mimic the live environment as much as possible. This quickly points out not so obvious problems like differences in character encoding, user permissions, port settings etc. Having to figure that out once everything is already live is a nightmare, especially if downtime is an issue (like in the case of having to deal with 'real' clients).


If you're worried about weird configuration issues, I'd suggest running a staging site on the same server as the live site, and test there.

Otherwise you're trusting you actually configured the dev server correctly to match the liver server. Mistakes there could cause very frustrating errors.

I guess my reason for avoiding a separate dev server is so I can focus on being a developer, not a network administrator. I make money writing code, not playing with hardware (as fun as that is). :)

This topic is closed to new replies.

Advertisement