How to Install PHP 7 on Debian 9

Install PHP 7 on Debian 9

In this tutorial we are going to learn how to install PHP 7 on Debian 9. We will also install and configure its prerequisites. The PHP Hypertext Preprocessor (PHP) is a programming language that allows web developers to create dynamic and interactive Web pages. As of 2018, PHP was used as the server-side programming language on 85% of 10 million most popular websites

I recommend to use a minimal Ubuntu server setup as a basis for the tutorial, that can be a virtual or a root server image with an Debian 9 Stretch minimal install from a web hosting company or you use our minimal server tutorial to install a server from scratch.

Install PHP 7 on Debian 9

Step 1. First, before we install packages, it’s a good idea to update repository and software packages. Run the following command on your Debian 9 OS:

sudo apt update
sudo apt upgrade

Step 2. Installing PHP 7 on Debian 9.

First, install the dependencies necessary to add a new repository over HTTPS:

sudo apt install apt-transport-https ca-certificates curl software-properties-common

Next add the GPG key and enable the ondrej’s repository:

curl -fsSL https://packages.sury.org/php/apt.gpg | sudo apt-key add -
sudo add-apt-repository "deb https://packages.sury.org/php/ $(lsb_release -cs) main"

Now install PHP by specifying the version we want to use:

sudo apt update
sudo apt install php7.2-common php7.2-cli

Once the package has finished installing, we can test PHP in the command line:

php -v

If PHP installed correctly, you should see something similar below:

PHP 7.2.8-1+0~20180902124257.2+stretch~1.gbp571e46 (cli) (built: Sep 02 2018 12:11:00) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.8-1+0~20180902124257.2+stretch~1.gbp571e46, Copyright (c) 1999-2018, by Zend Technologies

You may also need to install modules based on your application requirements. Use the following command to search available PHP 7 modules in the package repository:

sudo apt-cache search php7*

Step 3. Verify PHP for Apache.

Create a new file called info.php in /var/www/html.

sudo nano /var/www/html/info.php

Paste in the following PHP code:

<?php
phpinfo();

Then, load this file in the browser by going to:

http://example.com/info.php or http://your_ip/info.php

Congratulation’s! You have successfully install and configured PHP 7 on your Debian Stretch. Thanks for using this tutorial installing PHP 7 on Debian 9 (Stretch) system.

How to Install Nginx on Debian 9

Install Nginx on Debian 9

In this tutorial we are going to learn how to install Nginx on Debian 9. We will also install and configure its prerequisites. Nginx is one of the most common open source web server software. It is widely used for load balancing, reverse proxying, media streaming and much more. The specialization of Nginx is its capability to operate on little resource and handle a high number of requests. Nginx works as an internet server, proxy, load balancer and Reverse Proxy. Today Nginx is installed on more afterward 450 million servers net, and is used by a few of the maximum traffic sites on the internet such as Dropbox and Netflix.

I recommend to use a minimal Ubuntu server setup as a basis for the tutorial, that can be a virtual or a root server image with an Debian 9 Stretch minimal install from a web hosting company or you use our minimal server tutorial to install a server from scratch.

Install Nginx on Debian 9

Step 1. First, before we install packages, it’s a good idea to update repository and software packages. Run the following command on your Debian 9 OS:

sudo apt update
sudo apt upgrade

Step 2. Installing Nginx on Debian 9 Stretch.

Nginx is available in the Debian package repositories simple. Follow this command to install Nginx:

sudo apt install nginx

Once the installation is completed, check the status and the version of the Nginx service, with:

systemctl start nginx
systemctl enable nginx

Step 3. Configure Firewall ports for Nginx.

If you use iptables to filter connections to your system, you’ll need to open HTTP (80) and HTTPS (443) ports:

sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 443 -j ACCEPT

Step 4. Verifying Apache Installation.

To verify that everything works correctly, open your browser, type your server IP address or doman name http://Your_IP_or_Your_Domain/

