How To Install LAMP Stack on Ubuntu 18.04 LTS

Install LAMP Stack on Ubuntu 18

LAMP represents a full featured stack containing the most popular web server known as Apache, the most popular database server MySQL and the most popular open-source web programming language known as PHP. All components are free and open-source software, and the combination is suitable for building dynamic web pages.

This article assumes you have at least basic knowledge of linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple. I will show you through the step by step installation LAMP (Linux Apache, MySQL and PHP) on Ubuntu 18.04 LTS Bionic Beaver server.

Install LAMP Stack on Ubuntu 18.04 LTS Bionic Beaver

Step 1. First make sure that all your system packages are up-to-date

apt-get update
apt-get upgrade

Step 2. Installing Apache web server on Ubuntu 18.04 LTS Bionic Beaver.

We will be installing Apache with apt-get, which is the default package manager for ubuntu:

apt-get install -y apache2 apache2-utils

After installing Apache2, the commands below can be used to stop, start and enable Apache2 service to always start up with the server boots:

systemctl enable apache2
systemctl start apache2
systemctl status apache2

Check Apache version:

apache2 -v

You can verify that Apache is really running by opening your favorite web browser and entering the URL http://your-server’s-address, if it is installed, then you will see this:

apache2-ubuntu-default-page

Step 3. Installing MariaDB on Ubuntu 18.04 LTS Bionic Beaver.

Now that we have our web server up and running, it is time to install MariaDB. MariaDB is a database management system. Basically, it will organize and provide access to databases where our site can store information:

apt-get install mariadb-server mariadb-client

After installing MariaDB, the commands below can be used to stop, start and enable MariaDB service to always start up when the server boots:

systemctl status mariadb
systemctl enable mariadb
systemctl start mariadb

By default, MariaDB is not hardened. You can secure MariaDB using the mysql_secure_installation script. you should read and below each steps carefully which will set root password, remove anonymous users, disallow remote root login, and remove the test database and access to secure MariaDB:

mysql_secure_installation

Configure it like this:

- Set root password? [Y/n] y
- Remove anonymous users? [Y/n] y
- Disallow root login remotely? [Y/n] y
- Remove test database and access to it? [Y/n] y
- Reload privilege tables

To log into MariaDB, use the following command (note that it’s the same command you would use to log into a MySQL database):

mysql -u root -p

Step 4. Installing PHP 7.2 on Ubuntu 18.04 Bionic Beaver.

At the the time of this writing, PHP7.2 is the latest stable version of PHP and has a minor performance edge over PHP7.0. Enter the following command to install PHP7.2:

apt-get install software-properties-common
add-apt-repository ppa:ondrej/php

Run the commands below to install PHP 7.2 FPM and related modules:

apt-get update
apt-get install php7.2 libapache2-mod-php7.2 php7.2-common php7.2-mbstring php7.2-xmlrpc php7.2-soap php7.2-gd php7.2-xml php7.2-intl php7.2-mysql php7.2-cli php7.2-zip php7.2-curl

After install PHP and related modules, all you have to do is restart Apache2 to reload PHP configurations:

systemctl restart apache2

To test PHP, create a test file named info.php with he content below. Save the file, then browse to it to see if PHP is working:

nano /var/www/html/info.php

In this file, paste the following code:

<?php
phpinfo();
?>
1
2
3
	
<?php
phpinfo();
?>

Try to access it at http://your_server_ip/info.php . If the PHP info page is rendered in your browser then everything looks good and you are ready to proceed further.

php_ubuntu_test_18.04_LTS

Congratulation’s! You have successfully installed LAMP stack. Thanks for using this tutorial for installing LAMP (Linux Apache, MySQL and PHP) in Ubuntu 18.04 LTS (Bionic Beaver) system. For additional help or useful information, we recommend you to check the official Apache, MySQL and PHP web site.

How To Install Nagios on Ubuntu 18.04 LTS

Install Nagios on Ubuntu 18

Nagios is an open source software that can be used for network and infrastructure monitoring. Nagios will monitor servers, switches, applications and services. It alerts the System Administrator when something went wrong and also alerts back when the issues has been rectified. Resources that can be monitored include CPU, memory and disk space loads, log files, temperature or hardware errors. It can monitor various parameters and problems for services like HTTP, SMTP, DNS, and with the help of plugins it can be highly extended. Nagios core was originally designed to run under Linux, although it should work under most other unices as well.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo’ to the commands to get root privileges. I will show you through the step by step installation Nagios on a Ubuntu 18.04 (Bionic Beaver) server.

Install Nagios on Ubuntu 18.04 LTS Bionic Beaver

Step 1. First make sure that all your system packages are up-to-date by running these following apt-get commands in the terminal.

sudo apt-get update
sudo apt-get upgrade
[php]

