Microsoft Windows üzerinde Apache 2.x

Bu bölüm, PHP'nin Microsoft Windows sistemlerinde Apache 2.x kurulumlarına özel notlar ve ipuçları içerir.

Bilginize:

Lütfen önce elle kurulum adımlarını okuyun!

Apache 2.x Sunucusu hakkında temel bir anlayışa sahip olmak için » Apache Belgelerine başvurmanız şiddetle tavsiye edilir. Ayrıca, burayı okumadan önce » Windows'a özgü Apache 2.x notlarını okumanız yararlı olur.

» Apache 2.x'in en son sürümünü ve uygun bir PHP sürümünü indirin. Elle Kurulum Adımlarını izleyin ve PHP'nin Apache ile bütünleştirilmesine devam etmek için geri gelin.

PHP'yi Windows'ta Apache 2.x ile çalışacak şekilde kurmanın üç yolu vardır. PHP, işleyici olarak, CGI olarak veya FastCGI altında çalıştırılabilir.

Bilginize: Windows üzerinde, Apache yapılandırma dosyalarına c:\dizin\dosya.uzn gibi dosya yollarını eklerken tüm tersbölü çizgilerini normal bölü çizgilerine çevirmeyi unutmayınız: c:/dizin/dosya.uzn. Dizin yollarını eklerken sona da bir bölü çizgisi eklemeniz gerekebilir.

Apache işleyicisi olarak kurulum

Apache 2.x PHP modülünü yüklemek için Apache httpd.conf yapılandırma dosyasına aşağıdaki satırlar eklenmelidir:

Örnek 1 Apache 2.x işleyicisi olarak PHP

# PHP 8.0.0 öncesinde modülün ismi php7_module idi
LoadModule php_module "c:/php/php8apache2_4.dll"
<FilesMatch \.php$>
    SetHandler application/x-httpd-php
</FilesMatch>
# php.ini yolunu yapılandır
PHPIniDir "C:/php"

Bilginize: Yukarıdaki örneklerde C:/php/ yerine PHP'nin gerçek yolu yazılmalıdır. LoadModule yönergesinde başvurulan dosyanın belirtilen konumda olduğundan emin olun. PHP 7 için php7apache2_4.dll, PHP 8 için php8apache2_4.dll kullanın.

PHP'yi CGI olarak çalıştırmak

Apache'de CGI çalıştırmanın daha iyi bir şekilde anlaşılması için » Apache CGI belgelerine başvurmanız şiddetle tavsiye edilir.

PHP'yi CGI olarak çalıştırmak için, php-cgi dosyalarının ScriptAlias yönergesi kullanılarak CGI dizini olarak belirlenmiş bir dizine yerleştirilmesi gerekecektir.

PHP dosyalarının başına PHP çalıştırılabilirinin konumuna işaret eden #! satırının yerleştirilmesi gerekir:

Örnek 2 CGI olarak PHP ve Apache 2.x

#!C:/php/php.exe
<?php
  phpinfo();
?>

Uyarı

CGI kipinde çalışan bir sunucu olası saldırılara açık hale gelir. Sunucunuzun böyle saldırılardan nasıl korunacağınızı öğrenmek için CGI güvenliği bölümü okunabilir.

PHP'yi FastCGI altında çalıştırmak

PHP'yi FastCGI altında çalıştırmanın, bir CGI olarak çalıştırmaya göre bir takım getirileri vardır. Bu şekilde ayarlamak oldukça basittir:

mod_fcgid modülünü » https://www.apachelounge.com adresinden edinin. Win32 ikili dosyaları bu siteden indirilebilir. Modülü beraberinde gelen talimatlara göre kurun.

Web sunucunuzu, sisteminize yüklediğiniz yeri belirten dosya yolunu ayarlamaya özen göstererek aşağıda gösterildiği gibi yapılandırın:

Örnek 3 PHP'yi FastCGI altında çalıştırmak için Apache yapılandırması

LoadModule fcgid_module modules/mod_fcgid.so
# php.ini dosyanızın yeri
FcgidInitialEnv PHPRC        "c:/php"
<FilesMatch \.php$>
    SetHandler fcgid-script
</FilesMatch>
FcgidWrapper "c:/php/php-cgi.exe" .php
.php uzantılı dosyalar artık PHP FastCGI sarmalayıcısı tarafından yürütülecektir.

add a note

User Contributed Notes 7 notes

up
40
wolfeh1994 at yahoo dot com
10 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.
up
1
a user
8 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"
up
8
a solution for simpletons like me
12 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

Testing Apache

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

DONE
up
1
Amaroq
11 years ago
Like someone else mentioned, on the Windows download page for PHP, ignore the warning about not downloading the VC9 compiled installers for the Apache.org version of Apache.

Whoever wrote that is guaranteeing that people install a PHP that breaks their Apache server. (On Windows 7 anyway.) The installer failed to write the correct path info to httpd.conf, and even after fixing that manually, Apache wouldn't start because of missing dlls.

Ignore that dumb warning and get the newest installer anyway. Everything just plain works with no hassle and no hunting down dll files over google.
up
1
kynetikmedia at gmail dot com
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

Testing Apache

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

DONE
up
1
Anonymous
14 years ago
If anybody here encounters an error regarding PHPIniDir, change PHPIniDir "C:/php/" to PHPIniDir "C:\php\".
up
3
farinspace
13 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 <Directory "C:/apache/htdocs"> block (or virtual host blocks):

Options ExecCGI
To Top