in Web and Tech

LAMP setup on development server running Ubuntu Desktop 13.04

UPDATE (June 2020):
Ubuntu has certainly come a long way. Today I bid my Trusty Tahr (14.04)  install goodbye and said hello to Focal Fossa (20.04 LTS). Details on the process are here: http://infragrey.com/notes/archives/1022.

UPDATE (April 2014):
I’ve recently made a clean install of Ubuntu 14.04 LTS and have followed the same procedure detailed below for my AMP stack. Still works like a charm.


Never thought this could prove to be a breeze. Training (albeit much outdated, as that was back in the days of Fedora Core 4!) and experience has told me that installing the *AMP stack was pretty much faster on Windows because of the installer executables. Now the speed and ease of this one completely blew me away. It was practically faster and less complicated than setting up WAMP on my other machine. I would say I was done in less than half an hour.

The guide I followed was in here: http://www.howtoforge.com/ubuntu_lamp_for_newbies

Please note that I have made edits of my own on the instruction set so as to conform to the quirks of my own system.

Install Apache

To start off we will install Apache.

1. Open up the Terminal (Applications > Accessories > Terminal). The default hot key is “ctrl+t”

2. Copy/Paste the following line of code into Terminal and then press enter:

sudo apt-get install apache2

3. The Terminal will then ask you for you’re password, type it and then press enter.

Testing Apache

To make sure everything installed correctly we will now test Apache to ensure it is working properly.

1. Open up any web browser and then enter the following into the web address:

http://localhost/

You should see a folder entitled apache2-default/. Open it and you will see a message saying “It works!” , congrats to you! (Update: In my recent installation on 14.04, the apache2-default/ folder was no longer present. Instead, hitting http://localhost/ immediately displayed the default Apache “It works!” page.)

Install PHP

In this part we will install PHP 5.

Step 1. Again open up the Terminal (Applications > Accessories > Terminal).

Step 2. Copy/Paste the following line into Terminal and press enter:

sudo apt-get install php5 libapache2-mod-php5

Step 3. In order for PHP to work and be compatible with Apache we must restart it. Type the following code in Terminal to do this:

sudo /etc/init.d/apache2 restart

Test PHP

To ensure there are no issues with PHP let’s give it a quick test run.

Step 1. In the terminal copy/paste the following line:

sudo gedit /var/www/html/testphp.php

This will open up a file called phptest.php. The directory /var/www/html/ is the default root directory for Apache 2.

Step 2. Copy/Paste this line into the phptest file:

<?php phpinfo(); ?>

Step 3. Save and close the file.

Step 4. Now open you’re web browser and type the following into the web address:

http://localhost/testphp.php

Congrats you have now installed both Apache and PHP!

Install MySQL

To finish this guide up we will install MySQL. (Note – Out of Apache and PHP, MySQL is the most difficult to set up. I will provide some great resources for anyone having trouble at the end of this guide.)

Step 1. Once again open up the amazing Terminal and then copy/paste this line:

sudo apt-get install mysql-server

Step 2 (optional). In order for other computers on your network to view the server you have created, you must first edit the “Bind Address”. Begin by opening up Terminal to edit the my.cnf file. (Note: Myself, I skipped this part as I prefer to have MySQL bound only to my local machine)

gksudo gedit /etc/mysql/my.cnf

Change the line

bind-address = 127.0.0.1

And change the 127.0.0.1 to your IP address.

Step 3. This is where things may start to get tricky. Begin by typing the following into Terminal: (My note: The new MySQL package offered a sort of VGA GUI so i had no need to do this via the command line.)

mysql -u root

Following that copy/paste this line:

mysql> SET PASSWORD FOR ‘root’@’localhost’ = PASSWORD(‘yourpassword’);

(Make sure to change yourpassword to a password of your choice.)

Step 4. We are now going to install a program called phpMyAdmin which is an easy tool to edit your databases. Copy/paste the following line into Terminal:

sudo apt-get install libapache2-mod-auth-mysql php5-mysql phpmyadmin

(Update: Follow the onscreen instructions. A terminal-based GUI will come up. When prompted to configure phpmyadmin with dbconfig-common, click “Ok” and continue to follow onscreen instructions.)

After that is installed our next task is to get PHP to work with MySQL. To do this we will need to open a file entitled php.ini. To open it type the following:

gksudo gedit /etc/php5/apache2/php.ini

(Update: The gksudo command requires that gksu is actually installed. If gksu is not yet installed, proceed to install by typing “apt-get install gksu”)

Now we are going to have to uncomment the following line by taking out the semicolon (;). (Note: I did not find a commented out line similar to this, so I simply added this at the area of the .ini file that dealt with extensions.) (Note 2: On a more recent installation via apt-get for MySQL version 14.14 on Ubuntu 14.04, a conf files was created – /etc/php5/cli/conf.d/20-mysql.ini – so there is no need to uncomment or add the line below. I did, and it caused a notification error saying the MySQL module has already been loaded.)

Change this line:

;extension=mysql.so

To look like this:

extension=mysql.so

To get PHPMyAdmin to Run

1. To get PHPMyAdmin to work, copy its entire directory to /var/www like so:

sudo cp -R /usr/share/phpmyadmin /var/www

2. Open /etc/apache2/apache2.conf and add the following line

Include /etc/phpmyadmin/apache.conf

3. Now just restart Apache and you are all set!

sudo /etc/init.d/apache2 restart


Addendum:
The next hurdle would be placing your PHP files in the /var/www directory. Trouble is, this directory’s permissions are not automatically set to recognize your default user account. As such, you’ll have to gain access using sudo everytime. Doing so can be very annoying if you have to do this everytime.

A quick fix is to make the directory writable by its user group and then adding your default user account tot his group. This is done like so:

sudo groupadd www-data
sudo adduser < username > www-data
sudo chown -R www-data:www-data /var/www
sudo chmod -R g+rw /var/www

Reference: http://askubuntu.com/questions/19898/whats-the-simplest-way-to-edit-and-add-files-to-var-www

Additional information are also available here:
https://help.ubuntu.com/community/ApacheMySQLPHP

Write a Comment

Comment

Webmentions

  • Setting up my Dev Ubuntu box – The infraGrey Journal

    […] installing LAMP (please see other post on AMP installation in Ubuntu) I move on to setup other […]