Apache Installation on Ubuntu 24.04
1. Update the package index
Before installing Apache, it is recommended to update your system's package index:
sudo apt updateCopied!
2. Install Apache
Install the Apache package using the following command:
sudo apt install apache2 -yCopied!
3. Verify Apache version
To confirm the installation and check Apache's version:
apachectl -vCopied!
4. Configure the firewall
Allow HTTP connections through the firewall:
sudo ufw allow 80/tcpCopied!
5. Check Apache service status
Ensure that the Apache service is active:
sudo systemctl status apache2Copied!
6. Enable Apache to start at boot
Set Apache to automatically start with the system:
sudo systemctl enable apache2Copied!
7. Access Apache's test page
Open a web browser and go to http://YOUR-IP-ADDRESS
to see Apache's welcome page and confirm the installation was successful.
You can find your IP address using the ifconfig
command:
ifconfigCopied!
8. Create a virtual host
Edit the virtual host configuration file:
sudo nano /etc/apache2/sites-available/website.confCopied!
Add the following content:
<VirtualHost *:80> ServerAdmin webmaster@example.com ServerName example.com DocumentRoot /var/www/html/website DirectoryIndex index.html index.php ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined <Directory /var/www/html/website> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> </VirtualHost>Copied!
Enable the new site:
sudo a2dissite 000-default sudo a2ensite website sudo apachectl configtestCopied!
9. Create the website directory
sudo mkdir -p /var/www/html/websiteCopied!
Create an index.html
file for the site:
sudo nano /var/www/html/website/index.htmlCopied!
Example HTML file content:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Glintu Blog</title> </head> <body> <h1>Welcome to our website</h1> </body> </html>Copied!
10. Adjust permissions and restart Apache
sudo chown -R www-data:www-data /var/www/html/website sudo systemctl restart apache2Copied!