We did one post for LAMP for CentOS7/RHEL7 machines. For this post we are going to use Ubuntu 17.10 machine for implementing Apache, MySQL and PHP code to enable operating system to host website and web apps. In this concept we have Linux machine to run Apache process which host PHP code website which could display and store data in MySQL database. So in this post we will see How To Install Linux, Apache, MySQL, PHP (LAMP) stack on Ubuntu 17.10


For this setup, we are using Ubuntu 17.10 latest as of now in Dec 2017

root@srvu:~# lsb_release -d
Description:	Ubuntu 17.10

root@srvu:~# uname  -r

As we have already install Ubuntu 17.10 machine, I hope readers know how to install Ubuntu 17.10.

Apache Installation

Apache web server is most popular web server world wide used and well documented. Also default web server for most of Unix/Linux machine. In Ubuntu machine, Apache server could install with apt-get command like mentioned below.

# apt-get update
# apt-get install apache2

After installation of Apache, you can verify it with below command.

# dpkg -l apache2

After installation of Apache packages on Ubuntu Machine, we need to configure and test Apache web page before we go further for MySQL and PHP.
So for Apache configuration, first we should know and check its default configuration with below mentioned commands.

# apache2ctl configtest
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using Set the 'ServerName' directive globally to suppress this message
Syntax OK

As mentioned above configuration Syntax is OK, but server can’t determine FQDN, it also shows that proper settings of ServerName directive could suppress this message.
But we could also make it possible without having any editing in Apache configuration file.

With above message it is quit clear that it matter of FQDN resolution, either we should proper DNS resolution for this machine or we have properly configured /etc/hosts file like below,

root@srvu:~# grep srvu /etc/hosts	srvu.geekpills.com srvu

root@srvu:~# apache2ctl configtest
Syntax OK

So we have properly configured /etc/hosts file which corrected Apache configtest messages. Now we need to start Apache service on machine.

# systemctl start apache2

We can browse Ubuntu Apache page on browser, like show below.









Now we know Apache is Installed and running properly. Configuration of Apache is depend upon your requirement and platform, packages used in support of Apache.

Installation of MySQL

We are in second phase of this post, where we will see how to install MySQL on ubuntu 17.10 machine and initial configuration.
In Ubuntu 17.10 both MySQL and Mariadb packages available for MySQL database.
I recommended to use Mariadb instead of MySQL (This is only because most of Linux distributions default MySQL database packages is Mariadb). So in below way we can install Mariadb packages in ubuntu17.10

# apt-get install mariadb-server

After installation as mentioned above command, we could see installation of below packages on machines.

# dpkg -l | grep mariadb| awk '{print $2}'

Once installation is complete, we should perform some mandatory security features like below.

# mysql_secure_installation 


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: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!

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
production environment.

Remove anonymous users? [Y/n] y
 ... Success!

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
 ... Success!

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...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

Once installation is completed, we could access MySQL prompt through client like mentioned below.

# mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 10.1.25-MariaDB-1 Ubuntu 17.10

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases;
| Database           |
| information_schema |
| mysql              |
| performance_schema |
3 rows in set (0.00 sec)

MariaDB [(none)]> 

This is will ask for password which we set during mysql_secure_installation as mentioned above. In one of earlier post we described How to connect/disconnect MySQL Server.
Now we create database as required for application and provide access to it for creating tables and data structure that used to maintain database through application console itself, like in wordpress we allow wordpress to access MySQL database and save data in its database’s tables which could display through Apache console on web.

Install PHP

In this section, we will talk about how to install and configure PHP in Ubuntu machines, So PHP is most of time used to write website content code which would display on browser. It can also used to run script in background to access database for display data.

So, we need to use apt-get command to install PHP packages like mentioned below.We are taking care of that our PHP code need to work with Apache and need to access MySQL database.

# apt-get install php libapache2-mod-php php-mcrypt php-mysql

This will install PHP7 packages which we need to configure with Apache Server. In ubuntu17.10, this configuration is default and already placed.

# cat  /etc/apache2/mods-enabled/dir.conf

	DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

Install PHP modules

Sometime we need to install some other PHP modules for some extra features in Apache PHP website, which helps to enhance web application functionality in various prospects.Below some of apt commands used to know and display information about PHP modules.

Command will show various php modules available.

apt-cache search php- | less

These command will show PHP module detail, which easily install with same apt-get install if required for Application.

apt-cache show php-bcmath

verify PHP working

When everything is installed and configured we should verify PHP working over Apache website, For same we could create one PHP page like below

# cat  /var/www/html/info.php

Now check this PHP page through browser http://IP/info.php Will display like below