There is a new revision of this tutorial available for Ubuntu 15.04 (Vivid Vervet).

Installing Apache2 With PHP5 And MySQL Support On Ubuntu 14.04LTS (LAMP)

LAMP is short for Linux, Apache, MySQL, PHP. This tutorial shows how you can install an Apache2 webserver on anUbuntu 13.04 server with PHP5 support (mod_php) and MySQL support.

I do not issue any guarantee that this will work for you!

 

1 Preliminary Note

In this tutorial I use the hostname server1.example.com with the IP address 192.168.0.100. These settings might differ for you, so you have to replace them where appropriate.

I'm running all the steps in this tutorial with root privileges, so make sure you're logged in as root:

sudo su

 

2 Installing MySQL 5

First we install MySQL 5 like this:

apt-get install mysql-server mysql-client

You will be asked to provide a password for the MySQL root user - this password is valid for the user root@localhost as well as [email protected], so we don't have to specify a MySQL root password manually later on:

New password for the MySQL "root" user: <-- yourrootsqlpassword
Repeat password for the MySQL "root" user: <-- yourrootsqlpassword

 

3 Installing Apache2

Apache2 is installed by default in ubuntu14.04, If not installed then install it. Apache2 is available as an Ubuntu package, therefore we can install it like this:

apt-get install apache2

Now direct your browser to http://192.168.0.100, and you should see the Apache2 placeholder page (It works!):

Apache's default document root is /var/www/html on Ubuntu, and the configuration file is /etc/apache2/apache2.conf. The configuration system is fully documented in /usr/share/doc/apache2/README.Debian.gz

 

4 Installing PHP5

We can install PHP5 and the Apache PHP5 module as follows:

apt-get install php5 libapache2-mod-php5

We must restart Apache afterwards:

service apache2 restart

5 Testing PHP5 / Getting Details About Your PHP5 Installation

The document root of the default web site is /var/www/html. We will now create a small PHP file (info.php) in that directory and call it in a browser. The file will display lots of useful details about our PHP installation, such as the installed PHP version.

vi /var/www/html/info.php

<?php
phpinfo();
?>