Step 5. Nginx Configuration File Structure.

  • Nginx configuration files are stored in the /etc/nginx directory.
  • The main Nginx configuration file is /etc/nginx/nginx.conf.
  • Server block (vhost) configuration files are stored in /etc/nginx/sites-available directory. The configuration files found in this directory are not used by Nginx unless they are linked to the /etc/nginx/sites-enabled directory.
  • Activating server blocks is done by creating a symlink (a pointer) from the configuration file sites in a sites-available directory to the sites-enabled directory.
  • To write more maintainable code, it’s a good idea to a follow a standard naming convention. For example if your domain name is mydomain.com then your the configuration file should be named /etc/nginx/sites-available/mydomain.com.conf.
  • The /etc/nginx/snippets directory contains configuration snippets that can be included in the server block files. If you use repeatable configuration segments then you can refactor those segments into snippets and include the snippet file to the server blocks.
  • Nginx log files (access.log and error.log) are located in the /var/log/nginx/ directory. It is recommended to have a different access and error log files for each server block.

Congratulation’s! You have successfully install and configured Nginx on your Debian Stretch. Thanks for using this tutorial installing Nginx web server on Debian 9 (Stretch) system.

How to Install PostgreSQL on Debian 9

Install PostgreSQL on Debian 9

In this tutorial we are going to learn how to install PostgreSQL on Debian 9. We will also install and configure its prerequisites. PostgreSQL is a free, open-source object-relational database management system (object-RDBMS), similar to MySQL, and is standards-compliant and extensible. It is commonly used as a back-end for web and mobile applications.

I recommend to use a minimal Ubuntu server setup as a basis for the tutorial, that can be a virtual or a root server image with an Debian 9 Stretch minimal install from a web hosting company or you use our minimal server tutorial to install a server from scratch.

Install PostgreSQL on Debian 9

Step 1. First, ensure your system and apt package lists are fully up-to-date by running the following:

apt-get update -y
apt-get upgrade -y

Step 2. Installing PostgreSQL on Debian 9.

Run the following command to install the PostgreSQL 9 package:

sudo apt install postgresql postgresql-contrib

When the installation is completed, the PostgreSQL service will start automatically. To check an verify that PosgreSQL server/client are installed, you can use the following command:

psql --version

Step 3. Basic PostgreSQL usage on Debian 9.

Let’s log in to postfix to verify that installation completed successfully:

su - postgres

Use psql command to access PostgreSQL prompt with admin privileges:

$ psql

psql (9.6.7)
Type "help" for help.

postgres=#

You may create password for user postgres for security purpose:

postgres=# \password postgres

Now you can execute command specific to PostgreSQL. For example, to list all current databases you can type \l and press Enter:

postgres=# \l
                                  List of databases
   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
 postgres  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
 template0 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
 template1 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
(3 rows)

You can also create databases and tables, insert data, retrieve data and do many other things using the PostgreSQL interactive terminal.

Congratulation’s! You have successfully install and configured PostgreSQL on your Debian Stretch. Thanks for using this tutorial installing PostgreSQL on Debian 9 (Stretch) system.

How to Install Apache Tomcat on Debian 9

Install Apache Tomcat on Debian 9

In this tutorial we are going to learn how to install Apache Tomcat on Debian 9. We will also install and configure its prerequisites. Apache Tomcat is a web server and servlet container that is used to serve Java applications. Tomcat is an open source implementation of the Java Servlet and JavaServer Pages technologies, published by the Apache Software Foundation.

I recommend to use a minimal Ubuntu server setup as a basis for the tutorial, that can be a virtual or a root server image with an Debian 9 Stretch minimal install from a web hosting company or you use our minimal server tutorial to install a server from scratch.

Install Apache Tomcat on Debian 9

Step 1. First, before we install packages, it’s a good idea to update repository and software packages. Run the following command on your Debian 9 OS:

sudo apt update
sudo apt upgrade

Step 2. Installing Java.

Apache Tomcat is written in Java application, so Java runtime environment needs to be installed:

sudo apt install default-jdk

Once Java is installed, you can verify the Java version by using the following command:

java -version

Step 3. Create Tomcat Group and User.

Tomcat should not be run as root user. So, create a normal user for running the Tomcat service:

sudo useradd -m -U -d /opt/tomcat -s /bin/false tomcat