<strong> Step 2. Install LAMP (Linux, Apache, MariaDB and PHP) server.</strong>

A Ubuntu 18.04 LAMP server is required. If you do not have LAMP installed, you can follow our guide here. Also install all required PHP modules:
[php]
apt-get install php7.1-cli php7.1-mbstring php7.1-gd php7.1-opcache php7.1-mysql php7.1-json php7.1-mcrypt php7.1-xml php7.1-curl

Step 3. Create users and groups for Nagios.

For security reasons, create a user and group specifically to run Nagios:

useradd nagios
groupadd nagcmd
usermod -a -G nagcmd nagios
usermod -a -G nagcmd www-data

Step 4. Installing Nagios and plugins on Ubuntu 18.04 LTS.

First thing to do is to go to Nagios’s download page and download the latest stable version of Nagios, At the moment of writing this article it is version 4.4.2:
wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.4.2.tar.gz
tar -zxvf /tmp/nagios-4.4.2.tar.gz
cd /tmp/nagios-4.4.2/

Perform below steps to compile the Nagios from the source code:

./configure --with-nagios-group=nagios --with-command-group=nagcmd --with-httpd_conf=/etc/apache2/sites-enabled/
make all
make install
make install-init
make install-config
make install-commandmode
make install-webconf

Next steps, Download latest nagios-plugins source and install using following commands:

wget http://www.nagios-plugins.org/download/nagios-plugins-2.1.1.tar.gz
tar xzf nagios-plugins-2.1.1.tar.gz
cd nagios-plugins-2.1.1
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install

Step 5. Configure Nagios on Ubuntu 18.04 Bionic Beaver.

Edit the /usr/local/nagios/etc/objects/contacts.cfg config file with your favorite editor and change the email address associated with the nagiosadmin contact definition to the address you’d like to use for receiving alerts.

nano /usr/local/nagios/etc/objects/contacts.cfg

Change the email address field to receive the notification:

