In this article, Let me explain how you can setup a LAMP server with default configuration in Ubuntu 18.04.1 / Ubuntu 18.10. Majority of the websites in the internet are running on LAMP stack which is a combination of Linux Apache MySQL and PHP. LAMP servers are very popular and it is easy to setup.
Before we begin, let’s update package repo lists of Ubuntu 18.04.1 / Ubuntu 18.10 to the latest by running apt-get update
sudo apt-get update
This video is for Ubuntu 16.04, but same commands are used for Ubuntu 18.04.1 / Ubuntu 18.10(Except PHP installation command).
Please LIKE , COMMENT and SUBSCRIBE .
Step1. Install Apache for LAMP in Ubuntu 18.04.1 / 18.10:
Here is a little background of Apache . Apache is an open-source HTTP server for modern operating systems which is written C. The Apache HTTP Server (“httpd”) was launched in 1995 and it has been the most popular web server on the Internet since April 1996. Apache 2.4 is the latest stable version of Apache. If anybody still using Apache 2.2, it is time to upgrade it as Apache has discontinued all development and patch review of the 2.2.x series of releases.
Let’s install Apache 2.4 :
sudo apt-get install apache2
Give Y to the prompt for confirmation and wait for 2mins.
When It is done, make sure Apache is ‘running’ by executing command.
sudo systemctl status apache2
If Apache is in running state, you would see the Apache default page in the browser when searched with server IP address (http://your-server-ipaddress )
Let’s enable Apache in the boot so that apache start automatically when the system is rebooted
sudo systemctl enable apache2
So you got the apache running fine our Ubuntu 18.04.1 / Ubuntu 18.10, let’s setup php.
Step2. Install PHP for LAMP in Ubuntu 18.04.1 / 18.10:
Let’s install PHP7.2 along with few PHP modules and a module which is required to integrate PHP with Apache.
sudo apt-get install php7.2 php7.2-mysql libapache2-mod-php7.2 php7.2-cli php7.2-cgi php7.2-gd php7.2-curl php7.2-mbstring php7.2-xml php7.2-xmlrpc
Give Y to the prompt for confirmation and wait for 2 mins
When it is done, go to /var/www/html (This is the default document root where you store all your website content in order to serve via your website) and create a file info.php with content given below.
<?php phpinfo(); ?>
Now go to http://your_server_ip_address/info.php on the browser and you will see the PHP info page as shown below.
This means that your website is now serving PHP code. If you are a PHP developer, you can put your code here and check it in the browser.
Let’s tell Apache to look for index.php first by making following changes. open /etc/apache2/mods-enabled/dir.conf . Current content should be looking this.
<IfModule mod_dir.c> DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm </IfModule>
Change it to as below
<IfModule mod_dir.c> DirectoryIndex index.php index.html index.cgi index.pl index.php index.xhtml index.htm </IfModule>
And then reload Apache.
sudo systemctl reload apache2
Now we have PHP installed in our Ubuntu 18.04.1 / Ubuntu 18.10. Let’s install MySQL.
Step3. Install MySQL for LAMP in Ubuntu 18.04.1 / 18.10:
A database is required when you are building a robust and data driven website. Let’s install MySQL 5.7 which can be used as a database for your website.
sudo apt-get install mysql-server
Give Y when prompted and also give root password for the database server when asked during installation.
When it is completed, check the status of the MySQL by running following command.
sudo systemctl status mysql
You should see something like this:
Let’s enable MySQL in the boot so that MySQL start automatically when the system is rebooted.
sudo systemctl enable mysql
That’s it. you have LAMP server up and running in your Ubuntu 18.04.1 / Ubuntu 18.10.. Now you can start developing your PHP website or you setup web applications like WordPress, Joomla, Magento. WordPress installation on a LAMP server is explained here >>
Let me come back with other useful articles soon. Subscribe to this blog so that you don’t miss out anything useful (Checkout Right Sidebar for the Subscription Form) . Please also put your thought on this article as a comment .