Web Development on Ubuntu

If you want to build dynamic websites, one of the first things you’ll need to do is set up a development environment your local computer, so you can experiment and test new code without uploading everything to a remote web server. In a nutshell, this means LAMP — Linux, Apache, MySQL and PHP.

With this setup, you’ll be primed and ready to go to run popular content management software on your local box–like [Drupal](http://drupal.org/), [Joomla](http://www.joomla.org/) or [Silverstripe](http://www.silverstripe.com/); start a [Wordpress](http://wordpress.org/) or [Textpattern](http://www.textpattern.com/) blog; or even roll your own community site from scratch using a hot framework like [CakePHP](http://www.cakephp.org/).

(If you’re just getting started with web design, it’s a good idea to check out the tutorials at [w3schools.com](http://www.w3schools.com/), although you don’t have to know a single line of code to install a well-designed product like WordPress.)

This short tutorial assumes you’ve already installed some version of Ubuntu on your computer (–that takes care of the “Linux” part–), and leads you through installing an Apache web server, the PHP scripting language, and a MySQL database server.

(These instructions were tested on Kubuntu 7.10 “Gutsy.”)

**(1) Install everything.** Open a terminal and paste the following code, which will grab Apache, PHP, and MySQL all at once. That was easy.

sudo apt-get install apache2 php5-mysql libapache2-mod-php5 mysql-server

**(2) Test Apache.** Once installed, the Apache web server should be running. To find out for sure, open up a browser and enter `http://localhost/` in the URL field. You should see something like this:


If you click on the `apache2-default/` folder, you should see a message that says, “It works!” If instead of seeing the above, you get some sort of “Unable to connect” message, then the server is not running.

Try restarting Apache, then repeat step two:

sudo /etc/init.d/apache2 restart

**(3) Enable PHP.** Open a terminal and paste the following code, which will enable support for the PHP module in Apache’s configuration file:

sudo ln -s /etc/apache2/mods-available/php5.load /etc/apache2/mods-enabled/

Now, restart the Apache server (so the new module will take effect).

sudo /etc/init.d/apache2 restart

**(4) Learn PHP. Quick.** Create your first PHP script to test that the new module works. Open a terminal and paste the following code:

sudo nano /var/www/phpinfo.php

Whoa! What happened? Never used [nano](http://www.nano-editor.org/docs.php) before? It’s a simple terminal-based text editor. Check out the keyboard shortcut commands at the bottom of the screen. You’ll figure it out.

Here’s the code to paste into nano:


Don’t forget to save the file using Ctrl-O and then exit with Ctrl-X. Are we having *fun* yet?!

**(5) Test PHP.** Jump back over to the browser and reload the `localhost` page. You should see your new `phpinfo.php` file in there. Hey cool; we learned something: The Apache web root is located at `/var/www`, so any PHP files you save in there will be parsed by the server’s PHP engine.

Anyway, click on your new file. You should see some variant of this:


Great! We’re in.

**(6) Test MySQL.** This should already be installed and running, if step one went as planned. You should have already created a root username and password. If that’s the case, then just open a terminal and type:

mysql -u root -p

You’ll be prompted for the password you created earlier, and then you should see something like this:

Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 26
Server version: 5.0.45-Debian_1ubuntu3-log Debian etch distribution

Type 'help;' or 'h' for help. Type 'c' to clear the buffer.


Done! That’s it. You’re all set up. Check out the [MySQL Command Reference](/mysql-command-reference) for a few things to try in the monitor, if you like. Now you’re ready to start building your first dynamic website.

Fortunately, that’s another tutorial.


One response to “Web Development on Ubuntu

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s