<\/span><\/h2>\n\n\n\nLog in to your Ubuntu 20.04 VPS with SSH as a root user or as a regular user with sudo privileges<\/p>\n\n\n\n
ssh master@IP_Address -p Port_number<\/pre>\n\n\n\nRemember to replace “master” with a user that has sudo privileges, or root. Additionally, replace “IP_Address” and “Port_Number” with your server\u2019s IP address and SSH port.<\/p>\n\n\n\n
You can check whether you have the proper Ubuntu version installed on your server with the following command:<\/p>\n\n\n\n
$ lsb_release -a<\/pre>\n\n\n\nYou should get this output:<\/p>\n\n\n\n
No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 20.04.3 LTS Release: 20.04 Codename: focal<\/pre>\n\n\n\n <\/figure>\n\n\n\nNow, run the following command to update all installed packages to the latest available version.<\/p>\n\n\n\n
$ sudo apt update && sudo apt upgrade<\/pre>\n\n\n\n<\/span>Step 2. Install Apache<\/span><\/h2>\n\n\n\nApache is considered as the most widely-used and user-friendly web server software. It is fast, secure, reliable, and can be easily customized depending on your needs.<\/p>\n\n\n\n
To install Apache on the server, run the following command:<\/p>\n\n\n\n
$ sudo apt install apache2<\/pre>\n\n\n\nAfter the installation is completed, you should enable Apache to start automatically upon server boot with:<\/p>\n\n\n\n
$ sudo systemctl --now enable apache2<\/pre>\n\n\n\nYou can also check the status of your Apache service with the following command<\/p>\n\n\n\n
$ sudo systemctl status apache2<\/pre>\n\n\n\n <\/figure>\n\n\n\nor, open your web browser and navigate to http:\/\/123.123.123.123<\/code>, replace 123.123.123.123 with your Ubuntu 20.04 actual IP address. You should see a default page as shown in the picture below.<\/p>\n\n\n\n <\/figure>\n\n\n\nCreate virtualhost<\/h3>\n\n\n\n Let’s create an apache virtual host, you can change the file name and the domain name to reflect your actual domain name.<\/p>\n\n\n\n
$ sudo nano \/etc\/apache2\/sites-available\/domain1.com.conf<\/pre>\n\n\n\nThe add the following to the file.<\/p>\n\n\n\n
$ sudo mkdir -p \/var\/www\/html\/domain1.com\/web <\/pre>\n\n\n\n<VirtualHost *:80>\n\nServerAdmin admin@domain1.com\nServerName domain1.com\nServerAlias www.domain1.com\nDocumentRoot \/var\/www\/html\/domain1.com\/web\n\nErrorLog ${APACHE_LOG_DIR}\/domain1.com_error.log\nCustomLog ${APACHE_LOG_DIR}\/domain2.com_access.log combined\n\n<Directory \/var\/www\/html\/domain1.com\/web>\nAllowOverride All\nRequire all granted\n<\/Directory>\n\n<\/VirtualHost><\/pre>\n\n\n\nSave the file then exit, then change the domain’s webroot permission with this command:<\/p>\n\n\n\n
$ sudo chown -R www-data. \/var\/www\/html\/domain1.com\/web<\/pre>\n\n\n\nContao requires us to activate the apache mod_rewrite. In Ubuntu, mod_rewrite is not enabled by default, we need to run this command below to enable it.<\/p>\n\n\n\n
$ sudo a2enmod rewrite<\/pre>\n\n\n\nRemember, always check your Apache configuration to make sure there is no type or other issues by running this command prior to restarting it.<\/p>\n\n\n\n
$ sudo apache2ctl -t<\/pre>\n\n\n\n$ sudo systemctl restart apache2<\/pre>\n\n\n\n