Linux - Install Apache
Installation
Install Apache using Ubuntu’s package manager using apt
:
1
2
sudo apt update
sudo apt install apache2
Check and adjust the Firewall rules to allow all web traffic to Apache using ufw
:
1
sudo ufw allow in "Apache Full"
When you check your server’s IP on the browser, you should see a default landing page of Apache.
Configuration
Now lets start setting virtual hosts:
1
2
3
sudo mkdir /var/www/your_domain
sudo chown -R www-data:www-data /var/www/your_domain
sudo chmod -R 755 /var/www/your_domain
Let’s create simple HTML page:
1
sudo vim /var/www/your_domain/index.html
1
2
3
4
5
6
7
8
<html>
<head>
<title>Welcome to Your_domain!</title>
</head>
<body>
<h1>Success! The your_domain server block is working!</h1>
</body>
</html>
Now let’s create a new virtual host file under Apache’s available sites:
1
sudo vim /etc/apache2/sites-available/your_domain.conf
1
2
3
4
5
6
7
8
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName your_domain
ServerAlias www.your_domain
DocumentRoot /var/www/your_domain
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Let’s enable out host file and disable the default Apache landing page:
1
2
sudo a2ensite your_domain.conf
sudo a2dissite 000-default.conf
Verification
Now we can check if the configurations are working properly and restart Apache service for changes to take effect:
1
2
3
4
sudo apache2ctl configtest
Syntax OK
sudo systemctl restart apache2
Finally, when you check your server’s IP on the browser, you should see “The your_domain server block is working!”
.
This post is licensed under CC BY 4.0 by the author.