> For the complete documentation index, see [llms.txt](https://spacecore.gitbook.io/wiki/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://spacecore.gitbook.io/wiki/ua/web-development/install-apache2.md).

# Встановлення Apache2

Apache - це кросплатформенне програмне забезпечення, яке підтримує операційні системи Linux, BSD, Mac OS, Microsoft Windows, Novell NetWare та BeOS.

## **Встановлення Apache2:**

Щоб встановити Apache2 на VDS, необхідно зареєструвати:

```
apt-get install apache2
```

## **Налаштування Apache2:**

Щоб налаштувати Apache2, перейдіть до /etc/apache2/sites-available та створіть файл за зразком 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>
```

Увімкнення сайту. Назва місця розташування site.conf повинна відповідати імені створеного вами конфігураційного файлу:

```
a2ensite site.conf
```

Якщо потрібно відключити сайт, замість site.conf повинно бути ім'я конфігураційного файлу:

```
a2dissite site.conf
```

Перезапуск apache2:

```
service apache2 reload
```

### **Підключення PHP до Apache2:**

Щоб Apache правильно відображав файли php, потрібно встановити пакет:

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

Перезапуск apache2:

```
service apache2 reload
```

## **Увімкнення rewrite:**

{% hint style="danger" %}
Без цієї опції 70% CMS для вебсайтів не працюватимуть.
{% endhint %}

Більшість сайтів містять файл .htaccess, який необхідно зареєструвати для його роботи:

```
a2enmod rewrite
```

Перезапуск apache2:

```
service apache2 reload
```

### **Увімкнення SSL:**

{% hint style="info" %}
SSL-з'єднання не є обов'язковим, воно здійснюється за наявності та за вашим бажанням.
{% endhint %}

Потрібно увімкнути модуль, який відповідає за SSL:

```
a2enmod ssl
```

Створіть інший конфігураційний файл у /etc/apache2/sites-available, який відповідатиме за SSL, наприклад 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 %}

Перезапуск apache2:

```
service apache2 reload
```

## **Перевірка на nginx:**

Якщо apache2 встановлено разом з nginx, вони будуть конфліктувати через порт 80. Тому потрібно видалити один з вебсерверів. Перевірте, чи встановлено nginx:

```
service nginx status
```

{% hint style="info" %}
Якщо не видно великого повідомлення з інформацією, то він не встановлений.
{% endhint %}

Якщо nginx встановлений, потрібно його видалити:

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

## **Видалення Apache2:**

Щоб видалити Apache2, використовуйте:

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


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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/ua/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.
