How to Install LAMP on LINUX Mint or Ubuntu

This blog has two parts: first, how to install LAMP in Mint or Ubuntu, and second one about start working in PHP:

 

 

 

I. Installing LAMP (Linux, Appache, MySql, and PHP) in ubuntu or mint

(A) Installing Apache

1. Open up the Terminal:
On desktop, right-click the mouse and select ‘Open in Terminal’

2. Copy and Paste (Ctrl + V may not work; on cursor, right click mouse and click paste) the following line of code into Terminal and then press Enter:

sudo apt-get install apache2

3. The Terminal will then ask you for your password,
Type your a password of your choice (carefully enter) and then press Enter. Then, system will show the files that will be deleted, new files that will be installed, required memory etc. And, then the system will ask:

Do you want to continue: Y/N: Type Y and Enter

Testing Apache

Test Apache to ensure that it is correctly installed:
Open a web browser, then Copy and Paste the following into the web address and press Enter:

http://localhost/

You will see the following message:

It works!
This is the default web page for this server.
The web server software is running but no content has been added, yet

Congrats! You have successfully installed Apache

(B) Installing PHP

1. Open up the Terminal, if it is not already open

2. Copy and Paste the following line of code into the Terminal and press Enter:

sudo apt-get install php5 libapache2-mod-php5

As mentioned above, after the process, Terminal will ask:

Do you want to continue: Y a/N: Type Y and Enter

3. Now, the system needs restarting. Copy and Paste the following code into the Terminal, and then press Enter:

sudo /etc/init.d/apache2 restart

Testing PHP

We need to test PHP to ensure that everything is installed properly

1. Copy and paste the following code into the Terminal, and press Enter:

sudo gedit /var/www/testphp.php

Now, a file named phptest.php. will open up

2. Copy and Paste the following code into the phptest.php file:

<?php phpinfo(); ?>

3. Save and Close the phptest.php file.

4. Open any web browser, then Copy and Paste the following into the web address, and press Enter:

http://localhost/testphp.php

Now, few pages will be displayed showing details of PHP programs installed into your system

Congrats! You have successfully installed PHP

(C) Installing MySQL

1. Open up Terminal (if it is NOT open) and then Copy and Paste the following code and press Enter:

sudo apt-get install mysql-server

After processing, the system will ask you to enter a password:

Carefully Type your password and then press Enter

Again, after completing the process, the system will ask:

Do you want to continue: Y/N: Type Y and Enter

Again, after processing, the system will ask:
Do you want password for MySql:

Carefully Type your password and press Enter

Again, the system will ask: Repeat password:

Carefully Type your password again and then press Enter

2. Copy and Paste the following line into the Terminal, and press Enter

mysql -u root

Then, Copy and and Paste the following line (Do NOT press Enter NOW)

mysql> SET PASSWORD FOR ‘root’@'localhost’ = PASSWORD(‘yourpassword’);
(Ensure to change yourpassword to the password of your choice) and then press Enter

Congrats! You have successfully installed MySQL

(D) Installing phpMyAdmin

1. Open up the terminal (if it is NOT open), then Copy and Paste the following code and then press Enter

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

2. After processing, the system will ask,

Do you want to continue: Y/N: Type Y and press Enter

3. Now, after processing, the system will ask:

Please choose the server: Highlight apache2 and then press Enter (OK)

4. Now, after processing, the system will come up with 2-3 small paragraphs with a question at the end:

Configure database for phpadmin with dbconfig-comon: Highlight Yes and press Enter (OK)
5. After processing, the system will ask:

MySql Application password for phpadmin: Type your password and press Enter

6. Now, the system will ask:

Password for database administrative user: Type your password and press Enter

7. Now, the system will ask:

Password Confirmation: Type your password again and press Enter

8. Now, you can see what is working and status of each of the item by opening up php.ini file. Copy and Paste the following code into the Terminal and press Enter:

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

You may read the file and close it.

9. Now, we need to restart Apache once again. Copy and Paste the following code and then press Enter

sudo /etc/init.d/apache2 restart

Congrats! You have successfully installed phpMyAdmin

 

II. How to Start Working in PHP Files:

Please keep all the files in the following directory:

Computer/File System/var/www/

(A) Open, Work, and Save files in PHP:

1. On the desktop, double-click ‘Computer‘, double-click ‘File System‘, double-click ‘var‘, then highlight ‘www‘ folder, then right-click your mouse, select ‘Open as Administrator‘, then enter your password in the pop up window and press Enter (OK).
Now, you can see the www folder open in red background color.

2. Inside the red-background, right-click your mouse, then select ‘Create Document‘, and select ‘Empty File‘. A new file will be opened. Give the new file a name of your choice with extension .php (example hello.php)

3. Open the the new file named hello.php and write your first php program, may be as  follows:

<?php
echo ‘Hello World!’;
?>

Save the file

4. Open any browser, then Copy and Paste the following into the web address, and press Enter

http://localhost/hello.php

You can see the result of your first PHP program:

Hello World!

(B) Editing Existing PHP Files:

1. As mentioned above (Point 1. under (A) Open, Work, and Save files in PHP), open the ‘www‘ directory, highlight the existing php file (for example hello.php) you want to edit, right-click your mouse, then select ‘Open as Administrator‘ (Type and Enter Password, if required), open the file, edit, and save.

2. Then, you can go to the browser, type the file name (in the above example hello.php ) in the browser address, as follows, and press Enter

http://localhost/hello.php

You can see that the edited file is working

Congrats! Now, you are all set to go for mastering php programming.