All the next steps where written while being tested on the Linux Debian 9 dedicated server.
Before we begin we have to install sudo
because we'll need it in the next steps, so let's update and upgrade the operating system with the following commands
apt update
apt upgrade
Then to install sudo execute the command
apt install sudo
Once the commands complete, sudo
is installed.
Now if you want to run sudo
as a non-root user, you have to use the following command
usermod -aG sudo USERNAME
Where USERNAME is the name of the user.
To install curl
, just execute the command
sudo apt install curl
To install ufw
, execute the command
sudo apt-get install ufw
In order to install Apache Web Server, install apache2
package
sudo apt install apache2
Now you need to adjust the Firewall
sudo ufw allow 'WWW Full'
This should open both port 80 (normal, unencrypted web traffic) and port 443 (TLS/SSL encrypted traffic)
To verify if apache2 service is running, use this command
sudo systemctl status apache2
To host a website on your domain, first in /var/www
create a new folder with your domain address.
Then in this folder create public
, logs
and crt
folders and in the public
, put the website's files.
In crt
upload your certificate files and logs
leave empty, because it will be used to store website's logs.
Now in the /etc/apache2/sites-available
directory, create a new .conf
file with a name of your domain.
Open the file and paste this:
<VirtualHost *:443>
SSLEngine on
SSLCertificateFile /var/www/YOURDOMAIN/crt/certificate.crt
SSLCertificateKeyFile /var/www/YOURDOMAIN/crt/private.key
SSLCertificateChainFile /var/www/YOURDOMAIN/crt/ca_bundle.crt
ServerName YOURDOMAIN
ServerAdmin webmaster@YOURDOMAIN
DocumentRoot /var/www/YOURDOMAIN/public
ErrorLog /var/www/YOURDOMAIN/logs/error.log
</VirtualHost>
<VirtualHost *:80>
ServerName YOURDOMAIN
DocumentRoot /var/www/YOURDOMAIN/public
Redirect permanent / https://YOURDOMAIN
</VirtualHost>
When you finish configuring, execute the command to activate the site
sudo a2ensite YOURDOMAIN.conf
Then use the commands to validate the changes and restart apache2 service
sudo apache2ctl configtest
sudo systemctl restart apache2
If you are getting a message Invalid command 'SSLEngine', perhaps misspelled or defined by a module not included in the server configuration, use this command to enable the SSLEngine module and then restart apache2 to apply changes
sudo a2enmod ssl
To install PHP latest stable version, run the command
sudo apt install php
Install sudo
https://www.techrepublic.com/article/how-to-install-sudo-on-a-debian-minimal-server/
Install curl
https://www.cyberciti.biz/faq/howto-install-curl-command-on-debian-linux-using-apt-get/
Install ufw
https://www.digitalocean.com/community/tutorials/how-to-setup-a-firewall-with-ufw-on-an-ubuntu-and-debian-cloud-server
Install apache2
https://www.digitalocean.com/community/tutorials/how-to-install-the-apache-web-server-on-debian-9
Install PHP https://tecadmin.net/install-php-debian-9-stretch/