How to setup and deploy a website on Ubuntu Server 16.04/18.04 and Install Free SSL Certificates

Author

By

Date
Reading time

4 Minutes Read

How to setup and deploy a website on Ubuntu Server

Before going to set up and deploy a website on any hosting server, you need to register a domain for your website. There is various domain registrar available in the market to register a domain.

For more information, you can visit the below links:

  1. Bluehost
  2. HostGator
  3. GoDaddy
  4. Namecheap

NOTE: To set up and deploy a website on Linux Ubuntu Server, you need to install the following packages: Apache/Nginx

Note: In order to run below commands to set up and deploy a website, you need root access to the server.

Let’s Begin to set up a website “example.com”

Step 1:
First, create example.com.conf file on below location:

				
					/etc/apache2/sites-available

				
			

Step 2:
To create/edit the above file, please execute below command:

				
					$ sudo nano /etc/apache2/sites-available/example.com.conf

				
			
Step 3:
Paste below content in this file:
				
					<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/example.com
        ServerName example.com
        ServerAlias www.example.com
        Redirect permanent "/" "https://example.com/"

        <Directory /var/www/example.com>
              AllowOverride All
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
</VirtualHost>
				
			
Step 4:
To active example.com site, please execute below command:
				
					$ sudo a2ensite example.com.conf

				
			
Restart web server:
				
					$ sudo service apache2 restart

				
			

ZeroSSL Free SSL Certificates

NOTE: Please follow the instrucions to generate SSL Certificates on above URL.

From the above URL, you will get following files:
example.com-csr.csr

example.com-crt.crt
example.com-key.key

Now, you need to put following files on below location:
example.com-crt.crt
example.com-key.key

Location:
/etc/ssl/example.com

Step 2:
First, create example.com-ssl.conf file on below location

				
					/etc/apache2/sites-available

				
			
Step 3:
To create/edit above file, please execute below command:
				
					$ sudo nano /etc/apache2/sites-available/example.com-ssl.con

				
			

Step 4:
Paste below content in this file:

				
					<IfModule mod_ssl.c>
        <VirtualHost _default_:443>
                ServerAdmin webmaster@example.com
                ServerName example.com
                ServerAlias www.example.com
                #Redirect permanent "/" "https://example.com/"

                DocumentRoot /var/www/example.com

                # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
                # error, crit, alert, emerg.
                # It is also possible to configure the loglevel for particular
                # modules, e.g.
                #LogLevel info ssl:warn

                ErrorLog ${APACHE_LOG_DIR}/error.log
                CustomLog ${APACHE_LOG_DIR}/access.log combined

                # For most configuration files from conf-available/, which are
                # enabled or disabled at a global level, it is possible to
                # include a line for only one particular virtual host. For example the
                # following line enables the CGI configuration for this host only
                # after it has been globally disabled with "a2disconf".
                #Include conf-available/serve-cgi-bin.conf

                #   SSL Engine Switch:
                #   Enable/Disable SSL for this virtual host.
                SSLEngine on

                #   A self-signed (snakeoil) certificate can be created by installing
                #   the ssl-cert package. See
                #   /usr/share/doc/apache2/README.Debian.gz for more info.
                #   If both key and certificate are stored in the same file, only the
                #   SSLCertificateFile directive is needed.
                SSLCertificateFile /etc/ssl/example.com/example.com-crt.crt
                SSLCertificateKeyFile /etc/ssl/example.com/example.com-key.key
                
                #SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire
                <FilesMatch "\.(cgi|shtml|phtml|php)$">
                    SSLOptions +StdEnvVars
                </FilesMatch>
                <Directory /usr/lib/cgi-bin>
                    SSLOptions +StdEnvVars
                </Directory>
        </VirtualHost>
</IfModule>
				
			
Step 5:
To active example.com site, please execute below command:
				
					$ sudo a2ensite example.com-ssl.conf

				
			
Restart web server:
				
					$ sudo service apache2 restart

				
			

Conclusion

This article will help people to set up and deploy a website on Linux machine especially Ubuntu 16.04/18.04 without spending too much time reading many blogs/articles.

If you have suggestions or any question please mention in comment. For more information reach out to EncoreSky.

Related Articles

AI in Cybersecurity : Friend or Foe?

Every day, AI impacts how we live, work, and engage with technology. One of the most promising applications of AI is in the field of Cybersecurity. Cybersecurity involves the protection of…

Computing

Quantum Computing: Opportunities & Risks

Technology has continually surprised us with what it can do. A supercomputer in our pocket was unthinkable a few decades ago. And now, here we are, scrolling, working, and even running…

Face recognition

Face Recognition Systems: From Concept to Innovation

Face recognition system has moved from science fiction to everyday reality. From unlocking smartphones to verifying passengers at airports, it’s becoming a core part of security and convenience worldwide. But how…