# Installing Apache2

Apache is a cross-platform software that supports Linux, BSD, Mac OS, Microsoft Windows, Novell NetWare, and BeOS operating systems.

## Installation Apache2:

To install **Apache2** on **VDS**, you must register:

```
apt-get install apache2
```

## Customization Apache2:

To configure **Apache2**, go to /etc/apache2/sites-available and create a file modeled on site.conf:

```
<VirtualHost *:80>
        ServerName spacecore.pro # Specify the site domain
        ServerAdmin admin@spacecore.pro # Your email address
        DocumentRoot /var/www/html # The path to the site folder

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
```

Turning on the site, the site.conf location should be the name of the config that you created:

```
a2ensite site.conf
```

If you need to **disable the site**, the name of the config should be instead of site.conf:

```
a2dissite site.conf
```

Rebooting **apache2**:

```
service apache2 reload
```

### Connecting PHP to Apache2:

In order for **Apache** to display **php** files correctly, you need to install the package:

```
apt-get install libapache2-mod-php -y
```

Rebooting **apache2**:

```
service apache2 reload
```

### Enabling rewrite:

{% hint style="danger" %}
Without this option, 70% of CMS for websites will not work.
{% endhint %}

Most sites contain a file.**htaccess** must be registered for its operation:

```
a2enmod rewrite
```

Rebooting **apache2**:

```
service apache2 reload
```

### Enabling SSL:

{% hint style="info" %}
**SSL** connection is not required, it is carried out if it is available and you wish.
{% endhint %}

You need to enable the module that is responsible for **SSL**:

```
a2enmod ssl
```

Creating another config in /etc/apache2/sites-available, it will be responsible for **SSL**, for example site-ssl.conf:

{% code title="site-ssl.conf" %}

```
<VirtualHost *:443>
        ServerName spacecore.pro # Specify the site domain
        ServerAdmin admin@spacecore.pro # Your email address
        DocumentRoot /var/www/html # The path to the site folder
        
        SSLEngine on
        SSLCertificateFile /path/to/your_domain_name.pem # The path to the public certificate
        SSLCertificateKeyFile /path/to/your_private.key # The path to the private certificate

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
```

{% endcode %}

Rebooting **apache2**:

```
service apache2 reload
```

## Check на nginx:

If **apache2** is installed with nginx, then they will conflict due to port - 80. So you need to delete one of the **web servers**. Check if nginx is installed:

```
service nginx status
```

{% hint style="info" %}
If a huge message with information is not visible, then it is not installed.
{% endhint %}

If **nginx** is installed, you need to delete it:

```
apt-get remove --purge nginx* -y
```

## Removal Apache2

To remove **Apache2**, use:

```
apt-get remove --purge apache2* -y
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://spacecore.gitbook.io/wiki/en/web-development/install-apache2.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
