You should develop in a Virtual Machine
Many of us develop on Macintoshes. There are many reasons for this, but one of them is that it's based on a Unix platform of some sort. This allows us to run common server software such as Apache, Ruby, Python and Nodejs on our Macs.
Our computers become powerful develoment machines similar to the servers our apps will eventually live on.
Sometime we start our computer only to find Apache won't start, or MySQL can't create a PID file, or we've updated to Mountain Lion and Apache needs to be reconfigured. Death!
Using a Virtual Machine gives us the full power of a Linux server, and the full ability to completely fuck that server up without repercussion
.
This is an easy-to-follow guide on setting up a Linux server, getting a LAMP server setup, and sharing files. This will enable you to:
This assumes some knowledge of Linux and Apache. If you're a total beginner, some things might not make sense. Use google, or ask me.
My personal favorite is Ubuntu, and that is what this will teach you about. Ubuntu favors a lot of convention over configuration, making getting up and running very easy.
12.04 LTS
is what I use as of this writing.Hint: Download it via an official torrent, it's much quicker. Choose ubuntu-12.04-server-amd64.iso.torrent if you're on a MacBook Pro or iMac.
Hint: Install OpenSSH if you want to SSH into your virtual machine from another machine on your network. I always install this. I SSH in from Terminal instead of use the VMWare interface because I like how Terminal lets me scroll and copy and paste.
$ sudo apt-get install openssh-server
We'll be using SMB to connect to and share files with our Ubuntu server. VMware sets up its own file sharing if you let it, but it can be problematic. Log into your server and get ready to run some commands (Minus the comments after the # below)
$ sudo apt-get update #Update the package manager we'll use to install stuff
$ sudo apt-get install -y samba #Install samba, so we can use SMB
$ sudo apt-get install libpam-smbpass #Allow login via your Ubuntu user
Find your IP address by viewing the output of this command:
$ ifconfig
You can create a static IP address so you always know this, but its not strictly necessary.
You'll use this in step 4.
$ sudo nano /etc/samba/smb.conf
Once you're editing smb.conf:
[webshare]
comment = Ubuntu Web Files Share
path = /var/www
browsable = yes
guest ok = no
read only = no
create mask = 0755
Save your file and exit (ctrl+x, y, enter)
Set up /var/www for sharing:
$ sudo mkdir /var/www
$ sudo chown your_user:your_user /var/www #Change 'your_user' to whatever your Ubuntu username is. Be sure you keep the colon in place and use your username twice
$ sudo restart smbd
$ sudo restart nmbd
$ exit #IMPORTANT: log out, then relog back in!
Head back out to your Macintosh. In Finder, go to the Go menu, and choose Connect to Server
(or use cmd+k).
Connect to: smb://192.168.1.102
- Replace that with whatever your IP address is from step 2.
If everything is OK, you'll be prompted to enter your credentials. Use the username and password that you use to log into Ubuntu. If that connects, you'll find your sharing files from /var/www in Ubuntu with your macintosh. You can edit those files there as you would any other folder or file. If you followed this from the beginning, this is probably empty right now.
$ sudo tasksel install lamp-server #Oh, hey, you're done.
This installs a working LAMP stack.
/var/www
(Look familiar? That folder is shared with your Mac)./etc/apache2
./etc/apache2/sites-available
and symlinked to /etc/apache2/sites-enabled
to be enabled. Or use this. Or read this and see how a2ensite
and a2enmod
works.$ sudo a2enmod rewrite
$ sudo service apache2 reload
You can now point your web browser to your IP address and see the It Works! page.
Try these:
$ sudo apt-get install -y git-core
$ sudo apt-get install -y git-flow
$ sudo apt-get install -y php5-gd
$ sudo apt-get install -y php5-curl