Install LAMP stack on Elementary OS

Unlike most other Linux distributions Elementary OS doesn’t come preinstalled with a LAMP stack. In this tutorial I will show you from start to finish. If you are interested in a certain part of the LAMP stack we have separate tutorials for you to read on those here, here and here.

First up is to get Apache installed, we can do this with the following command:

sudo apt-get install apache2

 

This will now install Apache and start your Apache server. How easy was that? Now open up a browser of your choice (the default being Midori on Elementary OS) and navigate to http://localhost and you should see the Apache holding page. Brilliant its working!

Now lets make the www folder writable so we can create new files and folders for our web projects. Type the following:

sudo chmod 577 /var/www

 

This makes the /var/www folder readable and writable for the current user (your user account which you are logged into Elementary OS with). More about this later.

Next up lets install MySQL server and MySQL client. Run the following command in the terminal:

sudo apt-get install mysql-server mysql-client

 

During the install you will be prompted to set-up a password for the root account. This is highly recommended during a live environment but not vital during development. I would enter a password to get into the habit.

Lets test to see if our database server is up and running. in the terminal type:

mysql -u root -p

 

The first part (mysql) lets the system know we would like to use mysql. The second part (-u root) lets mysql know we want to login using the root account. The third part is optional (-p), only add this if you set-up a password in the previous step, this simply tells mysql to promopt you for your password. If all has gone well you should see the MySQL command prompt. Just double check we are good to go type the following into the MySQL prompt:

SHOW DATABASES;

 

This should return a list of the current databases running. Great lets exit the MySQL command prompt and install PHP. Type exit to leave the MySQL prompt.
Installing PHP is just as easy, type the following into the terminal:

sudo apt-get install php5 libapache2-mod-php5

 

Now its time to make sure Apache, PHP and MySQL all play nicely together. Install the following by typing this into the terminal:

sudo apt-get install php5-mysql php5-curl php5-gd php5-intl php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl

 

Thats it you know have MySQL, Apache and PHP installed. All thats left is to restart Apache to ensure everything is working correctly. Type in the following:

sudo /etc/init.d/apache2 restart

 

Lets create a test file to makes sure our PHP install is working correctly.

nano /var/www/test.php

 

Now type the following into the file:

php phpinfo();

 

Save the file (Ctrl and X) now open your browser and navigate to:

http://localhost/test.php

 

If you see the PHP info page well done! Your Apache and PHP are set-up and ready to go.

Optional

You may wish to install PHPMyAdmin to make using your MySQL database easier. You can install PHPMyAdmin with the following command:

sudo apt-get install phpmyadmin

 

You will be prompted to select your web server type, we installed Apache before so we will select that (you can select your webserver using the spacebar).
It will then inform you it will need a database select yes and then enter your root password as we set-up earlier.
It will then ask you for a password for PHPMyAdmin simply enter whatever you like here (do not leave blank!).

Now go to:

http://localhost/phpmyadmin

 

You can now login with the username of root and the password you have just entered in the above step.

Leave a Reply

Your email address will not be published. Required fields are marked *