One place for hosting & domains

      Quickstart

      How To Install the Apache Web Server on Ubuntu 18.04 [Quickstart]


      Introduction

      The Apache HTTP server is the most widely-used web server in the world. It provides many powerful features, including dynamically loadable modules, robust media support, and extensive integration with other popular software.

      In this guide, we’ll explain how to install an Apache web server on your Ubuntu 18.04 server. For a more detailed version of this tutorial, please refer to How To Install the Apache Web Server on Ubuntu 18.04.

      Prerequisites

      Before you begin this guide, you should have the following:

      • An Ubuntu 18.04 server and a regular, non-root user with sudo privileges. Additionally, you will need to enable a basic firewall to block non-essential ports. You can learn how to configure a regular user account and set up a firewall for your server by following our initial server setup guide for Ubuntu 18.04.

      When you have an account available, log in as your non-root user to begin.

      Step 1 — Installing Apache

      Apache is available within Ubuntu’s default software repositories, so you can install it using conventional package management tools.

      Update your local package index:

      Install the apache2 package:

      Step 2 — Adjusting the Firewall

      Check the available ufw application profiles:

      Output

      Available applications: Apache Apache Full Apache Secure OpenSSH

      Let's enable the most restrictive profile that will still allow the traffic you've configured, permitting traffic on port 80 (normal, unencrypted web traffic):

      Verify the change:

      Output

      Status: active To Action From -- ------ ---- OpenSSH ALLOW Anywhere Apache ALLOW Anywhere OpenSSH (v6) ALLOW Anywhere (v6) Apache (v6) ALLOW Anywhere (v6)

      Step 3 — Checking your Web Server

      Check with the systemd init system to make sure the service is running by typing:

      • sudo systemctl status apache2

      Output

      ● apache2.service - The Apache HTTP Server Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled) Drop-In: /lib/systemd/system/apache2.service.d └─apache2-systemd.conf Active: active (running) since Tue 2018-04-24 20:14:39 UTC; 9min ago Main PID: 2583 (apache2) Tasks: 55 (limit: 1153) CGroup: /system.slice/apache2.service ├─2583 /usr/sbin/apache2 -k start ├─2585 /usr/sbin/apache2 -k start └─2586 /usr/sbin/apache2 -k start

      Access the default Apache landing page to confirm that the software is running properly through your IP address:

      http://your_server_ip
      

      You should see the default Ubuntu 18.04 Apache web page:

      Apache default page

      When using the Apache web server, you can use virtual hosts (similar to server blocks in Nginx) to encapsulate configuration details and host more than one domain from a single server. We will set up a domain called example.com, but you should replace this with your own domain name. To learn more about setting up a domain name with DigitalOcean, see our introduction to DigitalOcean DNS.

      Create the directory for example.com, using the -p flag to create any necessary parent directories:

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

      Assign ownership of the directory:

      • sudo chown -R $USER:$USER /var/www/example.com/html

      The permissions of your web roots should be correct if you haven't modified your unmask value, but you can make sure by typing:

      • sudo chmod -R 755 /var/www/example.com

      Create a sample index.html page using nano or your favorite editor:

      • nano /var/www/example.com/html/index.html

      Inside, add the following sample HTML:

      /var/www/example.com/html/index.html

      <html>
          <head>
              <title>Welcome to Example.com!</title>
          </head>
          <body>
              <h1>Success!  The example.com server block is working!</h1>
          </body>
      </html>
      

      Save and close the file when you are finished.

      Make a new virtual host file at /etc/apache2/sites-available/example.com.conf:

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

      Paste in the following configuration block, updated for our new directory and domain name:

      /etc/apache2/sites-available/example.com.conf

      <VirtualHost *:80>
          ServerAdmin [email protected]
          ServerName example.com
          ServerAlias www.example.com
          DocumentRoot /var/www/example.com/html
          ErrorLog ${APACHE_LOG_DIR}/error.log
          CustomLog ${APACHE_LOG_DIR}/access.log combined
      </VirtualHost>
      

      Save and close the file when you are finished.

      Enable the file with a2ensite:

      • sudo a2ensite example.com.conf

      Disable the default site defined in 000-default.conf:

      • sudo a2dissite 000-default.conf

      Test for configuration errors:

      • sudo apache2ctl configtest

      You should see the following output:

      Output

      Syntax OK

      Restart Apache to implement your changes:

      • sudo systemctl restart apache2

      Apache should now be serving your domain name. You can test this by navigating to http://example.com, where you should see something like this:

      Apache virtual host example

      Conclusion

      Now that you have your web server installed, you have many options for the type of content to serve and the technologies you want to use to create a richer experience.

      If you'd like to build out a more complete application stack, check out this article on how to configure a LAMP stack on Ubuntu 18.04.



      Source link

      How To Install Nginx on Ubuntu 18.04 [Quickstart]


      Introduction

      Nginx is one of the most popular web servers in the world and is responsible for hosting some of the largest and highest-traffic sites on the internet. It is more resource-friendly than Apache in most cases and can be used as a web server or reverse proxy.

      In this guide, we’ll explain how to install Nginx on your Ubuntu 18.04 server. For a more detailed version of this tutorial, please refer to How To Install Nginx on Ubuntu 18.04.

      Prerequisites

      Before you begin this guide, you should have the following:

      • An Ubuntu 18.04 server and a regular, non-root user with sudo privileges. Additionally, you will need to enable a basic firewall to block non-essential ports. You can learn how to configure a regular user account and set up a firewall by following our initial server setup guide for Ubuntu 18.04.

      When you have an account available, log in as your non-root user to begin.

      Step 1 – Installing Nginx

      Because Nginx is available in Ubuntu’s default repositories, you can install it using the apt packaging system.

      Update your local package index:

      Install Nginx:

      Step 2 – Adjusting the Firewall

      Check the available ufw application profiles:

      Output

      Available applications: Nginx Full Nginx HTTP Nginx HTTPS OpenSSH

      Let's enable the most restrictive profile that will still allow the traffic you've configured, permitting traffic on port 80:

      • sudo ufw allow 'Nginx HTTP'

      Verify the change:

      Output

      Status: active To Action From -- ------ ---- OpenSSH ALLOW Anywhere Nginx HTTP ALLOW Anywhere OpenSSH (v6) ALLOW Anywhere (v6) Nginx HTTP (v6) ALLOW Anywhere (v6)

      Step 3 – Checking your Web Server

      Check with the systemd init system to make sure the service is running by typing:

      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-04-20 16:08:19 UTC; 3 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

      Access the default Nginx landing page to confirm that the software is running properly through your IP address:

      http://your_server_ip
      

      You should see the default Nginx landing page:

      Nginx default page

      When using the Nginx web server, you can use server blocks (similar to virtual hosts in Apache) to encapsulate configuration details and host more than one domain from a single server. We will set up a domain called example.com, but you should replace this with your own domain name. To learn more about setting up a domain name with DigitalOcean, see our introduction to DigitalOcean DNS.

      Create the directory for example.com, using the -p flag to create any necessary parent directories:

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

      Assign ownership of the directory:

      • sudo chown -R $USER:$USER /var/www/example.com/html

      The permissions of your web roots should be correct if you haven't modified your umask value, but you can make sure by typing:

      • sudo chmod -R 755 /var/www/example.com

      Create a sample index.html page using nano or your favorite editor:

      • nano /var/www/example.com/html/index.html

      Inside, add the following sample HTML:

      /var/www/example.com/html/index.html

      <html>
          <head>
              <title>Welcome to Example.com!</title>
          </head>
          <body>
              <h1>Success!  The example.com server block is working!</h1>
          </body>
      </html>
      

      Save and close the file when you are finished.

      Make a new server block at /etc/nginx/sites-available/example.com:

      • sudo nano /etc/nginx/sites-available/example.com

      Paste in the following configuration block, updated for our new directory and domain name:

      /etc/nginx/sites-available/example.com

      server {
              listen 80;
              listen [::]:80;
      
              root /var/www/example.com/html;
              index index.html index.htm index.nginx-debian.html;
      
              server_name example.com www.example.com;
      
              location / {
                      try_files $uri $uri/ =404;
              }
      }
      

      Save and close the file when you are finished.

      Enable the file by creating a link from it to the sites-enabled directory:

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

      Two server blocks are now enabled and configured to respond to requests based on their listen and server_name directives:

      • example.com: Will respond to requests for example.com and www.example.com.
      • default: Will respond to any requests on port 80 that do not match the other two blocks.

      To avoid a possible hash bucket memory problem that can arise from adding additional server names, it is necessary to adjust a single value in the /etc/nginx/nginx.conf file. Open the file:

      • sudo nano /etc/nginx/nginx.conf

      Find the server_names_hash_bucket_size directive and remove the # symbol to uncomment the line:

      /etc/nginx/nginx.conf

      ...
      http {
          ...
          server_names_hash_bucket_size 64;
          ...
      }
      ...
      

      Test for syntax errors:

      Restart Nginx to enable your changes:

      • sudo systemctl restart nginx

      Nginx should now be serving your domain name. You can test this by navigating to http://example.com, where you should see something like this:

      Nginx first server block

      Conclusion

      Now that you have your web server installed, you have many options for the type of content to serve and the technologies you want to use to create a richer experience.

      If you'd like to build out a more complete application stack, check out this article on how to configure a LEMP stack on Ubuntu 18.04.



      Source link