Install and Setup Apache2, Php5, Mysql on Ubuntu Server (LAMP)

July 2, 2013 — 5 Comments

Want to build a website? Then you need to setup a web server! Here I’ll show you how to install and setup LAMP pack on Ubuntu 12.04 LTS Server.

LAMP is a combination of Linux (OS), Apache HTTP Server, PHP (open-source scripting language), and MySQL (database software).

In this tutorial I use the hostname www.example.com with the IP address 192.168.0.100 as example.

1.) Login or Remote access your server as root, or run command to get root privileges.

sudo su

2.) Install Mysql 5:

apt-get install mysql-server mysql-client

You’ll be asked to set a password for root user of Mysql.

3.) Install Apache2:

apt-get install apache2

After installed, test if it works by going to http://192.168.0.100 in your web browser. Remember change the IP to yours.

apache-wellcome-page

The default default document root is /var/www/, and the configuration file is /etc/apache2/apache2.conf.

4.) Install PHP5:

apt-get install php5 libapache2-mod-php5

Restart Apache2 service to get it works with PHP5:

/etc/init.d/apache2 restart

5.) To test if PHP5 works, create info.php in the root directory “/var/www/”:

vi /var/www/info.php

press I to insert following codes:

<?php
phpinfo();
?>

then press Esc -> Shif+: type in wq and hit enter to save. Then in browser go to http://192.168.0.100:info.php

Phpinfo

6.) To get Mysql support in PHP5, install following packages:

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

Then restart Apache2 service:

/etc/init.d/apache2 restart

Go to or reload http://192.168.0.100/info.php in your browser:

Mysql-support-in-php5

7.) (Optional) Install phpMyAdmin, a web interface to manage Mysql Databases:

apt-get install phpmyadmin

After installed, go to http://192.168.0.100/phpmyadmin/, login with root and password you set in step 2.

I'm a freelance blogger who started using Ubuntu 5+ years ago and wishes to share my experiences and some useful tips with Ubuntu beginners and lovers. Please notify me if you find any typo/grammar/language mistakes. English is not my native language. Contact me on Google Plus or email to ubuntuhandbook1@gmail.com

5 responses to Install and Setup Apache2, Php5, Mysql on Ubuntu Server (LAMP)

  1. Leonardo S. Mardini October 17, 2013 at 8:56 pm

    Cool Man ;)

  2. good but you php 5.3 which will not be supported anymore, very soon!

  3. You should place the info.php file in /var/www/html in the new lamp distribution.

Trackbacks and Pingbacks:

  1. How to Install WordPress on Ubuntu 13.04 Server | UbuntuHandbook - August 9, 2013

    [...] installed LAMP or LEMP (Nginx with PHP, Mysql) on your Ubuntu Server? This time I’m going to show you how to [...]

Leave a Reply

*

Text formatting is available via select HTML.

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>