Categories
Linux Ubuntu

Host a website on LAMP Ubuntu 20.04

You can install LAMP Server with one command, later you only need to configure it, please follow the tutorial below to configure.

//to install LAMP server with one command
sudo tasksel install lamp-server
Step 1: Install Apache
sudo apt update && sudo apt upgrade
sudo apt install apache2
Configure Apache
sudo nano /etc/apache2/apache2.conf
KeepAlive Off

   ...

   <IfModule mpm_prefork_module>
       StartServers 4
       MinSpareServers 20
       MaxSpareServers 40
       MaxClients 200
       MaxRequestsPerChild 4500
   </IfModule>
Restart Apache
sudo systemctl restart apache2
Step 2: Host Website

Disable the default Apache virtual host

sudo a2dissite *default

Create folder for your website

sudo mkdir -p /var/www/html/example.com/{public_html,log,backups}

Configure Virtual host

sudo nano /etc/apache2/sites-available/example.com.conf
# domain: example.com
# public: /var/www/html/example.com/public_html/

<VirtualHost *:80>
  # Admin email, Server Name (domain name), and any aliases
  ServerAdmin webmaster@example.com
  ServerName  example.com
  ServerAlias www.example.com

  # Index file and Document Root (where the public files are located)
  DirectoryIndex index.html index.php
  DocumentRoot /var/www/html/example.com/public_html
  # Log file locations
  LogLevel warn
  ErrorLog  /var/www/html/example.com/log/error.log
  CustomLog /var/www/html/example.com/log/access.log combined
</VirtualHost>

Enable your website

sudo a2ensite example.com.conf

Reload

sudo systemctl reload apache2

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.