Apache2 quick config

This guide provides an example of how to configure your Apache2 web server for use in the Build on the cloud tutorial. This process assumes the LAMP stack installed through the Marketplace hasn’t been modified.

How long will this take? Approximately 15-20 minutes

Update your DNS, add your domain to your Apache2 web server, and test access to it.

1. Get your public IP

Using Cloud Manager, get the public IP address for your primary Linode instance:

  1. From Cloud Manager, select Linodes.

  2. Locate your primary Linode.

  3. Make note of the IPv4 address listed under Public IP Addresses. You can use the copy function to copy the address.

See our Manage IP addresses for more information on viewing, adding, and configuring different types of IP addresses.

2. Create a DNS entry

Your domain should point to the IP address of your primary Linode instance. To do this, you need to update your DNS with an A record entry. For example, if you were using a domain provider like Google Domains, you would log into your DNS control panel, and add a new custom record:

See our DNS Manager documentation to configure your DNS settings using our free DNS Manager service in Cloud Manager.

3. Update Apache2

Edit your default Apache2 configuration, including Virtual Host, to work with your domain.

  1. In a terminal window, log into your Linode via SSH, replacing USER with your limited sudo username and IP_ADDRESS with the public IPv4 of your instance:

    ssh USER@IP_ADDRESS
  2. Navigate to the default directory Apache2 uses to store website files, /var/www:

    cd /var/www
  3. Create a new directory for your site, using your domain name to make it easy to recognize, and then navigate into it. Replace the example domain docasssociates with your own domain. This tutorial uses docasssociates throughout.

    sudo mkdir docassociates.com
    cd docsassociates.com
  4. Using a text editor like nano, create and open a new index.html file to serve as your site's root page.

    sudo nano index.html
  5. In your text editor, create a simple HTML layout for use. Later, you can optionally overwrite this page with your site's actual index.html home page.

    <html>
      <body>
      <h1>Welcome to Doc Associates!</h1>
      </body>
    </html>
  6. Press Ctrl + X, followed by Y then Enter to save and exit nano.

  7. Navigate to the directory where sites are managed in Apache2:

    cd /etc/apache2/sites-available
  8. Create and open a new configuration file for your domain, replacing docassociates.com with your domain:

    sudo nano docasassociates.com.conf
  9. In your text editor, set up the domain configuration file using the sample below. Update the ServerAdmin value with a valid email address associated with the person serving as your site admin, and replace docsassociates.com with your domain where applicable.

    <VirtualHost *:80>
            ServerAdmin jdoe@docsassociates.com
            DocumentRoot /var/www/docsassociates.com
    
            <Directory /var/www/docsassociates.com>
                Options Indexes FollowSymlinks
                AllowOverride All
                Require all granted
            </Directory>
            
            ErrorLog ${APACHE_LOG_DIR}/error.log
            CustomLog ${APACHE_LOG_DIR}/access.log combined
            
            <IfModule mod_dir.c>
                DirectoryIndex index.html index.php
            </IfModule>
            
    </VirtualHost>
  10. Press Ctrl + X, followed by Y then Enter to save and exit nano.

  11. Activate the site using the config file you just created:

    sudo a2ensite docsassociates.com.conf

    This prompts a message stating that you need to restart Apache2. You don't need do this yet as it's done in the final step.

  12. Run ls to view all of the config files in /sites-available. You may see results similar to the following:

    000-default.conf                                     default-ssl.conf
    192.0.2.49.ip.linodeusercontent.com.conf         docsassociates.com.conf
    192.0.2.49.ip.linodeusercontent.com-le-ssl.conf
  13. Make sure that all the *.conf files are deactivated from Apache2 except for the new one you just created. Run the a2dissite command for each one:

    sudo a2dissite 000-default.conf
    sudo a2dissite default-ssl.conf
    sudo a2dissite 192.0.2.49.ip.linodeusercontent.com.conf
    sudo a2dissite 192.0.2.49.ip.linodeusercontent.com-le-ssl.conf
    📘

    Some of these files may return a message of Site <name> already disabled. This is OK.

  14. Finally, restart Apache2 to apply your updates:

    sudo systemctl reload apache2

4. Test it

Launch a browser, and enter your domain in the search bar. If you did everything correctly, you should see the home page you set up.

A browser screenshot showing a basic index.html home page.
👍

I got a 404

If you don't see your page, it might be because your DNS entry hasn't fully propagated yet. Give it a few minutes, and try again. If it still doesn't work, make sure that you set up your A record entry with the correct domain and IP address for your primary Linode instance.