Step by Step Guide for Setting up LAMP

For a basic complete web server implementation, various components needs to be installed namely – Apache, PHP and MySQL

Step 1: Installing Apache

Installing apache in various Linux distribution is same as installing any other package. You need to use apt-get command.

sudo apt-get install apache2

Step 2: Installing MySQL

Similar to installing Apache, following command will install MySQL

sudo apt-get install mysql-server

Securing MySQL is a priority. In order to do this with a password, use this command

sudo mysql_secure_installation

Executing this command will prompt for a password. This password would be required in order to access any database so be sure to use a strong and secure one.

In order to be able to execute any SQL commands such as creating databases, tables or adding any form of data, you need to be in SQL prompt. Thus, start MySQL server and then login as root providing the password entered during secure installation.

systemctl start mysql

sudo /usr/bin/mysql -u root -p

You should have mysql> as your prompt meaning that you are now able to execute any sql queries. Use exit; to return back to original linux path;

Step 3: Installing PHP

You would need several packages to install fully functional PHP. Install packages depending upon your requirement.

sudo apt-get install php-pear php-fpm php-dev php-zip php-mysql php-xmlrpc php-xml libapache2-mod-php

Once you are done installing, you should restart apache. To confirm if PHP has been installed or not, you can simply use a well known PHP function echo as shown below from linux terminal.

sudo service apache2 restart

php -r ‘echo “PHP should be working if this text is printed.\n”;’

That is all required for proper functioning of a web server. You can check by accessing ‘localhost’ in your machine. Try adding and accessing some PHP files in /var/www/html/ directory to ensure its working properly.

Note: Follow this link to check for any additional packages that may be required for PHP