Skip to content

Installing Apache2

Warning

Before installing Apache2 make sure the server does not have nginx on it!

Install Apache2

Write the Apache2 installation command:

shell
apt-get install apache2

Information

For centOS, use the command yum install httpd (Apache2's middle name)

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:

apache
<VirtualHost *:80>
        ServerName aeza.net # Specify the domain of the site
        ServerAdmin admin@aeza.net # Your email.
        DocumentRoot /var/www/html # Path to the folder with the site
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

To launch the site, enter the command:

shell
a2ensite server_name.conf # (1)!
  1. specify the file name of your site

To disable the site, use the following command:

shell
a2dissite server_name.conf # (1)!
  1. specify your site's file name

To reboot, use the following command:

shell
service apache2 reload

Connect PHP to Apache2

To use php files, install a special package:

shell
apt-get install libapache2-mod-php -y

Reboot Apache2:

shell
service apache2 reload

Enable rewrite

Warning

Without this setting, a significant portion of CMS sites may not work.

Let's write settings for the .htaccess file:

shell
a2enmod rewrite

Reboot Apache2:

shell
service apache2 reload

Enable SSL (encryption protocol)

Information

This is a non-essential item to increase the credibility of your site.

Enable the SSL encryption module:

shell
a2enmod ssl

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

apache
<VirtualHost *:443>
        ServerName aeza.net # Specify the domain of the site
        ServerAdmin admin@aeza.net # Your email.
        DocumentRoot /var/www/html # The path to the folder with the site.

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

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

Reboot Apache2:

shell
service apache2 reload

Checking for Nginx

Information

When using Apache2 with Nginx, they will not work correctly, conflicting over port - 80. Therefore, it is important to remove one of the Web server's POs.

Let's check for the presence of Nginx:

shell
service nginx status

Information

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

To uninstall Nginx, write:

shell
apt-get remove --purge nginx* -y

Uninstall Apache2

To remove Apache2, write:

shell
apt-get remove --purge apache2* -y

AézaWiki © 2024