[...]
define contact{
contact_name nagiosadmin ; Short name of userus
generic-contact ; Inherit default values from generic-contact template (defined above)
alias Nagios Admin ; Full name of useremail
[email protected] ; <<=== CHANGE THIS TO YOUR EMAIL ADDRESS ===
[...]

Step 6. Configure Apache web server for Nagios.

Now create nagios apache2 configuration file:

nano /etc/apache2/sites-enabled/nagios.conf

Edit the following lines if you want to access nagios administrative console from a particular IP series, Here, I want to allow nagios administrative access from 192.168.1.0/24 series only:

[...]
## Comment the following lines ##
#   Order allow,deny
#   Allow from all

## Uncomment and Change lines as shown below ##
Order deny,allow
Deny from all
Allow from 127.0.0.1 192.168.1.0/24
[...]

Enable Apache’s rewrite and cgi modules:

sudo a2enmod rewrite
sudo a2enmod cgi

Configure Apache authentication:

We need to setup the password for the user nagiosadmin. This username will be used to access the web interface so it is important to remember the password that you will input here. Set the password running the following command and enter the password twice:

# sudo htpasswd -s -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
New password:
Re-type new password:
Adding password for user nagiosadmin

Restart Apache for the changes to take effect:

systemctl restart apache2

Step 7. Verify and Start Nagios service.

Next we have to make Nagios start at boot time, so first verify that the configuration file has no errors running the following command:

sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

And you should get the output:

[...]
Checking objects...
    Checked 8 services.
    Checked 1 hosts.
    Checked 1 host groups.
    Checked 0 service groups.
    Checked 1 contacts.
    Checked 1 contact groups.
    Checked 24 commands.
    Checked 5 time periods.
    Checked 0 host escalations.
    Checked 0 service escalations.
Checking for circular paths...
    Checked 1 hosts
    Checked 0 service dependencies
    Checked 0 host dependencies
    Checked 5 timeperiods
Checking global event handlers...
Checking obsessive compulsive processor commands...
Checking misc settings...

Total Warnings: 0
Total Errors:   0

Things look okay - No serious problems were detected during the pre-flight check
[...]

Ubuntu 18.04 uses systemd for starting / stopping all the services, so, we need to create nagios.service file:

nano /etc/systemd/system/nagios.service

Add the following lines:

[Unit]
Description=Nagios
BindTo=network.target

[Install]
WantedBy=multi-user.target

[Service]
User=nagios
Group=nagios
Type=simple
ExecStart=/usr/local/nagios/bin/nagios /usr/local/nagios/etc/nagios.cfg

Enable Nagios to start automatically at system startup:

systemctl enable /etc/systemd/system/nagios.service

Now, start Nagios service:

systemctl start nagios

Step 8. Accessing Nagios.

Nagios will be available on HTTP port 80 by default. Open your favorite browser and navigate to http://your-domain.com/nagios or http://server-ip/nagios and complete the required the steps to finish the installation. When prompted for username and password you will introduce the username “nagiosadmin” and the password that you entered in step 6.
Nagios-admin-panel
Congratulation’s! You have successfully installed Nagios. Thanks for using this tutorial for installting Nagios monitoring tool in ubuntu 18.04 (Bionic Beaver) systems. For additional help or useful information, we recommend you to check the official Nagios web site.

How To Install LEMP on Ubuntu 16.04

Install LEMP on Ubuntu 16

A LEMP software stack is a group of open source software that is typically installed together to enable a server to host dynamic websites and web apps. This term is actually an acronym which represents the Linux operating system, with the Nginx web server (which replaces the Apache component of a LAMP stack). The site data is stored in a MySQL database (using MariaDB), and dynamic content is processed by PHP.

lemp stack install in ubuntu

This article assumes you have at least basic knowledge of linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple. I will show you through the step by step installation LEMP stack (Linux, Nginx, MariaDB and PHP) on Ubuntu 16.04 server.

Install LEMP on Ubuntu 16.04

Step 1. First make sure that all your system packages are up-to-date by running these following apt-get commands in the terminal.

apt-get update
apt-get upgrade

Note: If another web server like Apache2 was installed in your system, remove it first to avoid conflicts. To uninstall Apache, run the following commands:

sudo service apache2 stop
sudo apt-get remove --purge apache2 apache2-utils apache2.2-bin apache2-common -y
sudo apt-get autoremove -y
sudo apt-get autoclean -y

Step 2. Installing Nginx on Ubuntu 16.04.

Install Nginx with apt-get, which is the default package manager for Ubuntu:

sudo apt-get install nginx

Start Nginx service using the following command:

sudo systemctl start nginx

You can verify that Nginx is really running by opening your favorite web browser and entering the URL http://your-server’s-address, if it is installed, then you will see this:
nginx-default-page
The default web page for NGINX on Ubuntu 16.04

Step 3. Configure Nginx web server.

To get Nginx to work with PHP correctly, we need to make changes to the Nginx configuration file. This guide we will be using a simple Nginx config file:

sudo nano /etc/nginx/sites-available/default

Copy the following into your text editor:

server {
listen 80;
server_name your_domain_name.com;
root /usr/share/nginx/html;
index index.php index.html;
location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}

Once you have finished editing the file restart Nginx with:

sudo nginx -t
sudo systemctl restart nginx

Step 4. Installing MySQL on Ubuntu 16.04.

To install MySQL in Ubuntu 16.04 run the following command:

sudo apt-get install mysql-server php5-mysql

Once complete, you can verify MySQL is installed by running the below command:

systemctl status mysql

By default, MySQL is not hardened. You can secure MySQL using the mysql_secure_installation script. you should read and below each steps carefully which will set root password, remove anonymous users, disallow remote root login, and remove the test database and access to secure MySQL:

mysql_secure_installation

Configure it like this:

- Set root password? [Y/n] y
- Remove anonymous users? [Y/n] y
- Disallow root login remotely? [Y/n] y
- Remove test database and access to it? [Y/n] y
- Reload privilege tables now? [Y/n] y

To log into MySQL, use the following command (note that it’s the same command you would use to log into a MySQL database):

mysql -u root -p

Step 5. Installing and Configuring PHP on Ubuntu 16.04.

Install PHP on the Ubuntu 16.04 with the following command to begin the install:

sudo apt-get install php php-fpm php7.0-mysql

Once the installation is finished, edit the server php.ini file and change the cgi.fix_pathinfo parameter value to 0. By default it will be commented out with a semi-colon and the value set to 1 which practically ensures that PHP will attempt to execute the closest file available when a requested PHP file can’t be found. This is a bad security practice, so let’s change it. Execute the below command:

nano /etc/php/7.0/fpm/php.ini

Now find the cgi.fix_pathinfo line, uncomment it and set the value to 0. Save and close the file.

Your server should restart Nginx automatically after the installation of both MySQL and PHP. If it doesn’t, execute this command:

sudo systemctl restart nginx

To test PHP, create a test file named info.php with he content below. Save the file, then browse to it to see if PHP is working:

nano /usr/share/nginx/html/info.php

Copy the following into your text editor:

<!--?php phpinfo(); ?-->

Try to access it at http://your_server_ip/info.php . If the PHP info page is rendered in your browser then everything looks good and you are ready to proceed further.

installing-lemp-ubuntu-16-04
Congratulation’s! You have successfully installed LEMP stack. Thanks for using this tutorial for installing LAMP (Linux, Nginx, MySQL and PHP) in Ubuntu 16.04 system. For additional help or useful information, we recommend you to check the official Nginx, MySQL and PHP web site

You Might Also Like: How To Install LAMP Stack on Ubuntu 16.04