Install Apache, MariaDB and PHP7 (LAMP Stack) on Ubuntu 14.04 LTS
LAMP (Linux, Apache, MariaDB/MySQL, PHP) is the most common solution stack for dynamic websites. In this tutorial, we are going to look at how to install Apache, MariaDB and PHP7 (LAMP stack) on Ubuntu 14.04 LTS Trutsy Tahr.
Step 1: Update Ubuntu 14.04 LTS
Before we install any software, it’s always a good idea to update software repository and upgrade software packages. So first ssh into your Ubuntu 14.04 server and enter the below commands.
sudo apt-get update sudo apt-get upgrade sudo apt-get dist-upgrade
Step 2: Install Apache Web Server
Apache is the most popular web server. Enter this command to install Apache Web server and Apache utilities.
sudo apt-get install apache2 apache2-utils
After it’s installed, Apache should be automatically started. Check out its status with:
sudo service apache2 status
* apache2 is running
It will also enable the default site
000-default. If Apache is not running, then manually start it with:
sudo service apache2 start
If we check its version, we can see Apache 2.4.7 is installed.
Server version: Apache/2.4.7 (Ubuntu) Server built: May 4 2016 17:05:10
Now in your browser’s address bar, type the public IP address of Ubuntu 16.04 LTS server. You should see the “It works!” Web page which means Apache Web server is running correctly.
You can use the curl command line tool to fetch the public IP address of Ubuntu 16.04 server.
sudo apt-get install curl curl http://icanhazip.com
If you are installing Apache on your local Ubuntu 14.04 box, just type
localhost in the browser address bar.
Finally, we need to make
www-data (Apache user) as the owner of document root so Apache can write to this directory.
sudo chown www-data /var/www/html/ -R
Step 3: Install MariaDB
MariaDB is a drop-in replacement for MySQL. It is developed by former members of MySQL team who concerned that Oracle might turn MySQL into a closed-source product. Many Linux distributions and companies have migrated to MariaDB. So we’re going to install MariaDB instead of MySQL.
sudo apt-get install mariadb-server mariadb-client
During the installation process, you will be asked to set a password for the MariaDB root user. Note that this is not the root user of Ubuntu 14.04 system.
Enter the password again.
After it’s installed, MariaDB server should be automatically stared. Check its status with:
sudo service mysql status
* /usr/bin/mysqladmin Ver 9.0 Distrib 5.5.49-MariaDB, for debian-linux-gnu on x86_64 Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others. Server version 5.5.49-MariaDB-1ubuntu0.14.04.1 Protocol version 10 Connection Localhost via UNIX socket UNIX socket /var/run/mysqld/mysqld.sock Uptime: 3 min 20 sec Threads: 1 Questions: 582 Slow queries: 0 Opens: 183 Flush tables: 4 Open tables: 24 Queries per second avg: 2.910
The uptime indicates that MariaDB server is running. If for some reason it’s not running, start it with:
sudo service mysql start
Now run the post installation security script.
It will ask you to enter the MariaDB root user password. If you set a password during installation, then enter the password. You can also choose to change the password. If you didn’t set the password, then just press Enter and set a new one.
Next you can just press Enter to answer all the remaining questions. This will remove anonymous user, disable remote root login and remove test database. This step is a basic requirement for MariaDB database security.
Step 4: Install PHP7
Ubuntu 14.04 software repository has not yet included the latest PHP7. However, you can install it from a PPA (Personal Package Archive) which belongs to a PHP7 debian package maintainer. Add the PPA with the following commands:
sudo apt-get install python-software-properties software-properties-common sudo add-apt-repository ppa:ondrej/php sudo apt-get update
Then install PHP7 and some common PHP7 extensions.
sudo apt-get install php7.0-fpm php7.0-mysql php7.0-common php7.0-mbstring php7.0-gd php7.0-json php7.0-cli php7.0-curl libapache2-mod-php7.0
During installation, the Apache
mpm_event module will be disabled and the
mpm_prefork will be enabled. This is because PHP uses the prefork module by default.
In the command above we also installed the Apache php7.0 module (libapache2-mod-php7.0) and by default it will enable this module.
If you like to install all available PHP7 extensions, use this command:
sudo apt-get install php7.0-*
Step 5: Test PHP
To test PHP with Apache server, first create a
test.php file in the document root directory.
sudo nano /var/www/html/test.php
Paste the following PHP code into the file.
<?php phpinfo(); ?>
Save and close the file. Now in the browser address bar, enter
sever-ip-address with your actual IP. You should see your server’s PHP information. This means PHP processing is fine. You can find that Zend OPcache is enabled.
For your server’s security, you should delete
test.php file now.
Congrats! You have successfully installed Apache, MariaDB and PHP7 on Ubuntu 14.04 LTS Trusty Tahr.