Step 4. Installing the latest Apache Tomcat on Debian 9.

First, download the latest version of the Apache Tomcat from the website:

cd /tmp
wget http://www-us.apache.org/dist/tomcat/tomcat-8/v8.5.31/bin/apache-tomcat-8.5.31.zip

Then extract the Tomcat archive and move it to your desired (/opt/tomcat) directory:

unzip apache-tomcat-*.zip
sudo mv apache-tomcat-*/ /opt/tomcat

Next, we will create a symbolic link named latest which will point to the Tomcat installation directory:

sudo ln -s /opt/tomcat/apache-tomcat-* /opt/tomcat/latest

Now change the proper ownership using following command:

sudo chown -R tomcat: /opt/tomcat
sudo chmod +x /opt/tomcat/latest/bin/*.sh

Step 5. Create Systemd Unit for Tomcat.

Now you will need to create a systemd service file to manage the Tomcat process so you can run Tomcat as a service:

nano /etc/systemd/system/tomcat.service

Add the below information to Tomcat systemd service file:

[Unit]
Description=Tomcat 8.5 servlet container
After=network.target

[Service]
Type=forking

User=tomcat
Group=tomcat

Environment="JAVA_HOME=/usr/lib/jvm/default-java"
Environment="JAVA_OPTS=-Djava.security.egd=file:///dev/urandom"

Environment="CATALINA_BASE=/opt/tomcat/latest"
Environment="CATALINA_HOME=/opt/tomcat/latest"
Environment="CATALINA_PID=/opt/tomcat/latest/temp/tomcat.pid"
Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC"

ExecStart=/opt/tomcat/latest/bin/startup.sh
ExecStop=/opt/tomcat/latest/bin/shutdown.sh

[Install]
WantedBy=multi-user.target

Notify systemd that we created a new unit file and start the Tomcat service by executing:

systemctl daemon-reload
systemctl start tomcat 
systemctl enable tomcat

Step 6. Configure Firewall Apache Tomcat.

In order to test Apache Tomcat in a web browser, you need to modify the firewall rules:

sudo ufw allow 8080

Step 7. Configure Tomcat Web Management Interface.

In order to use the manager webapp that comes with Tomcat, we must add a login to our Tomcat server. We will do this by editing the tomcat-users.xml file:

nano /opt/tomcat/conf/tomcat-users.xml

Place the following two lines just above the last line:

<role rolename="admin-gui,manager-gui"/>
<user username="admin" password="tomcat" roles="manager-gui,admin-gui"/>

Restart Apache Tomcat to put your modifications into effect:

systemctl restart tomcat

Step 8. Accesing Apache Tomcat.

The Apache Tomcat is now accessible on the default port, which is 8080. The admin UI should be accessible at:

http://<your_domain_or_IP_address>:8080

Congratulation’s! You have successfully install and configured Tomcat on your Debian Stretch. Thanks for using this tutorial installing Apache Tomcat on Debian 9 (Stretch) system.

How to Install Apache on Debian 9

Install Apache on Debian 9

In this tutorial we are going to learn how to install Apache on Debian 9. We will also install and configure its prerequisites. Apache web server is among the most popular and powerful web servers in the world, as a result of its ease of administration and flexibility. In this tutorial we will install Apache on a host which doesn’t have a web server or database server installed.

I recommend to use a minimal Ubuntu server setup as a basis for the tutorial, that can be a virtual or a root server image with an Debian 9 Stretch minimal install from a web hosting company or you use our minimal server tutorial to install a server from scratch.

Install Apache on Debian 9

Step 1. First, before we install packages, it’s a good idea to update repository and software packages. Run the following command on your Debian 9 OS:

sudo apt update
sudo apt upgrade

Step 2. Installing Apache web server on Debian 9 Stretch.

Install the apache2 package with the following commands:

sudo apt install apache2

Now that Apache installed on your Debian system, Start the Apache service and make it start on system boot:

sudo systemctl start apache2.service
sudo systemctl enable apache2.service

Step 3. Configure Firewall Apache.

If you use iptables to filter connections to your system, you’ll need to open HTTP (80) and HTTPS (443) ports:

sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 443 -j ACCEPT

Step 4. Verifying Apache Installation.

To verify that everything works correctly, open your browser, type your server IP address or doman name http://Your_IP_or_Your_Domain/

Step 5. Apache Configuration File Structure.

  • In Debian based systems, Apache configuration files are located in the /etc/apache2 directory.
  • The main Apache configuration file is /etc/apache2/apache2.conf.
  • The ports that Apache will listen to are specified in the /etc/apache2/ports.conf file.
  • Apache Virtual Hosts files are located in the /etc/apache2/sites-available directory. The configuration files found in this directory are not used by Apache unless they are linked to the /etc/apache2/sites-enabled directory.
  • You can activate a virtual host directive by creating a symlink using the a2ensite command from the configuration files found in the sites-available directory of the sites-enabled directory. To deactivate a virtual host use the a2dissite command.
  • It is highly recommended to follow the standard naming convention, for example, if your domain name is mydomain.com then the domain configuration file should be named /etc/apache2/sites-available/mydomain.com.conf
  • Configuration files that are used for loading various Apache modules are located in the /etc/apache2/mods-available directory. Configurations in the mods-available directory can be enabled by creating a symlink to the /etc/apache2/mods-enable directory using the a2enconf command and disabled with the a2disconf command.
  • Files containing global configuration fragments are stored in the /etc/apache2/conf-available directory. Files in the conf-available directory can be enabled by creating a symlink to the /etc/apache2/conf-enabled using the a2enconf command and disabled with the a2disconf command.
  • Apache log files (access.log and error.log) are located in the /var/log/apache directory. It is recommended to use a different access and error log files for each virtual host.

Congratulation’s! You have successfully install and configured Apache on your Debian Stretch. Thanks for using this tutorial installing Apache web server on Debian 9 (Stretch) system.

How to Install Docker on Debian 9

Install Docker on Debian 9

In this tutorial we are going to learn how to install Docker on Debian 9. We will also install and configure its prerequisites. Docker is a container virtualization technology that has gained widespread popularity in recent times, it offers a more efficient way to deploy the application. With Docker, the applications reside inside the container on top of the Linux operating system. Docker uses Kernel features such as cgroups and namespace to allow an independent container to run on single OS instance.

I recommend to use a minimal Ubuntu server setup as a basis for the tutorial, that can be a virtual or a root server image with an Debian 9 Stretch minimal install from a web hosting company or you use our minimal server tutorial to install a server from scratch.

Install Docker on Debian 9

Step 1. First, before we install packages, it’s a good idea to update repository and software packages. Run the following command on your Debian 9 OS:

sudo apt update
sudo apt upgrade

Step 2. Install the dependencies.

Now run the following command to install the packages required to install Docker:

sudo apt install apt-transport-https ca-certificates curl software-properties-common gnupg2

Step 3. Installing Docker on Debian 9 Stretch.

First, add Docker’s GPG key to your apt keyring by executing:

curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -

Next, add the Docker stable repository run the following command:

sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable"

To install docker on Debian 9, run following commands:

sudo apt update
sudo apt install docker-ce

Start Docker service using the following command as per your operating systems. Also, enable Docker service to auto start on system boot:

sudo systemctl start docker
sudo systemctl enable docker

Verify the installation:

docker -v

Step 4. Deploying your first Docker image, “Hello World!”.

You can use the handy hello-world test to verify whether or not Docker will run on your system:

docker run hello-world

You will get the following output:

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world

42745666786f6: Pull complete
a3ee46f7veb02: Pull complete
Digest: sha256:4f32210em0naad5cac92BMWE46476c754fRAMONA8e5a8ba
Status: Downloaded newer image for hello-world:latest

Hello from Docker.
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker Hub account:
 https://hub.docker.com

For more examples and ideas, visit:
 https://docs.docker.com/engine/userguide/

Congratulation’s! You have successfully install and configured Docker on your Debian Stretch. Thanks for using this tutorial installing Docker on Debian 9 (Stretch) system.

How to Install Go on Debian 9

Install Go on Debian 9

In this tutorial we are going to learn how to install Go on Debian 9. We will also install and configure its prerequisites. Go also understand as Golang, is an open source programming language developed by Google. Many popular programs, including Grafana, Docker and Kubernetes, are written in Go.

I recommend to use a minimal Ubuntu server setup as a basis for the tutorial, that can be a virtual or a root server image with an Debian 9 Stretch minimal install from a web hosting company or you use our minimal server tutorial to install a server from scratch.

Install Go on Debian 9

Step 1. First, before we install packages, it’s a good idea to update repository and software packages. Run the following command on your Debian 9 OS:

sudo apt update
sudo apt upgrade

Step 2. Installing Go on Debian 9.

First, download the Go binary you can use either wget or curl:

wget https://dl.google.com/go/go1.10.3.linux-amd64.tar.gz

Next, use tar to extract the tarball to the /usr/local directory:

sudo tar -C /usr/local -xzf go1.10.3.linux-amd64.tar.gz

Then add it to your path:

export PATH=$PATH:/usr/local/go/bin

Save the file, and load the new PATH environment variable into the current shell session:

source ~/profile

As the final test, if we run this:

go version

Step 3. Test the Installation.

To test whether Go is installed, we will set up a workspace and build a simple “Hello world” program:

mkdir ~/go
mkdir -p ~/go/src/hello

And in that directory create a file named hello.go:

### ~/go/src/hello/hello.go

package main
import "fmt"
func main() {
fmt.Printf("Hello, World\n")
}

Next, build the file switch to the ~/go/src/hello directory and run go build:

cd ~/go/src/hello
go build

Then, run the executable by simply executing the command bellow:

./hello

Result:

Hello, World

Congratulation’s! You have successfully install and configured Golang on your Debian Stretch. Thanks for using this tutorial installing Go data bases on Debian 9 (Stretch) system.

How to Install Git on Debian 9

Install Git on Debian 9

In this tutorial we are going to learn how to install Git on Debian 9. We will also install and configure its prerequisites. Git is a distributed version control program, which you can use to monitor the code varies (versions) while developing software. Git offers features such as reverting to a prior stage, multiple workflows, neighborhood branching and lots of others. This makes Git one of the best variant control systems and that is why it is used by many software developers.

I recommend to use a minimal Ubuntu server setup as a basis for the tutorial, that can be a virtual or a root server image with an Debian 9 Stretch minimal install from a web hosting company or you use our minimal server tutorial to install a server from scratch.

Install Git on Debian 9

Step 1. First, before we install packages, it’s a good idea to update repository and software packages. Run the following command on your Debian 9 OS:

sudo apt update
sudo apt upgrade

Step 2. Installing Git on Debian 9.

  • Method 1 Installing Git from Source.

First you need to install the packages necessary to build Git on your Debian system:

sudo apt install make libssl-dev libghc-zlib-dev libcurl4-gnutls-dev libexpat1-dev gettext unzip

Once the dependencies are installed open your browser, go to Git project’s mirror on GitHub and copy the latest release link address that ends in .tar.gz:

cd /usr/src/
sudo wget https://github.com/git/git/archive/v2.18.0.tar.gz -O git.tar.gz

Next, extract the file that you downloaded and switch to the git source directory by typing:

sudo tar -xf git.tar.gz
cd git-*

Then, compile and install Git by typing these two commands:

sudo make prefix=/usr/local all
sudo make prefix=/usr/local install

Once the installation is completed verify it by typing the following command:

git --version
  • Method 2 Installing Git from Default repository.

Use following command to install Git:

sudo apt install git

Step 3. Configuration of Git on Debian 9.

The first thing that you might want to do after the installation is to configure your own name and email address in Git so the changes you commit contain the correct information. You can do that by using the following commands:

git config --global user.name "ramona"
git config --global user.email "ramona@myvpsource.com"

Next we’ll verify the configuration changes by viewing the .gitconfig:

git config --list

For more information and command line options you can use the –help flag:

git --help

Congratulation’s! You have successfully install and configured Git on your Debian Stretch. Thanks for using this tutorial installing Git on Debian 9 (Stretch) system.