Install LAMP stack on Debian

LAMP stack is used for hosting Websites and Apps. LAMP stack is a set of packages such as Linux, Apache, MySQL, and PHP. In this tutorial, you are going to learn How to install LAMP stack on Debian.

Prerequisites

Before you start to install LAMP stack on Debian 9. You must have the non-root user account on your server/desktop with sudo privileges.

1. Install Apache

Update the apt package manager index by running following command

sudo apt update

Now install Apache web server by typing following command

sudo apt install apache2

Confirm the installation of Apache by using the following command

sudo systemctl status apache2

If you have UFW firewall enabled then you should open port 80 for HTTP and 443 for HTTPS to Apache Web Server. Enter the following commands to enable ports.

sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw reload

Now you can verify your Apache installation by visiting http://YOUR_DOMAIN_NAME/ or http://localhost/

2. Install MariaDB

Update apt package manager index by typing following command

sudo apt update

Now you can install MariaDB by running following command

sudo apt install mariadb-server mariadb-client

Check the status and confirm installation by typing following command

sudo systemctl status apache2

To secure MariaDB run following command.

sudo mysql_secure_installation

Once you execute above command you will be asked to enter current password (Press ENTER for none) then you will be asked following questions, enter y for following questions:

  • Set root password? : y
  • Remove anonymous users? : y
  • Disallow root login remotely? : y
  • Remove test database and access to it? : y
  • Reload privilege tables now? : y

3. Install PHP

To install PHP you should first update package manager index. Update apt package manager index by typing

sudo apt update

Install PHP and some of its common extensions by typing

sudo apt install php php-common php-mysql php-gd php-cli

After installing PHP you can confirm installtion by creating info.php file. Run following command to create info.php file.

echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php

Now visit http://YOUR_DOMAIN_NAME/info.php or http://localhost/info.php in your browser to confirm installation.

Conclusion

You have successfully learned how to install LAMP stack on Debian 9. If you have any queries regarding this please don’t forget to comment below.

Install LAMP stack on Ubuntu

LAMP stack is a set of packages such as Linux, Apache, MySQL, and PHP. LAMP stack is used for hosting Websites and Apps. In this tutorial, you are going to learn How to install LAMP stack on Ubuntu.

Prerequisites

Before you start to install LAMP stack on Ubuntu 18.04. You must have the non-root user account on your server/desktop with sudo privileges.

1. Install Apache

First, you will need to update the package manager index by typing

sudo apt update

Now install Apache by running following command

sudo apt install apache2

Confirm the installation of Apache by using the following command

sudo systemctl status apache2

If you have UFW firewall enabled then you should open port 80 for HTTP and 443 for HTTPS to Apache Web Server. Enter the following commands to enable ports.

sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw reload

Now you can verify your Apache installation by visiting http://YOUR_DOMAIN_NAME/ or http://localhost/

2. Install MariaDB

Update apt package manager index by typing following command

sudo apt update

Now you can install MariaDB by running following command

sudo apt install mariadb-server mariadb-client

Check the status and confirm installation by typing following command

sudo systemctl status apache2

To secure MariaDB run following command.

sudo mysql_secure_installation

Once you execute above command you will be asked to enter current password (Press ENTER for none) then you will be asked following questions, enter y for following questions:

  • Set root password? : y
  • Remove anonymous users? : y
  • Disallow root login remotely? : y
  • Remove test database and access to it? : y
  • Reload privilege tables now? : y

3. Install PHP

To install PHP you should first update package manager index then you will install PHP.

Update apt package manager index by typing

sudo apt update

Install PHP and some of its common extensions by typing

sudo apt install php php-common php-mysql php-gd php-cli

After installing PHP you can confirm installtion by creating info.php file. Run following command to create info.php file.

echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php

Now visit http://YOUR_DOMAIN_NAME/info.php or http://localhost/info.php in your browser to confirm installtion.

Conclusion

You have successfully learned how to install LAMP stack on Ubuntu 18.04. If you have any queries regarding this please don’t forget to comment below.

Install MariaDB on Ubuntu 18.04

MariaDB is the fork of MySQL and backward compatible replacement for MySQL. Here in this tutorial, we are going to show you how to install MariaDB 10 on Ubuntu server in the following ways:

1. Install MariaDB from Ubuntu PPA
2. Install MariaDB from Official Repository.

In Ubuntu 18.04’s main repository by default contains repository for MariaDB. So the first way is recommended by us to install MariaDB.

Prerequisites

Before you start installing MariaDB 10.3 on Ubuntu 18.04. You must have non-root user account on your server with sudo privileges.

1. Install MariaDB from Ubuntu PPA

As Ubuntu 18.04 by default has MariaDB repository in its main repository. You will first update package manager index then you will install MariaDB 10 on Ubuntu.

To Update apt package manager index type following command.

sudo apt update

Install MariaDB server by typing following and hitting Enter.

sudo apt install mariadb-server

Now confirm the installation by typing following

mysql -V

The output should be :

mysql  Ver 15.1 Distrib 10.1.29-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2

After installation, MariaDB will start automatically. To check status type following command.

sudo systemctl status mariadb

The output should be :

● mariadb.service - MariaDB database server
    Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset
    Active: active (running) since Sun 2018-10-11 14:15:57 UTC; 38s ago
    Main PID: 14532 (mysqld)
    Status: "Taking your SQL requests now..."
    Tasks: 27 (limit: 507)
    CGroup: /system.slice/mariadb.service
        └─14532 /usr/sbin/mysqld

