Get a VPS server with a 15% discount
Sale ends in
00Days
:
00Hours
:
00Minutes
:
00Seconds

Installing Apache2

Apache is cross-platform software and supports the Linux, BSD, macOS, Microsoft Windows, Novell NetWare and BeOS operating systems.

 
 

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
 
Enabling rewrite:

 

Most sites include an .htaccess file; to make it work, run:

a2enmod rewrite

 

Reload 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 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 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* -y

 

Â