Installing Apache2

Apache is cross-platform server software that supports Linux, BSD, Mac OS, Microsoft Windows, Novell NetWare, BeOS.

Before installing Apache2, make sure nginx is not present on the server!

Installing Apache2

Enter the Apache2 installation command:

apt-get install apache2

For centOS use the command yum install httpd (second name for Apache2)

Configuring Apache2

Go to sFTP at address /etc/apache2/sites-available and create a file server_name.conf (name can be anything), containing the following text with your data:

<VirtualHost *:80>
        ServerName aeza.net # Specify the site domain
        ServerAdmin admin@aeza.net # Your email
        DocumentRoot /var/www/html # Path to the site folder
        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 # specify the name of your site file

To disable the site, use the following command:

a2dissite server_name.conf # specify the name of your site file

For reload, use the following command:

service apache2 reload

Connecting PHP to Apache2

To use php files, install a special package:

apt-get install libapache2-mod-php -y

Reload Apache2:

service apache2 reload

Enabling rewrite (file rewriting)

Without this setting, a significant part of site CMS may not work.

Enter settings for the .htaccess file:

a2enmod rewrite

Reload Apache2:

service apache2 reload

Enabling SSL (encryption protocol)

Is an optional item that increases trust in your site

Enable the SSL encryption module:

a2enmod ssl

Go to sFTP at address /etc/apache2/sites-available and create a new config site_name-ssl.conf:

site_name-ssl.conf
<VirtualHost *:443>
        ServerName aeza.net # Specify the site domain
        ServerAdmin admin@aeza.net # Your email
        DocumentRoot /var/www/html # Path to the site folder

        SSLEngine on
        SSLCertificateFile /path/to/your_domain_name.pem # Path to the public certificate
        SSLCertificateKeyFile /path/to/your_private.key # Path to the private certificate

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Reload Apache2:

service apache2 reload

Checking for Nginx

When using Apache2 with Nginx, they will not be able to work correctly, conflicting for port - 80. Therefore, it is important to remove one of the web server software.

Check for Nginx:

service nginx status

If you don't see a large message with information, then Nginx is not installed.

To remove Nginx, enter:

apt-get remove --purge nginx* -y

Removing Apache2

To remove Apache2, enter:

apt-get remove --purge apache2* -y

Table of Contents