LAMP* is pretty much the basis for much of the open source web applications today. Why? Oh, the usual reasons: it's free, it's well-documented, it's got thousands of users and developers, and it's got hundreds of applications to its name. I cover most of the background stuff in another post, LAMP for Small Business.
So how do you get a LAMP environment set up in Ubuntu?
These are the packages you need:
apache2
php5
php5-mysql
mysql-server-5.0
Installing these packages will pull in a few other components from the repository, coming out to about 100MB.
To install everything as a single line command:
sudo apt-get install apache2 php5 php5-mysql mysql-server-5.0
And with that, you now have a local LAMP environment installed on your system.
Once it's installed, where do you place your web pages? Well, there are two locations, depending on what you want to do and how you want to interact with your web server: in the web server's designated virtual root directory, and in a local virtual directory.
Your web server's virtual root directory, accessible via
http://localhost/
translates to the file system directory, /var/www
. The problem with this directory is that it's owned by root and writable only by root. Having to type sudo
everytime you change anything in the directory can be a pain.**A better option, in my opinion, is to use the local virtual directory. This is the subdirectory
public_html
which you create in your home directory. The contents of this directory translate to http://localhost/~username
. Since you own this directory, you can pretty much do what you want in it.As a test to see whether the Apache-PHP combination works, create a file called, say,
test.php
in /home/username/public_html
with the following contents:<? phpinfo(); ?>
Point your web browser to
http://localhost/~username/test.php
. You should get a dump of your PHP's settings.To test your MySQL installation, run the following in a command line:
sudo mysql
This will bring up the MySQL command line interpreter. Below is a sample interaction:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7 to server version: 5.0.24a-Debian_9ubuntu0.1-log
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
+--------------------+
2 rows in set (0.00 sec)
* Since it's actually PHP, Ubuntu, MySQL, and Apache, can we also call it PUMA? Just kidding. (Can't blame a guy for trying to start a trend.)
** You can also change ownership or permissions on the
/var/www
directory. The exercise is left up to the reader.