Thursday, July 4, 2013

Install Apache MySQL PHP (LAMP stack) in ubuntu

LAMP stack is a group of Apache, MySQL, PHP for Linux.

To install LAMP stack you will need to have root privileges.
To get root privileges

sudo su

OR use sudo before every command

First we are updating apt-get databases

sudo apt-get update

Now we are installing apache 2 package

sudo apt-get install apache2

Apache is installed now. Try to access your website using localhost or server IP address.

To get the server IP

ifconfig eth0 | grep inet | awk '{ print $2 }'

Now we can proceed to install PHP 5

sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt

It may ask you some question, choose yes and continue

You can install other PHP externsions/modules which you need.
To see a list of PHP modules

apt-cache search php5-

It will show you a list of php5 moudules

Then you can install php5 modules as follow

sudo apt-get install name_of_the_module name_of_the_module_2 ....

You can install multiple modules by separating the name of each module with space

Now It's time to install MySQL

sudo apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql

You will be asked to give a mysql root password. You can also set mysql root password later.

Once MySQL has been installed, we should activate it with this command

sudo mysql_install_db

Now Finish up it by running MySQL set up script

sudo /usr/bin/mysql_secure_installation

You will be asked to enter current mysql root password.
Then the prompt will ask you if you want to change the root password.
Choose N if you dont want to change current password and proceed to next step.
Complete all the steps and now you are done.

Start MySQL and Apache

sudo service mysql start
sudo service apache2 start

If its already started, restart them

sudo service mysql restart
sudo service apache2 restart

No comments:

Post a Comment