Tutorial:
Toward the end of pursuing various personal projects I decided to set up a LAMP server on my second machine here at home, but wanted to maintain the desktop aspects of what I currently have with Ubuntu desktop so I decided to run the LAMP setup on a clean Ubuntu desktop. I’m aware that I could have went the server route with the LAMP configuration, and then installed the desktop on top of it with:
$ sudo apt-get install ubuntu-desktop
but I decided for now to run similar setups on both machines. So below are my notes for installing the LAMP server on Ubuntu desktop (these notes are as much for my later use as they are for anyone who trips over them whilst running through the interwebs). Overall, its fairly straightforward, and there really aren’t that many steps involved. The community has made this pretty painless IMO. These notes assume that Ubuntu desktop is already installed. An excellent walkthrough for this process can be found here, and mostly what’s below are my adjustments to that excellent walkthrough.
1. Install the LAMP server package using tasksel.
$ sudo tasksel install lamp-server
This tasksel package will install apache2, php5, and mysql5, along with various dependencies and libraries.
2. Set your mysql password when prompted in the terminal. You’ll need it later.
3. Visit http://localhost. If Apache is up in your browser, you’ll see a directory listing.
4. Make sure PHP is up and parsing by placing a test index.php file in the /var/www/ directory. You’ll need sudo for this as it requires root privileges to edit files in this directory. You can do this with any text editor. I chose gedit.
$ gksudo gedit /var/www/index.php
Once open, enter this PHP line and save:
<? echo 'hello there'; ?>
5. Now refresh your browser. If your test page greets you heartily, PHP is up and parsing.
6. On the other hand, if firefox prompts you to download the file cuz it doesn’t know what to do with “PHTML”, make sure the php5 service is enabled with:
$ sudo a2enmod php5
7. If the message returned indicates php5 is already enabled, try just restarting the service:
$ sudo /etc/init.d/apache2 restart
Thats what it took for me. My guess is the alteration of a previously installed service by the subsequent installation of the other items in the same lamp-server package.
8. If you then get the error, “Restarting web server apache2. apache2: Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1 for ServerName” like I did, you’ll need to edit the httpd.conf file:
$ gksudo gedit /etc/apache2/httpd.conf
Add this line and save:
ServerName localhost
9. Once that’s done, refresh your browser again. If you’re like me, the test page performed as intended. So you now know that Apache and PHP are running, but what about MySQL?
10. Try logging in via the terminal and enter that password you created earlier when prompted. If you can login, then MySQL is running:
$ mysql -u root -p
11. If you prefer a web-based interface for your MySQL needs, phpMyAdmin is an excellent way to go. Its not installed with the other packages via the tasksel lamp-server command, but as usual, installing the application is as easy as command line:
$ sudo apt-get install phpmyadmin
you’ll be prompted to allow phpMyAdmin to automatically configure various instances of Apache for PHP use. If you’re following this walkthrough, you’ll want to select the apache2 web service.
12. once the installation is complete, go log in using your mysql login information at http://localhost/phpmyadmin.
13. But if you’re new at this like I am, you may want to verify that PHP can connect to your MySQL instance before you sit down and start writing code, so open up the same index.php file from earlier, add and save this code:
<?php
$hostname = 'localhost';
$username = 'root';
$password = 'yourMySQLpassword';
$conn = mysql_connect($hostname,$username,$password) or die ('could not connect to mysql.');
echo 'OK';
?>
14. Now refresh your browser. If you see the OK, then PHP has no problem connecting to your MySQL.
So hopefully you’re now up and running with your own LAMP server on Ubuntu desktop 7.10. If you’re not up and running, the best place I’ve found for help with anything Ubuntu related is http://ubuntuforums.org/.Good luck.











November 29th, 2007 at 1:46 am
[…] tylermcmanus.com We gotta go to the crappy town where I’m the hero! « Tutorial: LAMP Server On Ubuntu 7.10 Desktop […]
January 29th, 2008 at 2:39 pm
Thank you for this excellent tutorial! It is a clear and concise model to follow. Again, thanks.
January 29th, 2008 at 6:20 pm
@jim: You’re welcome. Thanks for leaving the feedback.