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:
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.conf
Â
If you need to disable the site, use the configuration file name instead of site.conf:
a2dissite site.conf
Â
Reload 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 -y
Â
Reload apache2:
service apache2 reload
Without this option, about 70% of website CMSs will not work.
Most sites include an .htaccess file; to make it work, run:
a2enmod rewrite
Â
Reload apache2:
service apache2 reload
Enabling SSL:
You need to enable the module that is responsible for SSL:
a2enmod ssl
Â
Create 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 status
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* -y
Â








