Select Page

Advent

The Apache HTTP server is essentially the most widely-used internet server on the earth. It supplies many robust options, together with dynamically loadable modules, powerful media toughen, and in depth integration with different common instrument.

On this information, we’re going to give an explanation for tips on how to set up an Apache internet server in your Ubuntu 18.04 server. For a extra detailed model of this instructional, please seek advice from How To Install the Apache Web Server on Ubuntu 18.04.

Must haves

Prior to you start this information, you’ll have the next:

  • An Ubuntu 18.04 server and a typical, non-root consumer with sudo privileges. Moreover, it is very important permit a fundamental firewall to dam non-essential ports. You’ll learn to configure a typical consumer account and arrange a firewall in your server by way of following our initial server setup guide for Ubuntu 18.04.

When you’ve got an account accessible, log in as your non-root consumer to start out.

Step 1 — Putting in Apache

Apache is accessible inside of Ubuntu’s default instrument repositories, so you’ll be able to set up it the usage of typical bundle control gear.

Replace your native bundle index:

Set up the apache2 bundle:

Step 2 — Adjusting the Firewall

Test the accessible ufw utility profiles:

Output

To be had packages: Apache Apache Complete Apache Safe OpenSSH

Let’s permit essentially the most restrictive profile that may nonetheless permit the visitors you may have configured, allowing visitors on port 80 (commonplace, unencrypted internet visitors):

Examine the exchange:

Output

Standing: lively To Motion From -- ------ ---- OpenSSH ALLOW Anyplace Apache ALLOW Anyplace OpenSSH (v6) ALLOW Anyplace (v6) Apache (v6) ALLOW Anyplace (v6)

Step 3 — Checking your Internet Server

Test with the systemd init device to verify the provider is working by way of typing:

  • sudo systemctl standing apache2

Output

● apache2.provider - The Apache HTTP Server Loaded: loaded (/lib/systemd/device/apache2.provider; enabled; seller preset: enabled) Drop-In: /lib/systemd/device/apache2.provider.d └─apache2-systemd.conf Energetic: lively (working) since Tue 2018-04-24 20:14:39 UTC; 9min in the past Primary PID: 2583 (apache2) Duties: 55 (restrict: 1153) CGroup: /device.slice/apache2.provider ├─2583 /usr/sbin/apache2 -k get started ├─2585 /usr/sbin/apache2 -k get started └─2586 /usr/sbin/apache2 -k get started

Get right of entry to the default Apache touchdown web page to substantiate that the instrument is working correctly thru your IP cope with:

http://your_server_ip

You will have to see the default Ubuntu 18.04 Apache internet web page:

Apache default page

When the usage of the Apache internet server, you’ll be able to use digital hosts (very similar to server blocks in Nginx) to encapsulate configuration main points and host a couple of area from a unmarried server. We will be able to arrange a site known as instance.com, however you will have to change this with your individual area identify. To be told extra about putting in place a site identify with DigitalOcean, see our introduction to DigitalOcean DNS.

Create the listing for instance.com, the usage of the -p flag to create any important father or mother directories:

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

Assign possession of the listing:

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

The permissions of your internet roots will have to be right kind if you have not changed your unmask price, however you’ll be able to be certain by way of typing:

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

Create a pattern index.html web page the usage of nano or your favourite editor:

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

Within, upload the next pattern HTML:

/var/www/instance.com/html/index.html


    
        Welcome to <span class="highlight">Instance.com</span>!

Good fortune! The instance.com server block is operating!

Save and shut the report when you’re completed.

Make a brand new digital host report at /and so on/apache2/sites-available/instance.com.conf:

  • sudo nano /and so on/apache2/sites-available/instance.com.conf

Paste within the following configuration block, up to date for our new listing and area identify:

/and so on/apache2/sites-available/instance.com.conf


    ServerAdmin admin@instance.com
    ServerName instance.com
    ServerAlias www.instance.com
    DocumentRoot /var/www/instance.com/html
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/get right of entry to.log blended

Save and shut the report when you’re completed.

Permit the report with a2ensite:

  • sudo a2ensite instance.com.conf

Disable the default website online outlined in 000-default.conf:

  • sudo a2dissite 000-default.conf

Take a look at for configuration mistakes:

  • sudo apache2ctl configtest

You will have to see the next output:

Output

Syntax OK

Restart Apache to put in force your adjustments:

  • sudo systemctl restart apache2

Apache will have to now be serving your area identify. You’ll check this by way of navigating to http://instance.com, the place you will have to see one thing like this:

Apache virtual host example

Conclusion

Now that you’ve got your internet server put in, you could have many choices for the kind of content material to serve and the applied sciences you wish to have to make use of to create a richer enjoy.

If you need to construct out a extra whole utility stack, take a look at this newsletter on how to configure a LAMP stack on Ubuntu 18.04.