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:
-
From Cloud Manager, select Linodes.
-
Locate your primary Linode.
-
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.
-
In a terminal window, log into your Linode via SSH, replacing
USERwith your limited sudo username andIP_ADDRESSwith the public IPv4 of your instance:ssh USER@IP_ADDRESS -
Navigate to the default directory Apache2 uses to store website files,
/var/www:cd /var/www -
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
docasssociateswith your own domain. This tutorial usesdocasssociatesthroughout.sudo mkdir docassociates.com cd docsassociates.com -
Using a text editor like nano, create and open a new
index.htmlfile to serve as your site's root page.sudo nano index.html -
In your text editor, create a simple HTML layout for use. Later, you can optionally overwrite this page with your site's actual
index.htmlhome page.<html> <body> <h1>Welcome to Doc Associates!</h1> </body> </html> -
Press Ctrl + X, followed by Y then Enter to save and exit nano.
-
Navigate to the directory where sites are managed in Apache2:
cd /etc/apache2/sites-available -
Create and open a new configuration file for your domain, replacing
docassociates.comwith your domain:sudo nano docasassociates.com.conf -
In your text editor, set up the domain configuration file using the sample below. Update the
ServerAdminvalue with a valid email address associated with the person serving as your site admin, and replacedocsassociates.comwith 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> -
Press Ctrl + X, followed by Y then Enter to save and exit nano.
-
Activate the site using the config file you just created:
sudo a2ensite docsassociates.com.confThis 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.
-
Run
lsto 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 -
Make sure that all the
*.conffiles are deactivated from Apache2 except for the new one you just created. Run thea2dissitecommand 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.confSome of these files may return a message of
Site <name> already disabled. This is OK. -
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.
I got a 404If 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
Arecord entry with the correct domain and IP address for your primary Linode instance.
Updated 17 days ago
