Methods of payment Abuse

Installing Apache2

15.01.2024, 22:02

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.

How to install?

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).

Before installing Apache2, make sure there is no nginx on the server!

Now let's move on to the server configuration process.

How to properly configure Apache2

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

Connecting PHP to Apache2

To use php files, let's install a special package:

apt-get install libapache2-mod-php -y

Reboot Apache2:

service apache2 reload

Enabling rewrite (overwriting files)

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

Enable SSL (encryption protocol)

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.