2. Installing MariaDB from Official Repository

MariaDB officially supports installer for MariaDB. Here you will need to download it from one of the mirrors at [MariaDB Download Page](http://https://downloads.mariadb.org/mariadb/repositories).

Import MariaDB key to your system by typing following

sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8

After Importing key add MariaDB repository

sudo add-apt-repository 'deb [arch=amd64,arm64,ppc64el] http://ftp.utexas.edu/mariadb/repo/10.3/ubuntu bionic main'

Now update the apt package manager index by typing following

sudo apt update

Install MariaDB server by typing following and hitting Enter.

sudo apt install mariadb-server

Now confirm the installation by typing following

mysql -V

The output should be :

Output:
mysql Ver 15.1 Distrib 10.1.29-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2

After installation, MariaDB will start automatically. To check status type following command.

sudo systemctl status mariadb

3. Setting Up MariaDB

After installation, we have to improve MariaDB security by typing following

sudo mysql_secure_installation

NOTE: it is recommended to answer ‘Y’ for all questions asked during secure installation.

You can log in to MariaDB by typing

mysql -u root -p

Conclusion

You have successfully learned how to install MariaDB 10 on Ubuntu 18.04. If you have any queries please don’t forget to comment out.

Install LEMP Stack On Ubuntu

LEMP stack stands for Linux, Nginx, MariaDB, and PHP. Here in LAMP stack which stands for Linux, Apache, MariaDB and PHP, all components are not tightly coupled. So by replacing Apache With Nginx, we are installing LEMP stack. This tutorial outlines how to install LEMP stack on Ubuntu 18.04.

Prerequisites

Before you start to install LEMP on Ubuntu 18.04. You must have a non-root user account on your server with sudo privileges.

1. Install NGINX

To install Nginx first update local package index to access most recent package listing by typing

sudo apt update

Now install Nginx by typing

sudo apt install nginx

You can check the status of Nginx by typing

systemctl status nginx

The output should be:

Output:
    ● nginx.service - A high performance web server and a reverse proxy server
    Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
    Active: active (running) since Fri 2018-07-01 16:08:19 UTC; 1 days ago
    Docs: man:nginx(8)
    Main PID: 2369 (nginx)
    Tasks: 2 (limit: 1153)
    CGroup: /system.slice/nginx.service
        ├─2369 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
        └─2380 nginx: worker process

2. Install MariaDB

To install MariaDB and related MySQL php extension type following command.

sudo apt install mariadb-server php-mysql

To setup secure installation enter following command, you will be prompted for the password which is not set previously that time press ENTER only.

sudo mysql_secure_installation

3. Install PHP

By default Nginx does not support native PHP processing. So you will need to install php-fpm (“fastCGI process manager”). Now you can install php-fpm by typing following command.

sudo apt install php-fpm

You can check the status where it is correctly installed or not by following command

systemctl status php7.2-fpm

4. Set up nginx configuration file

Create directory inside var/www/html named example.com (you can use your domain name).

sudo mkdir -p /var/www/html/example.com

Now you should remove the default configuration file provided. To remove default Nginx configuration file type following.

sudo rm -f /etc/nginx/sites-enabled/default

Configuration files for the website are stored inside /etc/nginx/sites-available directory so you need to create configuration file inside this directory named example.com.conf (you can use your domain name). Then enter following code inside that file by replacing example.com with your domain name.

/etc/nginx/sites-available/example.com.conf
server { 
    listen 80 default_server;
    listen [::]:80 default_server;

    server_name example.com www.example.com; 
    root /var/www/html/example.com; 
    index index.php; 

    location / { 
        try_files $uri $uri/ =404; 
    } 

    location ~* \.php$ { 
        fastcgi_pass unix:/run/php/php7.2-fpm.sock; 
        include fastcgi_params; 
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
        fastcgi_param SCRIPT_NAME $fastcgi_script_name; 
    }  
}

Create a link of above configuaration file inside /etc/nginx/sites-enabled/ directory by typing

sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/

5. Testing LEMP stack

Ensure your domain reaching at your server by configuring DNS records of your domain.

Now you need to restart PHP and reload Nginx configuration file as you have made changes in Nginx configuration directory. Type following command to restart PHP and reload Nginx.

sudo systemctl restart php7.2-fpm
sudo nginx -s reload

You can check the status of Nginx by typing following.

sudo nginx -t

Create an index.php file inside /var/www/html/example.com directory and enter following code inside the file.

<html>
    <head>
        <h2>Index Page</h2>
    </head>
    <body>
        <?php 
        echo '<p>Hello,</p>';
        
        // Define PHP variables for the MySQL connection.
        $servername = "localhost";
        $username = "test_user";
        $password = "password";
    
        // Creating a MySQL connection.
        $conn = mysqli_connect($servername, $username, $password);
     
        // Show if the connection fails or is successful.

        if (!$conn) {
            exit('<p>Your connection has failed.<p>' . mysqli_connect_error());
        }
        else {
            echo '<p>You have connected successfully.</p>';
        }
        ?>
    </body>
</html>

Conclusion

In this tutorial you have successfully learned how to install LEMP stack on Ubuntu 18.04. If you have any queries regarding this please don’t forget to comment below.