Now we call that file in a browser (e.g. http://192.168.0.100/info.php):

As you see, PHP5 is working, and it's working through the Apache 2.0 Handler, as shown in the Server API line. If you scroll further down, you will see all modules that arealready enabled in PHP5. MySQL is not listed there which means we don't have MySQL support in PHP5 yet.

 

6 Getting MySQL Support In PHP5

To get MySQL support in PHP, we can install the php5-mysql package. It's a good idea to install some other PHP5 modules as well asyou might need them for your applications. You can search for available PHP5 modules like this:

apt-cache search php5

Pick the ones you need and install them like this:

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

Now restart Apache2:

service apache2 restart

Xcache is a free and open PHP opcode cacher for caching and optimizing PHP intermediate code. It's similar to other PHP opcode cachers, such as eAccelerator and APC. It is strongly recommended to have one of these installed to speed up your PHP page.

Xcache can be installed as follows:

apt-get install php5-xcache

Now restart Apache:

service apache2 restart

Now reload http://192.168.0.100/info.php in your browser and scroll down to the modules section again. You should now find lots of new modules there, including the MySQL module:

7 phpMyAdmin

phpMyAdmin is a web interface through which you can manage your MySQL databases. It's a good idea to install it:

apt-get install phpmyadmin

You will see the following questions:

Web server to reconfigure automatically: <-- apache2
Configure database for phpmyadmin with dbconfig-common? <-- No

Afterwards, you can access phpMyAdmin under http://192.168.0.100/phpmyadmin/:

 

Share this page:

12 Comment(s)

Add comment

Comments

From:

I am not able to see mysql in phpinfo() though I can see .ini file loaded. can someone guide me. I checked some of the blogs and did steps mentioned here as well. no luck :(

From: Anonymous

"Now direct your browser to http://192.168.0.100, and you should see the Apache2 placeholder page (It works!): "

no it doesn't work

you have to use http://127.0.1.1/

i have just standard instalation of ubu 14

From: Anonymous

hi there. i follow all steps to install (step 7). but i get this error: phpMyAdmin - Error The json extension is missing. Please check your PHP configuration.

i try to install and install again phpMyAdmin.

i try to edit json.ini

now i dont know what i can i do to make that this work? thanks alot

 

 

 

From: Rahul Sharma

great tutorial. Thanks for sharing :-) If any one get page not found for phpmyadmin please follow this thread it will help:

http://askubuntu.com/questions/387062/how-to-solve-the-phpmyadmin-not-found-issue-after-upgrading-php-and-apache

From: Irshad Khan

run this camand if phpmyadmin is not working : sudo ln -s /usr/share/phpmyadmin /var/www/html/phpmyadmin

From: Mark Rhyne

Followed this Tut. But found it not working.

Had to add an A record type to my zone records to my domain.

server1      A    TTL 3600  IP ??.??.??.??

Did following in postfix config:

# See /usr/share/postfix/main.cf.dist for a commented, more complete version# Debian specific:  Specifying a file name will cause the first# line of that file to be used as the name.  The Debian default# is /etc/mailname.#myorigin = /etc/mailnamesmtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)biff = no# appending .domain is the MUA's job.append_dot_mydomain = no# Uncomment the next line to generate "delayed mail" warnings#delay_warning_time = 4hreadme_directory = /usr/share/doc/postfix# TLS parameterssmtpd_tls_cert_file = /etc/postfix/smtpd.certsmtpd_tls_key_file = /etc/postfix/smtpd.keysmtpd_use_tls = yessmtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scachesmtp_tls_session_cache_database = btree:${data_directory}/smtp_scache# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for# information on enabling SSL in the smtp client.# smtpd_relay_restrictions = myhostname = server1.example.comalias_maps = hash:/etc/aliasesalias_database = hash:/etc/aliasesmyorigin = /etc/mailnamemydestination = server1.example.com.au, localhost, localhost.localdomain# mynetworks = 127.0.0.0/32mailbox_size_limit = 0recipient_delimiter = +inet_protocols = allhtml_directory = /usr/share/doc/postfix/htmlvirtual_alias_domains = virtual_alias_maps = proxy:mysql:/etc/postfix/mysql-virtual_forwardings.cf, mysql:/etc/postfix/mysql-virtual_email2email.cfvirtual_mailbox_domains = proxy:mysql:/etc/postfix/mysql-virtual_domains.cfvirtual_mailbox_maps = proxy:mysql:/etc/postfix/mysql-virtual_mailboxes.cfvirtual_mailbox_base = /home/vmailvirtual_uid_maps = static:5000virtual_gid_maps = static:5000smtpd_sasl_auth_enable = yesbroken_sasl_auth_clients = yessmtpd_sasl_authenticated_header = yessmtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destinationtransport_maps = proxy:mysql:/etc/postfix/mysql-virtual_transports.cfvirtual_maildir_extended = yesvirtual_mailbox_limit_maps = proxy:mysql:/etc/postfix/mysql-virtual_mailbox_limit_maps.cfvirtual_mailbox_limit_override = yesvirtual_maildir_limit_message = "The user you are trying to reach is over quota."virtual_overquota_bounce = yesproxy_read_maps = $local_recipient_maps $mydestination $virtual_alias_maps $virtual_alias_domains $virtual_mailbox_maps $virtual_mailbox_domains $relay_recipient_maps $relay_domains $canonical_maps $sender_canonical_maps $recipient_canonical_maps $relocated_maps $transport_maps $mynetworks $virtual_mailbox_limit_mapscontent_filter = amavis:[127.0.0.1]:10024receive_override_options = no_address_mappingsinet_interfaces = all

 

May need to setup a reverse DNS with my ISP to send to some providers like gmail, google etc.

From: ruwan

Thanks.. works well...

From: Kelvin Kariuki

Thank you, awesome tutorial.

From: Andri

192.168.0.100/phpmyadmin/ was not found on this server.

 

How I can to fix it

From: chgogos

See there

https://help.ubuntu.com/community/ApacheMySQLPHP#Troubleshooting_Phpmyadmin_.26_mysql-workbench

From: Imre

Great tutorial. Thanks!

From: Ahyan

vi /var/www/html/info.php doesn't work for me. I used sudo nano /var/www/html/info.php