Install LAMP (PHP 7) on Ubuntu 16

by Daniel Pham
Published: Updated:

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.

You Might Be Interested In
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
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
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.

(This is an article from my old blog that has been inactive for a long time, I don’t want to throw it away so I will keep it and hope it helps someone).

0 0 votes
Article Rating

You may also like

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

DevOps Lite is a personal blog specializing in technology with main topics about DevOps, DevSecOps, SRE and System Administrator. Articles are shared for free and contributed to the community.

SUPPORT US

FOLLOW US

Subscribe my Newsletter for new blog posts. Stay updated from your inbox!

© 2021-2024 DevOpsLite.com – All rights reserved.

Please write sources “DevOpsLite.com” when using articles from this website.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More

2
0
Would love your thoughts, please comment.x
()
x

Adblock Detected

Please support us by disabling your AdBlocker extension from your browsers for our website.