How to Install LAMP with Apache, PHP 7 and MariaDB 10 on Ubuntu 16.04 Server

Channel: Ubuntu Linux
Abstract: $ sudo apt install php7.0[TAB]use apt command to install the proper components so that PHP can execute code in conjunction with apache web server. $ s

LAMP stack is an acronym which stands for the Linux operating system alongside with Apache web server, MySQL/MariaDB database and dynamic PHP programming language which facilitates the deployment of dynamic web applications.

Install Apache, PHP-7 and MariaDB 10 on Ubuntu-16.04

In this guide we will discuss how to install LAMP stack on Ubuntu 16.04 Server with new released of PHP 7 version and MariaDB 10 version.

Requirements
  1. Ubuntu 16.04 Server Installation Guide
Step 1: Install Apache on Ubuntu 16.04

1. On the first step will start by installing one of the most popular web servers today in internet, Apache. Install Apache binary package in Ubuntu from their official repositories by typing the following commands on console:

$ sudo apt install apache2
OR
$ sudo apt-get install apache2
Install Apache on Ubuntu 16.04

2. Once Apache web server has been installed on your system, verify if the daemon is started and on what ports it binds (by default it listens on port 80) by issuing the below commands:

$ sudo systemctl status apache2.service 
$ sudo netstat –tlpn
Start Apache Service Verify Apache Port

3. You can also verify if apache service is running by typing your server IP address in a web browser using HTTP protocol. A default web page should be displayed on the browser similar to the following screenshot:

http://your_server_IP_address
Apache Default Page

4. Because accessing web pages using HTTP protocol is highly insecure, further will start enabling Apache SSL module by issuing the following commands:

$ sudo a2enmod ssl 
$ sudo a2ensite default-ssl.conf 
$ sudo systemctl restart apache2.service
Enable Apache SSL Module

Confirm if the server is properly binding on default HTTPS port 443 by running netstat command again.

# sudo netstat -tlpn

5. Also, verify the default informational apache web page using HTTP Secure Protocol by typing the below address in your browser:

https://your_server_IP_address

Due to the fact that apache is configured to run with a Self-Signed Certificate, an error should be displayed on your browser. Just accept the certificate to bypass the error and the page should be securely displayed.

Apache SSL Certificate Confirmation Apache Running on HTTPS Step 2: Install PHP 7 on Ubuntu 16.04

6. PHP is an Open Source dynamic programming language which can connect and interact with databases to process you code embedded in HTML code in order to create dynamic web pages.

To install the latest version of PHP 7, which is designed to run with speed improvements on your machine, first start by performing a search of existing PHP modules by issuing the below commands:

$ sudo apt search php7.0
Search PHP 7 Modules

7. Next, once you found the proper PHP 7 modules required for your setup, use apt command to install the proper components so that PHP can execute code in conjunction with apache web server.

$ sudo apt install php7.0 libapache2-mod-php7.0
Install PHP 7 in Ubuntu 16.04

8. Once the PHP7 packages are installed and configured on your server, issue php -v command in order get the current release version.

$ php -v
Check PHP Version

9. To further tests PHP7 configuration on your machine, create a info.php file in apache webroot directory, located in /var/www/html/ directory.

$ sudo nano /var/www/html/info.php

add the below lines of code to info.php file.

<?php 
phpinfo();
?>

Restart apache service to apply changes.

$ sudo systemctl restart apache2

And navigate to your server IP address at the below URL to check the final result.

https://your_server_IP_address/info.php 
Check PHP 7 Information

10. If you need to install extra PHP modules on your server, just press [TAB] key after php7.0 string when using apt command and the bash autocomplete option will automatically list all available modules for you.

Choose the proper module and install it as usual. We strongly advise you to install the following Php additional modules:

$ php7.0-mbstring php7.0-mcrypt php7.0-xmlrpc
$ sudo apt install php7.0[TAB]
Install Additional PHP 7 Modules Pages: 1 2

Ref From: tecmint

Related articles