Installing and Configuring Apache2 on Linux
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:
apt-get install apache2#Configuring Apache2
To configure Apache2, go to /etc/apache2/sites-available and create a file similar to site.conf:
<VirtualHost *:80>
ServerName spacecore.pro # Specify the site domain
ServerAdmin admin@spacecore.pro # Your email address
DocumentRoot /var/www/html # Path to the site directory
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>Enable the site; instead of site.conf, use the name of the configuration file you created:
a2ensite site.confIf you need to disable the site, use the configuration file name instead of site.conf:
a2dissite site.confReload apache2:
service apache2 reload#Connecting PHP to Apache2
For Apache to correctly serve PHP files, you need to install the following package:
apt-get install libapache2-mod-php -yReload apache2:
service apache2 reload#Enabling rewrite
Without this option, about 70% of website CMSs will not work.
Most sites include an .htaccess file; to make it work, run:
a2enmod rewriteReload apache2:
service apache2 reload#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:
a2enmod sslCreate another configuration file in /etc/apache2/sites-available that will handle SSL, for example site-ssl.conf:
<VirtualHost *:443>
ServerName spacecore.pro # Specify the site domain
ServerAdmin admin@spacecore.pro # Your email address
DocumentRoot /var/www/html # Path to the site directory
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 reload#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:
service nginx statusIf you do not see a long status message, it means Nginx is not installed.
If Nginx is installed, you need to remove it:
apt-get remove --purge nginx* -y#Removing Apache2
To remove Apache2, use:
apt-get remove --purge apache2* -yDid not find the answer? We are online 24/7.Contact support