Installing and Configuring Apache2 on Linux
Installing Apache2
Apache is cross-platform software and supports the Linux, BSD, macOS, Microsoft Windows, Novell NetWare and BeOS operating systems.
Before installing Apache2, make sure that nginx is not present on the server!
Installing Apache2:
To install Apache2 on a VDS, run:
Configuring Apache2:
To configure Apache2, go to /etc/apache2/sites-available and create a file similar to site.conf:
Â
Enable the site; instead of site.conf, use the name of the configuration file you created:
Â
If you need to disable the site, use the configuration file name instead of site.conf:
Â
Reload apache2:
Connecting PHP to Apache2:
For Apache to correctly serve PHP files, you need to install the following package:
Â
Reload apache2:
Without this option, about 70% of website CMSs will not work.
Most sites include an .htaccess file; to make it work, run:
Â
Reload apache2:
Enabling SSL:
Enabling SSL is optional and can be done if you have a certificate and want to use HTTPS.
You need to enable the module that is responsible for SSL:
Â
Create another configuration file in /etc/apache2/sites-available that will handle SSL, for example site-ssl.conf:
Â
Reload apache2:
Checking for nginx:
If apache2 is installed together with nginx, they will conflict over port 80. Therefore, one of the web servers must be removed. Check whether nginx is installed:
If you do not see a long status message, it means nginx is not installed.
If nginx is installed, you need to remove it:
Removing Apache2
To remove Apache2, use:
Â