Pages

Saturday, 1 December 2012

Setup apache, PHP, MySQL, phpMyAdmin on ubuntu

Today i will show you how to setup apache, PHP, MySQL and phpMyAdmin on ubuntu

 

Express Install

sudo apt-get install apache2 php5 mysql-client mysql-server php5-mysql

Then restart the apache server
sudo /etc/init.d/apache2 restart or sudo service apache2 start

You are done!! If you want to do it step by step do this:

Setup apache

 

Type this in terminal
$ sudo apt-get install apache2

If you find any problem at any stage try restarting the apache server like this
$ sudo /etc/init.d/apache2 restart

Setup PHP

Type this in terminal
$ sudo apt-get install php5

Your htdocs are present in /var/www/ you have to be root to change/create files by default. To fix this
$ sudo -i
# cd /var/
# umask 0000
# chmod +rwx -R www
# chown <your username> www
# chgrp <your username> www
# exit

Note: You may have to do this sometimes in the future also

Now edit /var/www/index.php and add anything in php
Open browser and type localhost as url and check whether it works

Update
Many people asked me how to see the error log of PHP. To see use this command:

tail -f /var/log/apache2/error.log


Setup MySQL

Type this in terminal
$ sudo apt-get install mysql-client mysql-server

Note: You will be asked to enter password for your database. Enter a password and don't forget it as it is pretty important

Connect PHP and MySQL

In order for PHP to access MySQL do this
$ sudo apt-get install php5-mysql

Setup phpMyAdmin

Download phpMyAdmin from here.
Now extract contents and move phpMyAdmin to /var/www/

Open /var/www/config.sample.inc.php and change following lines

 
/* FIND THESE LINES AND CHANGE THEM IN YOUR CONFIG FILE*/
 
/* Authentication type */
 
$cfg['Servers'][$i]['auth_type'] = 'cookie';
 
/* Server parameters */
 
$cfg['Servers'][$i]['host'] = 'localhost';
 
$cfg['Servers'][$i]['connect_type'] = 'tcp';
 
$cfg['Servers'][$i]['compress'] = false;
 
/* Select mysql if your server does not have mysqli */
 
$cfg['Servers'][$i]['extension'] = 'mysqli';
 
$cfg['Servers'][$i]['AllowNoPassword'] = false;

Now open localhost/phpMyAdmin on your browser


2 comments:

  1. eh. easiest way to install lamp stack in linux:

    sudo apt-get install tasksel
    sudo tasksel

    Use it!

    ReplyDelete
  2. True. But this blog post provides more clarity and control over Apache,MySQL,PHP needed for advanced web developers.

    ReplyDelete