Install Lamp in Linux Machine (Ubuntu, Fedora, Etc)

Learn To Install LAMP (Linux Apache Mysql PHP)in Linux Machine using Command line , Command in terminal, or in remote Server using Putty etc. And Run PHP Code in Linux Machine.

Open Your terminal first:



Step1: For Ubuntu 11.10 and above go to dash home
Type Terminal.






(if you dont have this version (dashhome))
Open up the Terminal by (Applications > Accessories > Terminal).



ScreenShot 2


Step2:





Run This Command First



$ sudo apt-get update



It will ask you for Password (root/Administrator) password
Once you enter it will start updating.



Step3:



No we Begin with Installing Apache by running following command:



$ sudo apt-get install apache2


(While Installation It might Prompt you for y/n you can type 'y' and press enter)



Once it Finishes Installation You can check it by
Running the following URI in your Browser (Mozilla Firefox/Chrome)




http://localhost/


You will see



It works!

This is the default web page for this server.

The web server software is running but no content has been added, yet.






Step 4:



We will start with installation of PHP Now:

By simply Copy/Pasting the following command into Terminal & press enter:



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



(While Installation It might Prompt you for y/n you can type 'y' and press enter)



Step 5. After Installation we need to Restart Apache:



$ sudo /etc/init.d/apache2 restart



Step 6 : Test PHP(Optional)



To check if php has installed and running smoothly in system.

1) . In the terminal copy/paste the following line:



sudo gedit /var/www/testphp.php



This command will open up a file called phptest.php.



2). Copy/Paste this line into the phptest file:







3). Save and close the file.



4). Now open you're web browser and type the following into the web address:



http://localhost/testphp.php



The page should look like this:







Congrats you have sucessfully installed both Apache and PHP!



Step 7 : Install Mysql



Copy/paste the following line in Terminal:



$ sudo apt-get install mysql-server



(While Installation It might Prompt you for y/n you can type 'y' and press enter)



It will ask you enter root user Password ''







And will ask you to repeat and confirm password.







Step 8. We are now going to install an application called phpMyAdmin which is the most common tool to edit databases.
Copy/paste the following line into Terminal:


$ sudo apt-get install libapache2-mod-auth-mysql php5-mysql phpmyadmin



It will ask for web configuration of phpmyadmin with Apache
you select 'Apache' by pressing space and press Enter.






Then Configure PHPMyadmin with Mysql Select 'Yes' and Press Enter







Then Password for Mysql Admin task Password







Finally Password for PhpMyadmin







Confirm Password for PhpMyadmin



On completion to get PHP to work with MySQL. To get it working we need to open a file named php.ini. To open it type the following:



$ gksudo gedit /etc/php5/apache2/php.ini



Un-comment the following line by taking out the semicolon (;).



Change this line:



;extension=mysql.so



To :



extension=mysql.so



Also
add the following line in etc/apahe2/apache2.conf





Include /etc/phpmyadmin/apache.conf

Now Restart Apache and Installation is over! :)



sudo /etc/init.d/apache2 restart




Now open you're web browser and type the following into the web address:



http://localhost/phpmyadmin (Enter Phpmyadmin password user id will be 'root')





Related Posts

Install XAMPP (Run PHP Code in your Windows Mac)

Introduction to PHP and (Difference between HTML & PHP)

PHP Interview Questions

If You Think This Post has helped you buy us a Coffee :)

Make Donation

  • Other: $

Donate now