Sign in to follow this  
Samith

[web] development environment

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 :-)

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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). :)

Share this post


Link to post
Share on other sites
Last web project I worked on (using servlets) we kept the code in SVN but I had to manually write out and email database patches. Obviously this does not scale. At all. But if you're the only developer, just keep everything on a local machine. I kept everything on the desktop (less hassle with NetBeans+Glassfish) but with NFS (or Samba if your IDE is on a Windows box), you can treat remote directories like local ones, so even if your IDE does not speak SSH, you can still set it up to work on a directory on your test server.

Share this post


Link to post
Share on other sites
Quote:
Original post by cbotman
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.

Man, 'staging', I was looking for that word. :)

I do that too, but I find that it quickly becomes a mess when I have staging and live webs located on the same server, even when some of these sites aren't even running. Especially if you have a lot of small applications on a single machine. In case of the opposite, one site load balanced over multiple servers, it's even more complicated.

Of course, if you only have one or two servers available to you, there's not much you can do, but if there are dozens I like to reserve some of them exclusively for staging environments. I guess it's just how you prefer to organize things personally or within a company.

It do find it useful a new update is almost ready to be released: adding another web and then quickly changing the host headers or the pointing the configuration to the new directory.

Share this post


Link to post
Share on other sites
Quote:
I guess my reason for avoiding a separate dev server is so I can focus on being a developer, not a network administrator.


Any web developer worth his salt should know the basics about systems and network administration. If you don't know that, how can you design sites that scale? That deal well with congestion or peaks? How do you debug problems on your live website? See it as a challenge. Having your own home network and server to muck around with is a great way of honing those skills :-)

For example, at my home I did some heavy network and RAID benchmarking. The automated backups that my home computers make to the server on shutdown can easily be a couple of Gig, even with rsync. So I did some benchmarking and hardware upgrades (better RAID configuration and upgraded everything to Cat6 and gigabit) and now the backups are running at peak performance. It was fun to do :-)

Share this post


Link to post
Share on other sites
I agree completely, you should know the basics of system and network administration.

But talk to any network administrator and they'll revoke your privileges if you describe their job as basic, so be warned. :P

Having a simple development environment helps avoid overhead (time to set up new sites, etc) and distractions (such as having to patch and update additional machines).

You can do performance testing on your local machine or staging, and as for debugging live, again, that's the beauty of a live staging site.

Share this post


Link to post
Share on other sites
I run a virtual machine on my desktop PC that's configured basically the same as my production server. My local working copy of my project is stored directly on that VM. I set up Samba file sharing, mapped my VM's web root to a Windows drive letter, and work directly on the files on the VM using a text editor.

When deployment time comes, I rsync the files directly from my development VM to the production server (OK, it's a little more complicated, but not much).

This lets me avoid any possible problems with developing on Windows and deploying on Linux (like case-sensitivity of MySQL table names, or behavior of some system-level PHP functions, or system prerequisites like Ghostscript).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this