How To Install Linux, Apache, MySQL, PHP (LAMP)


Setting up Apache Web Server

Install Apache

First thing first install Apache2 using the following command :

sudo apt-get install apache2
?
Testing Apache

You can test if the installation successfully by visiting http://locahost/ from the machine itself or the local ip of the machine.

Changing The Default Web Page

You can nano -> /var/www/html/index.html to change the default page using the following code :

nano /var/www/html/index.html

Once you are done Ctrl+X and Enter to save your work.

Install PHP

Install the PHP and Apache packages with the following command:

sudo apt-get install php5 libapache2-mod-php5 -y
Test PHP

You can test if the PHP installation went correctly by creating a PHP file and visit it using the following :

cd /var/www/html/

sudo rm index.html

nano ./index.php
?

Once it is open paste this code :

<?php echo "Hello World"; ?>

Save your work using Ctrl+x hit Enter. Write the following code :

sudo service apache2 restart

Then from the machine itself navigate to http://localhost/index.php OR use the machine local IP instead of localhost. If you can see the message Hello World then PHP is running correctly.

Install MySQL

Install the MySQL Server and PHP-MySQL using the following command :

sudo apt-get install mysql-server php5-mysql -y

When installing MySQL you will be asked for a root password. You’ll need to remember this to allow your website to access the database.

Now restart Apache:

sudo service apache2 restart

And that that is it for today, Now you a fully functioning LAMP server that you can access internally.