2013-11-18

Installing LAMP Server(Apache,MySQL and PHP) in ubuntu


Pranaam to all Bhai ji _/\_
Today we will learn, how to setup LAMP Server(Linux Apache MySQL and PHP) in ubuntu based linux.
 so lets start....
we will install all mentioned packages using apt (apttitude) command .
apt command is syntax is

apt-get install package_name

here package name is the name of the package which we want to install .
ok lets start :)

first of all update your repository using apt-get update
if everything goes fine(didnt show any type of error, means repo links are working )
else need to update our repo link file
open /etc/apt/sources.list with nano text editor and paste these lines

deb http://archive.ubuntu.com/ubuntu/ precise main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu/ precise-security main restricted universe multiverse 
deb http://archive.ubuntu.com/ubuntu/ precise-updates main restricted universe multiverse

update repo links using command
apt-get update

Apache Web Server installation:-
apache web server is the server which process our http request forwarded on port number 80 via web browser :D
apache package name is apache2 for ubuntu
and command is
apt-get install apache2



system will ask you to confirm installation process by typing y and pressing enter
type y and press enter and apache server package installation will start.

starting apache server
service apache2 start
stopping apache server
service apache2 stop
Restarting apache server
service apache2 restart

MySQL Server installation:-
now we will install MySQL server using apt :)
MySQL server package name is mysql-server
command is 
apt-get install mysql-server



confirm installation process by typing y and press enter
during installation , system will ask info like password for mysql root user account. fill password and complete installation process :)

command for starting mysql server  is
service mysql start
stopping mysql server
service mysql stop
Restarting mysql sever
service mysql restart

PHP installation:-
php package name is php5 (for webserver) and we need php5-cli package for running such scripts  which we want to run via linux terminal (command line based php scripts)
command for installing php is
apt-get install php5
and for installing command line based php script support package is
apt-get install php5-cli




once installation completed , our lamp server is ready for use \ ^_^ /
if you are not good at command line based mysql interface, go for phpmyadmin 
phpmyadmin will let you add/edit/delete databases and sql query support via web interface >:D<
phpmyadmin package name in phpmyadmin
command is
apt-get install phpmyadmin



during installation, system will ask you some info like for which web server you want to setup phpmyadmin interface either for httpd(apache2) or lighthttpd
select apache or httpd, we are using apache server as web server
system will ask for mysql root account password that you used during mysql installation
then will ask for password that you wan t to setup for phpmyadmin root account
fill and proceed , phpmyadmin installation will be completed
once installation has been completed , we need to symlink phpmyadmin in our web server document root folder (folder which is accessible by web server ). by default web server document root in ubuntu is /var/www , you can change it by configuring apache server config file :P
so we need to symlink phpmyadmin application to our /var/www directory so that we can access phpmyadmin  web interface
location of phpmyadmin application is in /usr/share folder with name phpmyadmin
note:- check spelling of phpmyadmin application properly before symlinking it to /var/www


location of phpmyadmin will be under /usr/share
lets suppose path to phpmyadmin is  /user/share/phpmyadmin
symlink it to /var/www directory by using command

ln  -s  /usr/share/phpmyadmin    /var/www

this command will create shortcut in /var/www directory with name phpmyadmin
when you will brows http://127.0.0.1/phpmyadmin in your browser , you will be redirected to phpmyadmin web interface(dont forget to restart apache server ) , fill username and password and you will be able to perform tasks like add user/databases sql query support and other work via graphical user interface
if you want to setup you phpmyadmin interface with other name like i wan to access phpmyadmin with name
http://127.0.0.1/indishell
the i need to symlink phpmyadmin with name indishell under /var/www directory using command

ln  -s  /usr/share/phpmyadmin    /var/www/indishell

restart apache server and access 127.0.0.1/indishell in your browser ........... you will be redirected to phpmyadmin interface :D \m/

Note:- if you want that service should run automatically when you start your machine , use this command 
chkconfig   service_name   on
here service name is the name of the service which you want to start when your machine starts
for example i want to startup apache server during my system start
command will be 
chkconfig  apache2 on
if system shows , chkconfig command not found , install it using apt-get install  :P
command is
apt-get install chkconfig

Running your scripts on your newly installed localhost:-
if you want to run your scripts on your local server like php scripts , then you need to put them in web server document root folder(under /var/www folder)
for example i want to run a php script having name r.php, i am putting it in dir /var/www
now i can access r.php via web browser by typing URL  127.0.0.1/r.php
lets suppose we have a some files in a directory having name  ica in /var/www directory
i can access this directory by typing URL  127.0.0.1/ica
you may face problem in writing files under directory /var/www , for that either make directory /var/www writable for other user by using command

chmod  -R  1777 /var/www

 or change group of /var/www folder by using command

chgrp  -R  your_current_user    /var/www
chmod  -R  1775   /var/www

for example, i am using 'indishell' user account and want to use LAMP server through this user account
so i need to add indishell user as group of /var/www folder so that i can  write files to /var/www folder
command will be

chgrp  -R indishell  /var/www
chmod -R  1775   /var/www

this was short introduction about installing LAMP server in ubuntu based linux
if you have any kind of problem in setting up LAMP server in ubuntu , feel free to comment here :)

Thank you
Greetz To :-  
       <3   Zero cool, Team INDISHELL ,Mannu,Viki,Hardeep bhai and Ar Ar bhai ji <3

Share this post

1 comments

:) :-) :)) =)) :( :-( :(( :d :-d @-) :p :o :>) (o) [-( :-? (p) :-s (m) 8-) :-t :-b b-( :-# =p~ :-$ (b) (f) x-) (k) (h) (c) cheer

© 2009 Start With Linux | Mannu Linux
Designed by cyb3r.gladiat0r
Posts RSSComments RSS
Back to top