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.
<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
Now you can start the process of creating a database, configuring virtualhost and adding your website source to the server.
«« How to install PHP 7 in Debian 8How to change the hostname in CentOS 6 »»