Tech stuff and info dump

Ubuntu 10.04 (Lucid Lynx): simple, step-by-step lamp server installation (linux, apache, mysql, php)

May 13th, 2010

Well, today’s the day for installing a lamp server on my 10.04 machine! Wireless is working just well enough that I’ve not given up and gone running back to 9.04, although there are still some mysteries to figure out where that’s concerned.

It’s worth noting that I’m setting up my server for personal use. I want something that will let me test out webpages that will hosted by other people’s servers. (If you’re setting up an internet-facing server, these instructions will get you started, but more work is needed to keep the server safe from the wild world of the internet. If I come across a good tutorial on such things, I’ll post it.)

Downloading Necessary Packages

Synaptic Package Manager can be opened by going here:

System -> Administration -> Synaptic Package Manager

and entering one’s password.

I used Synaptic Package Manager to download the following packages:

  • php5 (this installs apache2-mpm-prefork, etc.)
  • mysql-server-5.1 (this installs the client and core as well)
  • Optional: phpMyAdmin (a nice GUI for managing MySQL tables)
  • Optional: php5-cli (only needed if you want to run PHP from the command line)

The packages can be found by clicking the Search icon and typing in the package names. When a package name is selected, Synaptic Package Manager kindly prompts one to install all other files required. Once you have chosen all the packages needed, click ‘Apply’ (underneath the green check mark) at the top of the Synaptic Package Manager window.

File Installation

For the most part, Synaptic Package Manager will take care of all the installation. There are a couple things that might need to be done manually, however.

Configuring phpMyAdmin

If you have chosen to install phpMyAdmin, you may get a pop-up window called ‘Configuring phpmyadmin’ with the text “Web server to reconfigure automatically:” and a choice of servers. This is just asking which server you want to be able to run phpMyAdmin. I was given the choice of apache2 and lighttpd. I ticked apache2 and clicked the ‘Forward’ button.

Configuring MySQL

The mysql installation also requires some information. A pop-up window called ‘Configuring mysql-server-5.’ should pop up with the text ‘New password for the MySQL “root” user:’ and a text box.

Make up a password for the root user and enter it into this box. (Write it down – you’ll need it later!) Click ‘Forward’. You’ll be asked to re-enter the password. Do so, and click ‘Forward’ again.

Database for phpMyAdmin

If you’ve chosen to install phpMyAdmin, you’ll get another ‘Configuring phpmyadmin’ pop-up with the text ‘Configure database for phpmyadmin with dbconfig-common?’ and a tickbox. I left this ticked; clicking ‘Help’ explains under what circumstances one wouldn’t want this to happen. Once the selection is made, click ‘Forward’ to continue.

If the box was ticked, you are then prompted for “Password of the database’s administrative user:” and given another text box. Use the MySQL root password that you just made up.

After this, the installation should complete itself without any more human help.

Restarting the Apache server

Before anything can be done, the Apache server will need to be restarted.

Open a terminal (Applications -> Accessories -> Terminal) and, at the command line, type:

sudo apache2ctl restart

The first time I did this, I received this warning:

apache2: Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1 for ServerName

This went away when I did this:

Letting Apache know about localhost

Open a terminal (Applications -> Accessories -> Terminal) and, at the command line, type:

sudo gedit /etc/apache2/apache2.conf

The sudo command gives you root-like powers (needed here to edit this particular file), gedit opens the notepad-like application, and /etc/apache2/apache2.conf is the name of the file being edited.

(If prompted for a password, use the password that is used to log in to Ubuntu.)

This should open a notepad-like window with a lot of stuff.

I added

ServerName localhost

as a separate line at the end of the file and saved the document (File -> Save in gedit).

After saving, restart Apache again by typing

sudo apache2ctl restart

at the command line.

Testing to make sure PHP works

Open a terminal window by going to

Applications -> Accessories -> Terminal

Type this (pressing enter when finished) at the command line:

cd /var/www/

This takes you to the /var/www folder. Then type:

sudo gedit

and press enter. You’ll be prompted for your system password (the one used to log in to Ubuntu). (The ‘gedit’ opens a notepad application; the ‘sudo’ is necessary because if gives you root-like powers which are needed to save a file in the /var/www folder.)

In the notepad application that should have popped up, type the following:

# test.php
<?
phpinfo();
?>

Then go to File -> Save As and enter test.php as the name of the file.

Open a browser (like, say, Firefox at Applications -> Internet -> Firefox Web Browser) and type

http://localhost/test.php

and you should get a page come up with all sorts of useful and interesting information about your Apache server! It works!

(If you get a page that just says “# test.php” then Apache doesn’t know about localhost. Try editing /etc/apache2/apache2.conf and restarting the Apache server as described above.)

Setting up phpMyAdmin

If you’ve opted for phpMyAdmin, there is one quick little thing to do to make it work.

Open a terminal window (Applications -> Accessories -> Terminal) and type:

sudo gedit /etc/apache2/apache2.conf

at the command line prompt. If prompted for a password, use the password for logging in to Ubuntu.

Add this line to the file that has been opened in the notepad-like window:

Include /etc/phpmyadmin/apache.conf

Make sure this is on a line of its own. Save the file (File -> Save), close the gedit window and restart Apache by typing:

sudo apache2ctl restart

at the command line prompt.

Check to make sure phpMyAdmin works

Open your favourite web browser (say, Firefox) and navigate to:

http://localhost/phpmyadmin/

This should bring up a login screen. You can log in to phpMyAdmin by using ‘root’ as the username and the mysql root password set during installation.

The mysql root password can be changed in phpMyAdmin by going to the privilege page and clicking the pencil icon next to each root account. Enter a password in appropriate field of the newly-loaded page.

Once logged in, you can use phpMyAdmin to manage your MySQL databases.

Where Important Things Are

Here’s where to find useful stuff.

The Apache configuration file is located at:

/etc/apache2/apache2.conf

The default web folder is here:

/var/www

Apache error logs are here:

h1

If anything goes horribly wrong, reading these can often be very helpful. (Even if what’s written in the file makes no sense, it’s often quite easy to pop the error message or warning into Google. Very often, there’s someone talking about the problem using real words in the first page of hits.)

Apache access logs live here:

/var/log/apache2/access.log

NB: Both etc and var can be found two levels ‘up’ from the home folder.


Filed under: apache,lamp server,mysql,php,Ubuntu 10.04
May 13th, 2010 12:54:28