LAMP is an acronym for Linux, Apache2, MySQL and PHP. However, LAMP can also be Linux, Apache2, MariaDB and PHP. This brief tutorial is going to show students and new users the steps to install these packages on Ubuntu 16.10.
At the time of this writing PHP 7 was also the default version in Ubuntu 16.10 repositories.
MariaDB is going to replace MySQL in the LAMP stack in this post. Our next tutorial will also show students how to replace Apache2 with Nginx in the lAMP stack as well.
Step 1: Linux
This post assumes you already have Ubuntu Linux 16.10 installed and you have root access. You need to be a root user or have rights to install packages in Ubuntu to be successful here.
Update Ubuntu server before installing the packages below.
sudo apt-get update
Step 2: Apache2
The next component of the stack is Apache2. To install Apache2 on Ubuntu 16.10, run the command below
sudo apt-get install apache2
After successfully installing Apache2, run the commands below to stop, start and enable apache2 server to always startup everytime your computer starts.
sudo systemctl stop apache2.service
sudo systemctl start apache2.service
sudo systemctl enable apache2.service
To verify if Apache2 is working, browse to the server hostname or IP address and you should see Apache2’s default index page for Ubuntu.
Apache2 default configurations also come with SSL/TLS but the module isn’t enabled. You won’t be able to access the default page over port 443 until you enable the SSL module.
To do that, run the commands below
sudo a2enmod ssl
Also enable the default SSL configuration for the site
sudo a2ensite default-ssl.conf
Restart Apache2 server and you should be able to access the default page via SSL over port 443
Step 3: MariaDB
The next component of the stack is MariaDB. To install MariaDB on Ubuntu 16.10, run the commands below
sudo apt-get install mariadb-server mariadb-client
After installing MariaDB server, run the commands below to stop, start and enable MariaDB server to always start up when your computer starts.
sudo systemctl stop mysql.service
sudo systemctl start mysql.service
sudo systemctl enable mysql.service
Next, run the command below to secure MariaDB server using the security script provided
You’ll be prompted to answer series of questions.. follow the guide below to answer them.
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
Set root password? [Y/n] y
New password: type_new_password
Re-enter new password: confirm_new_password
Password updated successfully!
Reloading privilege tables..
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
Remove anonymous users? [Y/n] y
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] y
By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y
- Dropping test database...
ERROR 1008 (HY000) at line 1: Can't drop database 'test'; database doesn't exist
... Failed! Not critical, keep moving...
- Removing privileges on test database...
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
After that MariaDB should be functioning ok. To MariaDB, run the commands below to logon.
mysql -u root -p
Step 4: PHP 7
The final component of the stack is PHP. PHP 7 comes default in Ubuntu 16.10. To install PHP and other important PHP modules, run the commands below.
sudo apt-get install php7.0 php7.0-mysql php7.0-xml php7.0-gd libapache2-mod-php7.0 php7.0-xmlrpc php7.0-xsl php7.0-mbstring php7.0-tidy
That will get PHP and modules that are required by many PHP based applications.
To test PHP installation, create a test php file in apache2 root directory called info.php with the lines below
sudo nano /var/www/html/info.php
sudo systemctl reload apache2.service
Access PHP test by browsing to the URL below.
That’s it! This is how one installs the LAMP stack with MariaDB and PHP 7 on Ubuntu 16.10.