Цей розділ містить замітки та підказки щодо встановлення Apache 2.x з PHP в
системи Unix.
На даний момент є дві версії Apache 2.x - це 2.2 та 2.4.
Хоча є певні причини для вибору однієї чи іншої версії, але 2.4 є зараз
найновішою та рекомендованою. Тим не менш, наведені тут інструкції мають
працювати для обох версій. Варто зазначити, що Apache httpd 2.2 офіційно не
підтримується і для нього не випускаються нові розробки чи виправлення.
-
Завантаживши HTTP-сервер Apache, його необхідно розпакувати:
-
Аналогічно, неодхідно розпаковати файли з початковим кодом PHP:
-
Далі потрібно зібрати та встановити Apache. Докладніші рекоментації є на
сайті Apache.
-
Тепер Apache 2.x.NN доступний за адресою /usr/local/apache2, зі
встановленим стандартним модулем MPM prefork та конфігурацією, яка
дозволяє додавати інші потрібні модулі. Щоб перевірити інсталяцію,
використовується звичайна процедура для старту сервера Apache, наприклад:
далі треба зупинити сервер, щоб перейти до встановлення PHP:
-
Тепер конфігуруємо та збираємо PHP. Наприклад, визначаємо які саме
розширення будуть включені в PHP. Щоб побачити список доступних
параметрів, запускаємо ./configure --help. В даному
прикладі виконується проста конфігурація Apache 2 з підтримкою MySQL.
Якщо Apache було зібрано вручну, як описано вище, в наступному прикладі
шлях буде відповідати розташуванню apxs, але якщо Apache встановлювався
по-іншому, то потрібно змінити шлях до apxs. Варто зауважити, що деякі
дистрибутиви можуть перейменувати apxs в apxs2.
Для зміни конфігурації після інсталяції, потрібно запустити заново кроки:
configure, make та make install. Після цього перезапустити Apache, щоб
зміни були застосовані. Перекомпільовувати Apache не потрібно.
Варто зауважити, що якщо не сказано іншого, то 'make install' буде також
встановлювати PEAR, PHP CLI, певні сервіси PHP, такі як phpize та інше.
-
Встановлення php.ini.
Можна редагувати файл .ini, додаючи потрібні опції PHP. Для розміщення
php.ini в іншому місці, використовується опція
--with-config-file-path=/some/path на 5-му кроці.
Якщо буде обрано php.ini-production, краще прочитати список відмінностей
між файлами .ini, щоб розуміти як це вплине на поведінку PHP.
-
Відредагуємо httpd.conf, щоб завантажувався модуль PHP. Шлях, який
зазначено праворуч від запису LoadModule, повинен вказувати на
розташування модуля PHP у системі. Команда make
install, про яку тут згадувалось раніше, повинна вже була
зробити це, але краще перевірити ще раз.
-
Скажемо Apache, щоб обробляв розширення .php через PHP. Замість того, щоб
використовувати лише директиву Apache AddType, ми хочемо уникнути
потенційної небезпеки завантаження та створення файлів, таких як
exploit.php.jpg, які будуть оброблятись через PHP. Використовуючи цей
приклад, можна додати будь-яке закінчення (і не одне), яке буде
оброблятись через PHP. Ми вказали .php лише для прикладу.
Або ж, якщо ми хочемо дозволити щоб файли .php, .php2, .php3, .php4, .php5,
.php6, та .phtml оброблялись через PHP, але ніякі інші, ми пишемо так:
Або щоб дозволити файли .phps обробляти через php source filter, та
показувати їх вміст з підсвічуванням синтаксису, використовується таке:
Можна використовувати модуль mod_rewrite, щоб дозволити показувати
початковий код з підсвічуванням синтаксису в файлах з розширенням .php,
без необхідності їх переназивати чи копіювати до файлів .phps:
Не слід вмикати php source filter на виробничих системах, де він може
розкрити конфіденційну або іншу важливу інформацію, розміщену в
початковому коді.
-
Стандартну процедура запуску сервер Apache:
АБО:
Дотримуючись зазначених вище кроків, ми запустимо вебсервер Apache2 з
підтримкою PHP як модуля SAPI
. Звичайно, є значно більше
параметрів, доступних для Apache та PHP. Більше інформації можна отримати
ввівши в консолі ./configure --help в їхніх кореневих
теках.
Не варто бездумно використовувати цю опцію, а тільки, якщо відомо про всі
наслідки такого рішення. В документації для Apache стосовно
» модулів MPM значно детальніше
розкрита ця тема.