# Update package lists
sudo apt update
# Install Apache (provides 2.4.58 or latest in repos)
sudo apt install apache2
# (Recommended) Update all packages
sudo apt upgrade
Apache should start automatically after installation.
# Show version
apache2 -v
# or
apachectl -v
# Check service status
sudo systemctl status apache2
# Restart (if needed)
sudo systemctl restart apache2
# Enable on boot (usually already enabled)
sudo systemctl enable apache2
Expected output example: Server version: Apache/2.4.58 (Ubuntu)
Open your browser and visit:
http://localhost → if you're on the same machinehttp://your-server-ip-address → from another computerYou should see the Apache2 Ubuntu Default Page.
sudo ufw allow 'Apache'
sudo ufw reload
Verify with: sudo ufw status
/var/www/html//etc/apache2/apache2.conf/etc/apache2/sites-enabled//etc/apache2/sites-available/000-default.confsudo apt install php libapache2-mod-php php-mysql
sudo systemctl restart apache2
Quick test: create /var/www/html/info.php with <?php phpinfo(); ?> and visit http://localhost/info.php
Generally not recommended for production servers because:
Alternatives (only if you really need it):
ondrej/apache2