$ sudo apt install apache2
$ sudo systemctl status apache2.service
$ sudo ufw allow http
$ http://your_server_ip
Use hostname -I to get your sever ip
$ sudo systemctl start|stop|restart|reload apache2.service
$ sudo systemctl enable apache2.service
Enable Apach to start automatically when server boots.
$ sudo mkdir /var/www/your_domain
$ sudo vim /var/www/your_domain/index.html
<html>
<head>
<title>your_domain</title>
</head>
<body>
<h1>Welcome to your_domain</h1 >
</body>
</html>
$ sudo vim /etc/apache2/sites-available/your_domain.conf
<VirtualHost *:80>
ServerAdmin webadmin@localhost
ServerName your_domain
DocumentRoot /var/www/your_domain
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Use port 443 instead of 80 if you intend to use HTTPS instead of HTTP for the website.
$ sudo apache2ctl configtest
Example Output
Syntax OK
$ sudo a2ensite your_domain.conf
Enable website
$ sudo systemctl restart apache2.service
$ http://your_domain
Check if your website opens.
Other related commands.
$ sudo a2dissite your_domain.conf
Disable website.
$ sudo systemctl disable apache2.service
Disable Apache to start automatically when server boots.