Apache2 (or Apache HTTP Server) is a free and open source web server that is used for hosting websites. It is one of the most popular web servers in the world and can be installed on various operating systems such as Linux, Windows, macOS and others.
Apache2 supports many protocols including HTTP, HTTPS, FTP and others and can be customized to handle dynamic content such as PHP, Python, Perl and others. Apache2 also has many modules and extensions that allow you to customize it for different tasks and requirements.
Let's spell out the Apache2 installation command:
apt-get install apache2
For centOS, use the command "yum install httpd" (the second name of Apache2).
Now let's move on to the server configuration process.
Go to sFTP at /etc/apache2/sites-available and create a file server_name.conf (the name can be anything) containing the following text with your data:
<VirtualHost *:80>
ServerName # Указать домен сайта
ServerAdmin admin # Ваш email
DocumentRoot /var/www/html # Путь до папки с сайтом
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
To start the site, enter the command:
a2ensite server_name.conf
To disable the site, use the following command:
a2dissite server_name.conf //укажите имя файла вашего сайта
To restart, use the following command:
service apache2 reload
To use php files, let's install a special package:
apt-get install libapache2-mod-php -y
Reboot Apache2:
service apache2 reload
Without this setting, a significant part of CMS sites may not work.
Let's write settings for .htaccess file:
a2enmod rewrite
Reboot Apache2:
service apache2 reload
This is a non-essential item to increase trust in your site
Let's enable the SSL encryption module:
a2enmod ssl
Go via sFTP to /etc/apache2/sites-available
and create a new config site_name-ssl.conf
:
<VirtualHost *:443>
ServerName # Указать домен сайта
ServerAdmin admin # Ваш email
DocumentRoot /var/www/html # Путь до папки с сайтом
SSLEngine on
SSLCertificateFile /path/to/your_domain_name.pem # Путь до публичного сертификата
SSLCertificateKeyFile /path/to/your_private.key # Путь до приватного сертификата
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Reboot Apache2:
service apache2 reload
As you can see, nothing complicated.