Install LAMP (PHP 7) on Ubuntu 16

Share this post to your friends !
  • 1
    Share

SystemMen - This article, I will guide you to install LAMP (PHP 7) on Ubuntu 16.x step by step. LAMP stack is a widely used software suite, serving millions of websites.

Server requirements

  • OS: Ubuntu 16.x, i use Ubuntu 16.04.4 LTS 64bit.
  • CPU: over 1 CPU or vCPU.
  • RAM: over 1 GB memory.
  • HDD: 5GB free space.
  • User: root
  • IP: setup static IP. For ex: 192.168.56.20.

Steps to Install LAMP on Ubuntu 16

Note that these installation steps need to be performed by the root user. If you are not root user, you need to add sudo before each command.

Install Apache2

1. First, we will update the operating system, this ensures all packages are the latest.

apt-get update && apt-get upgrade -y

Next, you type below command to install Apache2.

apt-get install apache2 -y

Once Apache is installed, open the /etc/apache2/mods-available/mpm_prefork.conf file and edit the parameters as below (refer to Linode), these parameters are optimized for 2 GB memory server.

install-lamp-php-7-on-ubuntu-16-01 Install LAMP (PHP 7) on Ubuntu 16
Optimized prefork module for 2 GB memory server.
<IfModule mpm_prefork_module>
    StartServers              4
    MinSpareServers           20
    MaxSpareServers           40
    MaxRequestWorkers         200
    MaxConnectionsPerChild    4500
</IfModule>

By default, the event module is enabled. It should be disabled and at the same time you should enable the prefork module. Type the commands below:

a2dismod mpm_event
a2enmod mpm_prefork

And restart Apache.

systemctl restart apache2

Install MariaDB

Many people are still using MySQL 5.x but I prefer to use MariaDB, which is a better performance version of MySQL.

In the Ubuntu 16 available repository, MariaDB is ready, you do not need to add any external repositories. To install MariaDB, type below command.

apt-get install mariadb-server mariadb-client -y

During the installation of MariaDB, it may ask you for MariaDB’s root password.

Once the installation is complete, you can run the command below, answering some of the questions given for initial security for MariaDB.

mysql_secure_installation

Install PHP 7

Another great thing about Ubuntu 16 is that PHP 7 is available in the repository. For other Linux OS, you will probably have to use unofficial repositories.

Type below command to install PHP 7 for LAMP stack.

apt-get install php7.0 php7.0-fpm php7.0-gd php7.0-mysql -y

You will need to enable the proxy module and fpm so that PHP can work better with Apache.

a2enmod proxy_fcgi setenvif
a2enconf php7.0-fpm

And restart apache to apply the newly enabled module.

systemctl restart apache2

Check LAMP informations

And now, you can run the following command to create the PHP information page of the LAMP stack. You can then visit that site to see if LAMP is working.

echo "<?php phpinfo(); ?>" > /var/www/html/info.php
install-lamp-php-7-on-ubuntu-16-02 Install LAMP (PHP 7) on Ubuntu 16
Web page to check PHP informations.

Now you can start the process of creating a database, configuring virtualhost and adding your website source to the server.

If you liked this article, then please subscribe to our YouTube Channel for more video tutorials. You can also find us on Twitter and Facebook.


Share this post to your friends !
  • 1
    Share
If you appreciate what we share in this blog, you can support us by:
  1. Stay connected to: Facebook | Twitter | Google Plus | YouTube
  2. Subscribe email to recieve new posts from us: Sign up now.
  3. Start your own blog with SSD VPS - Free Let's Encrypt SSL ($2.5/month).
  4. Become a Supporter - Make a contribution via PayPal.
  5. Support us by purchasing Ribbon Lite Child theme being using on this website.

We are thankful for your support.

«« »»

Got something to say? Join the discussion

Please keep in mind that all comments are subject to our Comment Policy. Your email address will not be published.
This site uses Akismet to reduce spam. Learn how your comment data is processed.