Login with your Social Account

How To Set Up Apache2 Virtual Hosts on Ubuntu 16.04 / 18.04 / 18.10

Here is how you can set up Apache2 Virtual Hosts on Ubuntu. In particular on Vultr’s instance i.e. Ubuntu 16.04 / 18.10 and 18.04 LTS.

Apache2 Virtual Hosts can run more than one website on a single server machine. With Virtual Hosts, you can specify the multiple site document roots, define a separate security policy for each site, use different SSL certificates and much more.

Have an Ubuntu 16.04 x64 / 18.01 x64 / 18.10 x64 instance.
Logged in as a root with sudo privileges.
You will also need to have Apache2 installed by following these instructions.
To get started with the set up of Apache2 Virtual Hosts, follow the steps below:

Step 1: Create the Directory Structure
The first step that we are going to take is to create a directory structure that will hold the website data and will be serving to visitors. The document root is the directory where the website data for a domain name is stored. You can define the document root to anywhere you want but in this article, we will use the default document root which is /var/www/html and our directory structure will be

| |__ public
| |__ public
| |__ public
We will create a directory here for the virtual hosts we plan on making. Within each of these directories, we will create a public folder that will hold our actual website data. This gives us some flexibility in our hosting.

You can create directories by using the following command:

sudo mkdir -p /var/www/html/
sudo mkdir -p /var/www/html/
sudo mkdir -p /var/www/html/
Step 2: Grant Permissions
As we are running the commands as a sudo user and the newly created files and directories are owned by the root user.

To avoid any permission issues we can change the ownership of the domain document root directory to the apache user (www-data):

sudo chown -R www-data:www-data /var/www/html/
sudo chmod -R 755 /var/www/html/html/
Step 3: Create a Virtual Hosts
By default, Apache2 Virtual Hosts on Ubuntu configuration files are stored in /etc/apache2/sites-available directory and can be enabled by creating symbolic links to the /etc/apache2/sites-enabled directory.

Open your editor of choice and create the basic Virtual Host configuration file in /etc/apache2/sites-available/ with the following code.

Options FollowSymLinks
AllowOverride None
Require all denied

Options -Indexes +FollowSymLinks
AllowOverride All

DocumentRoot /var/www/html/

CustomLog ${APACHE_LOG_DIR}/ combined

To enable the new virtual host file we need to create a symbolic link from the virtual host file to the sites-enabled directory, which is read by apache2 during startup. To enable the virtual host is by using the a2ensite helper i.e.

sudo a2ensite
sudo systemctl restart apache2.service
Once done, test the configuration for any syntax errors with:

sudo apachectl configtest
If there are no errors you will see the following output:

Syntax OK
Now that you have your virtual hosts configured, you can test your set up by opening any browser and browse to the server domain name. You should see that everything is working correctly.

You have learned how to set up an apache2 virtual host configuration to host multiple domains on Ubuntu server. You can repeat the steps we outlined above and create additional virtual hosts for all your domains.

how to Start / Stop and Restart Apache 2 Web Server Command

Debian/Ubuntu Linux Specific Commands to Start/Stop/Restart Apache
You can either use service or /etc/init.d/ command as follows on Debian Linux version 7.x or Ubuntu Linux version Ubuntu 14.10 or older:

Restart Apache 2 web server, enter:
# /etc/init.d/apache2 restart

$ sudo /etc/init.d/apache2 restart

$ sudo service apache2 restart

To stop Apache 2 web server, enter:
# /etc/init.d/apache2 stop

$ sudo /etc/init.d/apache2 stop

$ sudo service apache2 stop

To start Apache 2 web server, enter:
# /etc/init.d/apache2 start

$ sudo /etc/init.d/apache2 start

$ sudo service apache2 start

A note about Debian/Ubuntu Linux systemd users
Use the following systemctl command on Debian Linux version 8.x+ or Ubuntu Linux version Ubuntu 15.04+ or above:
## Start command ##
systemctl start apache2.service
## Stop command ##
systemctl stop apache2.service
## Restart command ##
systemctl restart apache2.service

CentOS/RHEL (Red Hat) Linux version 4.x/5.x/6.x or older specific commands
## Start ##
service httpd start
## Stop ##
service httpd stop
## Restart ##
service httpd restart

