Installing Apache2
On this page
Installing Apache2Installing Apache2:Configuring Apache2:Connecting PHP to Apache2:Enabling Rewrite:Enabling SSL:Checking for Nginx:Removing Apache2Installing Apache2
Apache is cross-platform software that supports operating systems such as Linux, BSD, Mac OS, Microsoft Windows, Novell NetWare, and BeOS.
Before installing Apache2, make sure that nginx is not present on the server!
Installing Apache2:
To install Apache2 on a VDS, you need to execute:
apt-get install apache2Configuring Apache2:
To configure Apache2, navigate to /etc/apache2/sites-available and create a file following the example of site.conf:
<VirtualHost *:80>
ServerName site.com # Specify the site's domain
ServerAdmin admin@site.com # Your email
DocumentRoot /var/www/html # Path to the website folder
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>Enable the site, where site.conf should be the name of the config you created:
a2ensite site.confIf you need to disable a site, replace site.conf with the config name:
a2dissite site.confReload Apache2:
service apache2 reloadConnecting PHP to Apache2:
To ensure Apache can correctly display PHP files, you need to install the package:
apt-get install libapache2-mod-php -yReload Apache2:
service apache2 reloadEnabling Rewrite:
Without this option, 70% of CMS for websites won't work. Most websites contain a .htaccess file, and to make it work, you need to enable rewrite:
a2enmod rewriteReload Apache2:
service apache2 reloadEnabling SSL:
Enabling SSL is optional and is done if you have an SSL certificate and want to use it. You need to enable the module responsible for SSL:
a2enmod sslCreate another config file in /etc/apache2/sites-available that will handle SSL, for example, site-ssl.conf:
<VirtualHost *:443>
ServerName site.com # Specify the site's domain
ServerAdmin admin@site.com # Your email
DocumentRoot /var/www/html # Path to the website 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 key
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>Reload Apache2:
service apache2 reloadChecking for Nginx:
If you install Apache2 alongside Nginx, they will conflict due to port 80. So, you need to remove one of the web servers. Check if Nginx is installed:
service nginx statusIf you don't see a large message with information, it means Nginx is not installed.
If Nginx is installed, you need to remove it:
apt-get remove --purge nginx* -yRemoving Apache2
To remove Apache2, use:
apt-get remove --purge apache2* -y