Как подключить PHP к Apache на Windows
Выбирайте самую последнюю версию, с той битностью, какая у вашего сервера. Т.е. если у вас Apache 64-битный, то PHP также должен быть 64-битным. Всегда выбирайте Thread Safe версию.
Для каждого файла имеется две ссылки:
Выбирайте Zip, поскольку отладочный пакет только для тех, кто действительно знает, зачем он им нужен. Здесь имеется ввиду не отладка PHP-скриптов, а отладка самого интерпретатора PHP.
Настройка PHP в Windows
Настройка выполняется в два этапа:
- подключение PHP к Apache
- изменение настроек самого PHP (какие расширения включены, сколько выделено памяти PHP скриптам и т.д.)
Подключение PHP к Apache
Для подключения PHP к Apache откройте конфигурационный файл веб-сервера, который расположен по следующему пути: Apache24\conf\httpd.conf (в папке сервера, в подпапке conf, файл httpd.conf).
В этот файл добавьте три строки, две из которых нужно откорректировать:
PHPIniDir "C:/путь/до/PHP" AddHandler application/x-httpd-php .php LoadModule php_module "C:/путь/до/PHP/php8apache2_4.dll"
В первой строке вместо C:/путь/до/PHP напишите точный путь до папки, куда вы распаковали файлы PHP. В третьей строке C:/путь/до/PHP/php8apache2_4.dll также откорректируйте путь, указав расположение PHP папки.
К примеру, я распаковал PHP в папку C:/Server/bin/PHP, тогда мои настройки следующие:
PHPIniDir "C:/Server/bin/PHP" AddHandler application/x-httpd-php .php LoadModule php_module "C:/Server/bin/php/php8apache2_4.dll"
Если папка PHP находится в корне диска C, тогда эти строки должны быть такими:
PHPIniDir "C:/PHP" AddHandler application/x-httpd-php .php LoadModule php_module "C:/PHP/php8apache2_4.dll"
Чтобы изменения вступили в силу, перезапустите веб-сервер или компьютер.
Настройка PHP
В папке PHP найдите файл php.ini-development и переименуйте его в php.ini – это нужно сделать обязательно, иначе PHP не будет видеть сделанные настройки.
Открываем файл php.ini любым текстовым редактором, ищем строчку
; extension_dir = "ext"
и заменяем её на
extension_dir = "C:\путь\до\PHP\ext\"
Обратите внимание, что вам нужно скорректировать строку C:\путь\до\PHP\ext\, указав конкретный путь до папки, где размещены файлы PHP.
У PHP (как и у Apache) имеется много расширений. Если вы не знаете, какое расширение для чего нужно, то как минимум два варианта:
- начать изучить предназначение каждого расширения и подключить только те, которые вам действительно нужны;
- подключить самые важные расширения, чтобы любые сайты и движки работали без ошибок.
Чтобы подключить большую часть расширений, найдите группу строк:
;extension=bz2 ;extension=curl ;extension=ffi ;extension=ftp ;extension=fileinfo ;extension=gd ;extension=gettext ;extension=gmp ;extension=intl ;extension=imap ;extension=ldap ;extension=mbstring ;extension=exif ; Must be after mbstring as it depends on it ;extension=mysqli ;extension=oci8_12c ; Use with Oracle Database 12c Instant Client ;extension=odbc ;extension=openssl ;extension=pdo_firebird ;extension=pdo_mysql ;extension=pdo_oci ;extension=pdo_odbc ;extension=pdo_pgsql ;extension=pdo_sqlite ;extension=pgsql ;extension=shmop
и замените её на:
extension=bz2 extension=curl extension=ffi extension=ftp extension=fileinfo extension=gd extension=gettext extension=gmp extension=intl extension=imap extension=ldap extension=mbstring extension=exif ; Must be after mbstring as it depends on it extension=mysqli ;extension=oci8_12c ; Use with Oracle Database 12c Instant Client extension=odbc extension=openssl ;extension=pdo_firebird extension=pdo_mysql ;extension=pdo_oci extension=pdo_odbc extension=pdo_pgsql extension=pdo_sqlite extension=pgsql extension=shmop
теперь раскомментируйте эту группу строк:
;extension=soap ;extension=sockets ;extension=sodium ;extension=sqlite3 ;extension=tidy ;extension=xsl
extension=soap extension=sockets extension=sodium extension=sqlite3 extension=tidy extension=xsl
Мы подключили самые востребованные расширения, чтобы работало как можно больше функций PHP.
Как подключить php 8 к apache windows
This section contains notes and hints specific to Apache 2.x installs of PHP on Microsoft Windows systems.
It is strongly recommended to consult the » Apache Documentation to get have a basic understanding of the Apache 2.x Server. Also consider reading the » Windows specific notes for Apache 2.x before reading on here.
Download the most recent version of » Apache 2.x and a fitting PHP version. Follow the Manual Installation Steps and come back to go on with the integration of PHP and Apache.
There are three ways to set up PHP to work with Apache 2.x on Windows. PHP can be run as a handler, as a CGI, or under FastCGI.
Note: Remember that when adding path values in the Apache configuration files on Windows, all backslashes such as c:\directory\file.ext should be converted to forward slashes: c:/directory/file.ext . A trailing slash may also be necessary for directories.
Installing as an Apache handler
To load the PHP module for Apache 2.x, the following lines in the Apache httpd.conf configuration file must be inserted:
Example #1 PHP and Apache 2.x as handler
# before PHP 8.0.0 the name of the module was php7_module LoadModule php_module "c:/php/php8apache2_4.dll"SetHandler application/x-httpd-php # configure the path to php.ini PHPIniDir "C:/php"
Note: The actual path to PHP must be substituted instead of C:/php/ in the above examples. Make sure that the file referenced in the LoadModule directive is at the specified location. Use php7apache2_4.dll for PHP 7, or php8apache2_4.dll for PHP 8.
Running PHP as CGI
It is strongly recommended to consult the » Apache CGI documentation for a more complete understanding of running CGI on Apache.
To run PHP as CGI, the php-cgi files will need to be placed in a directory designated as a CGI directory using the ScriptAlias directive.
A #! line will need to be placed in the PHP files, which point to the location of the PHP binary:
Example #2 PHP and Apache 2.x as CGI
#!C:/php/php.exe
Warning
A server deployed in CGI mode is open to several possible vulnerabilities. Please read our CGI security section to learn how to defend yourself from such attacks.
Running PHP under FastCGI
Running PHP under FastCGI has a number of advantages over running it as a CGI. Setting it up this way is fairly straightforward:
Obtain mod_fcgid from » https://www.apachelounge.com. Win32 binaries are available for download from that site. Install the module according to the instructions that will come with it.
Configure your web server as shown below, taking care to adjust any paths to reflect how you have installed things on your particular system:
Example #3 Configure Apache to run PHP as FastCGI
LoadModule fcgid_module modules/mod_fcgid.so # Where is your php.ini file? FcgidInitialEnv PHPRC "c:/php"SetHandler fcgid-script FcgidWrapper "c:/php/php-cgi.exe" .php
Files with a .php extension will now be executed by the PHP FastCGI wrapper.
User Contributed Notes 33 notes
9 years ago
Please for the love of god, download the threaded version. I spent over an hour trying to figure out why php5apache2.dll could not be found, and while desperately looking through manuals I went into the php 5 structure and found that it doesn’t exist in the non-threaded version.
This really could use a mention somewhere other than the PHP 5 structure, like the paragraph to the left of the homepage which talks about which PHP version to choose, or this part of the manual which covers Apache. Anywhere but structure, seriously. I would have never guessed to look there.
8 years ago
If you come with an error like this: Wrapper xxxx cannot be accessed: blah blah blah when starting Apache.
You have 3 choices to solve this problem. Any one of them would work.
1. Reinstall your applictions in paths that do not contain spaces.
2. Place a backslash before every space in the path set to the FcgidWrapper directive in httpd.conf, like:
FcgidWrapper «C:/Program\ Files/PHPServer/PHP/php-cgi.exe» .php
3. Use mklink (or junction for windows XP/2003) to create a symbol link to the path of php-cgi.exe’s containing folder.
run cmd.exe and type this command:
mklink /j C:\php\ «C:\Program Files\PHPServer\PHP».
or this command if you are on Windows XP/2003
junction C:\php\ «C:\Program Files\PHPServer\PHP»
Remember this : you need to download junction.exe to use it. Don’t know where to download? Google it.
Then the FcgidWrapper directive should be like this:
FcgidWrapper «C:/php/php-cgi.exe» .php
Don’t forget to change the paths above to your working paths.
12 years ago
Running PHP under FastCGI:
Besides the following in your httpd.conf
LoadModule fcgid_module modules/mod_fcgid.so
FcgidInitialEnv PHPRC «c:/php»
AddHandler fcgid-script .php
FcgidWrapper «c:/php/php-cgi.exe» .php
Remember to add the following to the default block (or virtual host blocks):
8 years ago
With Apache 2.4 in Windows, it seems that PHPIniDir directive must come before LoadModule directive to be used. Also, name of the DLL file seems to be php5apache2_4.dll, not php5apache2.dll.
This configuration in httpd.conf works for me (Apache 2.4.10, PHP 5.6.5):
LoadModule php5_module «c:/php/php5apache2_4.dll»
SetHandler application/x-httpd-php
15 years ago
If you use the PHP 5 installer, you’ll notice that it uses the wrong type of slash on Windows!
Change C:/Program Files/PHP/» to C:\Program Files\PHP\» and everything works great!
13 years ago
If anybody here encounters an error regarding PHPIniDir, change PHPIniDir «C:/php/» to PHPIniDir «C:\php\».
12 years ago
Here is yet another aspect of the «faulting module php5ts.dll» crash when trying to start apache.
I installed Apache 2.2.18, Mysql 5.1.57 and PHP 5.2.17 (apache module, VC6 thread-safe — initially with no extensions) on a fresh WinXP SP3 system. The versions chosen were because I was trying to replicate as near as possible apps on my Linux server.
Everything configured and ran properly without php extensions, so I then reran the msi installer and chose the necessary extensions. I reconfigured httpd.conf but apache then just kept crashing.
Eventually I came across the «fix» mentioned elsewhere «copy libmysql.dll to apache folder» and suddenly it worked. But why? I checked and the php installation folder was in the system path. The answer was simply that I had never rebooted. It seems that whatever process controls windows services only reads the path at boot time. I was thrown by assuming that if I started httpd from the command line then it would inherit that path.
Here are a few diagnostic tips that helped me along the way:
Try the CLI command:
php -m
and see that the command line version loads all the modules you asked for.
in php.ini, enable
display_errors = On
and
display_startup_errors = On
The latter pops up a window saying which extension it has trouble loading. Of course it is not perfectly clear, because it says something like ‘unable to load «C:\php\ext\php_mysql.dll» — The specified module could not be found’. It lies — it really does find that dll, but it must have failed on the dependency of libmysql.dll.
11 years ago
Installing Apache and PHP on Windows 7 Home Premium on a Gateway NV75S laptop with a quad AMD A6-3400M
All I need to do with these programs is to test my website out on my laptop. I have HTML and PHP files. I do not need MySQL as I use html5 storage.
Getting and installing Apache
1 In your browser go to h t t p : / / h t t p d . a p a c h e . o r g / d o w n l o a d . c g i
(without the spaces)
2 Click on httpd-2.2.22-win32-x86-no_ssl.msi
(this is a self-installing executable file without crypto . no Secure Socket Layer)
(2.2.22 was the latest version on April 25, 2012)
3 Click on the httpd-2.2.22-win32-x86-no_ssl.msi file after it downloads
(single click on the file tab in Chrome or double click on the actual file in Downloads)
4 Click Next
5 Click I accept the terms in the license agreement
6 Click Next
7 Click Next
8 Type localhost in the top box
9 Type localhost in the middle box
10 Type admin@localhost.com in the bottom box
11 Click Next
12 Click Next
13 Click Next
14 Click Install and wait
15 Cick Yes to allow the program to make changes
16 Click Finish
1 Type localhost in your browser location box (I use Chrome) or type h t t p : / / l o c a l h o s t
(without the spaces)
2 The message It works! should appear.
Getting and installing PHP
1 In your browser go to h t t p : / / w i n d o w s . p h p . n e t / d o w n l o a d /
(without the spaces)
2 Click on the Installer link under PHP 5.3 (5.3.10) VC9 x86 Thread Safe
(Ignore the Do NOT use VC9 version with apache.org binaries comment on the side panel)
3 Click on the php-5.3.10-Win32-VC9-x86.msi file after in downloads
(single click on the file tab in Chrome or double click on the actual file in Downloads)
4 Click Next
5 Click I accept the terms in the License Agreement
6 Click Next
7 Click Next
8 Click Apache 2.2.x Module
9 Click Next
10 Click Browse
11 Double click Apache Software Foundation
12 Double click Apache 2.2
13 Double click conf
14 Click OK
15 Click Next
16 Click Next
17 Click Install and wait
18 Cick Yes to allow the program to make changes
19 Click Finish
Testing PHP with Apache
1 Open Notepad
2 Type ‘left bracket character’?php phpinfo(); ?’right bracket character’
3 Save the file to C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs as test.php
4 Type localhost/test.php in your browser location box (I use Chrome) or type h t t p : / / l o c a l h o s t / t e s t . p h p
5 A table with title PHP Version . should appear
10 years ago
I am using Windows 8 x64, running Apache 2.2 and php 5.4.20
I found that it is necessary to add System Environment Variable PHPRC=[PHP path], so that php.ini is loaded using your PHP path, instead of C:\Windows.
This is how I do for my laptop
Go to Control Panel\System and Security\System\Advanced System Settings\Environment Variables
Add New System Variable
Name: PHPRC
Value: C:\php-5.4.20
Hope it relieve those who keep having empty string for Loaded Configuration File under phpinfo();
11 years ago
After spending few hours finally figured out that PHPINIDir path should be in single quotes and with backslash and php module with double quotes and regular slashes:
PHPIniDir ‘c:\apps\php\’
LoadModule php5_module «c:/apps/php/php5apache2_2.dll»
AddHandler application/x-httpd-php .php
13 years ago
After using the Windows installer for Apache 2.2 and PHP 5.3.2, and installing PHP as an Apache module (not CGI), Apache would crash and fail to start. There were two problems with the configuration files for Apache and PHP.
First, make sure your Apache configuration file reads something similar to:
LoadModule php5_module «C:/Program Files/PHP/php5apache2_2.dll»
PHPIniDir «C:/Program Files/PHP/»
While other users have disabled some or all of the MySQL extensions to prevent all three from running at the same time, I have all of them enabled. However, I do not have PostgreSQL, so I needed to comment out loading the php_pgsql.dll in my php.ini file, as follows:
This stopped Apache from crashing and started successfully.
7 years ago
If you are having issues getting the PHPIniDir or LoadModule directives to work and all the suggestions already given do not help, double-check if you are not using fancy quotes around your paths (‘ ’ “ ”).
This happened to me because I copied the statements from a random website. In my text editor the difference was barely noticeable, but to Apache it certainly is!
For example, this will not work:
PHPIniDir “C:/PHP7”
But this will work:
PHPIniDir «C:/PHP7»
8 years ago
If you come with an error like this: Wrapper xxxx cannot be accessed: blah blah blah when starting Apache.
You have 3 choices to solve this problem. Any one of them would work.
1. Install your applictions in paths that do not contains spaces.
2. Place a backslash before every space in the path set to Wrapper, like:
FctidWrapper «C:/Program\ Files/PHPServer/PHP/php-cgi.exe» .php
3. Use mklink (or junction for windows XP/2003) to create a link to the path you have installed php in.
run cmd.exe and type this command:
mklink /j C:\php\ «C:\Program Files\PHPServer\PHP».
or this command if you are on Windows XP/2003
junction C:\php\ «C:\Program Files\PHPServer\PHP»
Remember this : you have to download online to use this application. Don’t know where to download? Go and Google it.
Then the FctidWrapper directive should be like this:
FctidWrapper «C:/php/php-cgi.exe» .php
Don’t forget to change the paths above to your working paths.
8 years ago
Windows Apache 2.4.12 (x64) PHP 5.6.5 (x64)
If your Apache still outputs code instead of parsing a script. Make sure you put a trailing «\» at the end of the PHPIniDir value and use ONLY «\» in path to PHPIniDir. And «/» in LoadModule. A very subtle «feature» of Apache module. Lost several hours after upgrading to apache x64 to resolve the issue.
9 years ago
****Installed and Working 1- Fell Swoop — UPDATED****
Installed on Windows 8.1 XPS 12 — Dell 8GB RAM 128GB SSD —
Notes — Complications due to Apache latest version causes issues with the PHP handler on install. Following below will get it run right off the bat.
Getting and installing Apache
1 In your browser go to h t t p : / / h t t p d . a p a c h e . o r g / d o w n l o a d . c g i
(without the spaces) — You will need to go ‘Other Files’ , ‘Binaries’ , ‘W32’, and then your installer MSI will be listed as below.
2 Click on httpd-2.2.25-win32-x86-no_ssl.msi
(this is a self-installing executable file without crypto . no Secure Socket Layer)
(2.2.25was the latest version on June 4, 2014)
3 Click on the httpd-2.2.25-win32-x86-no_ssl.msi file after it downloads
(single click on the file tab in Chrome or double click on the actual file in Downloads)
4 Click Next
5 Click I accept the terms in the license agreement
6 Click Next
7 Click Next
8 Type localhost in the top box
9 Type localhost in the middle box
10 Type admin@localhost.com in the bottom box
11 Click Next
12 Click Next
13 Click Next
14 Click Install and wait
15 Cick Yes to allow the program to make changes
16 Click Finish
1 Type localhost in your browser location box (I use Chrome) or type h t t p : / / l o c a l h o s t
(without the spaces)
2 The message It works! should appear.
Getting and installing PHP
1 In your browser go to h t t p : / / w i n d o w s . p h p . n e t / d o w n l o a d /
(without the spaces)
2 Click on the Installer link under PHP 5.3 (5.3.10) VC9 x86 Thread Safe
(Ignore the Do NOT use VC9 version with apache.org binaries comment on the side panel)
3 Click on the php-5.3.10-Win32-VC9-x86.msi file after in downloads
(single click on the file tab in Chrome or double click on the actual file in Downloads)
4 Click Next
5 Click I accept the terms in the License Agreement
6 Click Next
7 Click Next
8 Click Apache 2.2.x Module
9 Click Next
10 Click Browse
11 Double click Apache Software Foundation
12 Double click Apache 2.2
13 Double click conf
14 Click OK
15 Click Next
16 Click Next
17 Click Install and wait
18 Cick Yes to allow the program to make changes
19 Click Finish
Testing PHP with Apache
1 Open Notepad
2 Type ‘left bracket character’?php phpinfo(); ?’right bracket character’
3 Save the file to C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs as test.php
4 Type localhost/test.php in your browser location box (I use Chrome) or type h t t p : / / l o c a l h o s t / t e s t . p h p
5 A table with title PHP Version . should appear