CentOS/RHEL (Red Hat) Linux version 7.x or newer specific commands
Most modern distro now using systemd, so you need to use the following command:
## Start command ##
systemctl start httpd.service
## Stop command ##
systemctl stop httpd.service
## Restart command ##
systemctl restart httpd.service

Generic method to start/stop/restart Apache on a Linux/Unix
The syntax is as follows (must be run as root user):
## stop it ##
apachectl -k stop
## restart it ##
apachectl -k restart
## graceful restart it ##
apachectl -k graceful
## Start it ##
apachectl -f /path/to/your/httpd.conf
apachectl -f /usr/local/apache2/conf/httpd.conf

How to Set Up An RTMP Server on Ubuntu Linux Using Nginx

How to Set Up An RTMP Server on Ubuntu Linux Using Nginx

The Real Time Messaging Protocol (RTMP) was developed by Macromedia as a method for transferring data, audio, and video for their Flash technology. Macromedia was subsequently acquired by Adobe, since when the specification has been partially released enabling third parties to implement it within Adobe’s own server and client software. This has led to the technology being commonly used when streaming media for a variety of providers. In this article, we’ll be looking at setting up your own media server using Nginxp-RTMP on Ubuntu 14.04.

Nginx RTMP Protocol

Nginx-RTMP is an open-source extension module for the Nginx web server that can be used as a media streaming server for both live streams and video on demand using RTMP. This doesn’t come pre-packaged for the operating system, so we’ll need to build Nginx with this module from source code. The first thing we need to do is get some bits. To do so, enter the following:

sudo apt-get install build-essential libpcre3 libpcre3-dev libssl-dev unzip

This will take some time. Once these are installed we then need to grab the nginx source code. Version 1.8.1 is the latest stable version so we will use that one:

mkdir nginx

cd nginx


tar -zxvf nginx-1.8.1.tar.gz

The next thing we will need is the source for Nginx-RTMP:



At this point, we should have a directory named nginx-1.8.1 which contains the Nginx source code, and one named nginx-rtmp-module-master which contains the Nginx-RTMP source code. The next step is to reconfigure the Nginx source to compile with the Nginx-RTMP module:

cd nginx-1.8.1

./configure --with-http_ssl_module --add-module=../nginx-rtmp-module-master

You should see a scroll of text while it is configured,  after which you can make and install nginx:


sudo make install

At this point Nginx will be installed into the /usr/local/nginx directory. To test everything is working let’s fire Nginx up:

sudo /usr/local/nginx/sbin/nginx

If everything is working as expected, you should now get the Nginx test page if you navigate to your server’s IP address in a web browser. To stop Nginx you need to call the program again and give it the stop command:

sudo /usr/local/nginx/sbin/nginx -s stop

Now you will need to add the code to configure the RTMP module. This is done in the default config file which is stored with the other files. I’m going to use nano here, but other text editors are available:

sudo nano /usr/local/nginx/conf/nginx.conf

Go to the end of the file and paste in the following configuration:

rtmp {

    server {

        listen 1935;

        chunk_size 8192;

        application vod {

            play /usr/local/nginx/rtmp;




Save and exit the file. In this file, we’ve told Nginx to listen on port 1935 for RTMP, which is the default port.  We’ve also set it to use a chunk size in transfers of 8192 bits. Next, we’ve created an “application” called vod for video on demand. You can have as many of these as you wish, and name them anything you like. We’ve then told it that the vod application will play files from /usr/local/nginx/rtmp directory. This directory doesn’t actually exist yet, so you will need to create it and place some media into it. Note that Nginx-RTMP can only serve flash flv video and mp4 video.

sudo mkdir /usr/local/nginx/rtmp

The next thing to do is start Nginx again, at which point everything is configured and ready for use:

sudo /usr/local/nginx/sbin/nginx

To test you just need to open a stream from your server.  The easiest method is to use VLC media player. To open this, go to the “Media” menu and then select “Open Network Stream”. A window will open for you where you can enter the URL for your media.

The URL will start with rtmp:// to tell VLC the protocol to use, and then the domain name or IP address of your server. Next will be a slash, then your application name, in our case “vod”, another slash and finally the filename of the file. So as an example:



So there you have it – a simple streaming server using RTMP based on open source components. Happy streaming!