Vâng, PHP4 có tại http://www.php.net, bây giờ là những bước cực kì đơn giản để cài Apache và PHP4 trên Windows của bạn. Có một lời câu hỏi mà nhiều người thắc mắc: thế còn PHP4+IIS thì sao? Tôi xin trả lời: "The installation instructions for PHP4 as an ISAPI filter for IIS are in the README.txt file, in the PHP 4.0.0 distribution." Tôi không thể viết một tutorial về vấn đề này, vì tôi có bao giờ dùng IIS đâu! Có một mailling list cho PHP+Windows, do đó nếu chỉ dẫn trong readme.txt không tốt lắm, hãy mail đến php-windows@lists.php.net.
Ok, ta bắt đầu...
Nếu Windows của bạn bạn đã cài Apache từ trước, bạn có thể bỏ qua bước này. Còn không, bây giờ hãy để cái PC thân yêu này trở thành một web server.
Trong quá trình cài đặt, một tập cấu hình sẽ lưu trong thư mục "conf" của Apache (thí dụ, "C:\Program Files\Apache Group\Apache\conf\"). Nếu bạn đã nhập những thông tin dưới đây khi cài đặt, có thể bỏ qua bước này. Dùng một chương trình soạn thảo, mở tập tin httpd.conf trong thư mục conf.
Trong httpd.conf, tìm đến dòng:
ServerAdmin you@your.address
Sửa lại cho đúng. Thí dụ:
ServerAdmin hainam@vnstars.com
Tìm đến dòng
#ServerName new.host.name
Sửa lại thành một cái gì đó đại loại như sau:
ServerName localhost
Nếu máy bạn có một cái tên đẹp, hãy ghi tên đấy vào.
Bây giờ chúng ta sẽ khởi động Apache.
Nếu bạn đang dùng Windows NT, và muốn chạy Apache như một service:
Nếu bạn không dùng NT:
Sau khi khởi động Apache, mở trình duyệt web và nhập http://127.0.0.1/ hoặc http://localhost/ để xem trang web cài đặt mặc định, có liên kết đến website của Apache và tài liệu về Apache. Nếu quá trình cài đặt có chỗ nào trục trặc, xin bạn đọc tài liệu về Apache và Apache FAQ để tìm lỗi, sau đó làm lại.
Nào, ta sẽ đi vào phần chính của bài viết.
Bây giờ ta sửa đôi chỗ trong các tập tin cấu hình Apache, và thưởng thức một hương vị của món trộn Apache + PHP4. Sau đó là vài bước tinh chỉnh PHP.Mở httpd.conf một lần nữa. Mục đích là bảo Apache sẽ làm gì với các tập tin .phtml, .php (hay những cái đuôi bạn thích là trang PHP). Về cơ bản, bạn cho Apache chạy một chương trình để làm một cái gì đó với các tập tin này; trường hợp của ta là chạy php.exe để biên dịch các đoạn mã PHP.
Tìm một đoạn như sau
## ScriptAlias: This controls which directories contain server scripts.
# ScriptAliases are essentially the same as Aliases, except that
# documents in the realname directory are treated as applications and
# run by the server when requested rather than as documents sent to the client.
# The same rules about trailing "/" apply to ScriptAlias directives as to
# Alias.
#
ScriptAlias /cgi-bin/ "C:/Apache/cgi-bin/"
Bạn thêm vào một dòng như sau
ScriptAlias /php4/ "C:/php4/"
Bây giờ tìm đến
## AddType allows you to tweak mime.types without actually editing it, or to
# make certain files to be certain types.
#
# For example, the PHP3 module (not part of the Apache distribution)
# will typically use:
#
#AddType application/x-httpd-php3 .phtml
#AddType application/x-httpd-php3-source .phps
Mặc dù cái thí dụ trên đã thành "đồ cổ", nhưng nó cũng cho bạn một ý tưởng. Đây là chỗ để bảo cho Apache "với những tập tin kết thúc bằng (cái gì đó), hãy xem nó thuộc kiểu (cái gì đó)". Thêm các dòng sau:
AddType application/x-httpd-php .phtml .phpAddType application/x-httpd-php-source .phps
Nếu thích, bạn có thể thêm các đuôi "tự tạo" cho các tập tin PHP của bạn (thực sự, bạn có thể đấy...). Bạn thêm vào ".nam" chẳng hạn sau dòng đầu.
Tiếp theo, tìm đến
## Action lets you define media types that will execute a script whenever
# a matching file is called. This eliminates the need for repeated URL
# pathnames for oft-used CGI file processors.
# Format: Action media/type /cgi-script/location
# Format: Action handler-name /cgi-script/location
#
Bạn cần thêm các action cho các types bạn vừa định nghĩa, để nó gửi đến trình biên dịch PHP. Thêm vào:
Action application/x-httpd-php /php4/php.exe
Lạ quá, không có kí tự ổ đĩa, dấu gạch lại ngược, không có các dấu nháy, nhưng mà đó là điều bạn cần làm. Cái /php4/ đã được định nghĩa qua ScriptAlias ở đầu tập tin cấu hình này (bạn nhớ không?), nên Apache biết /php4/ thực sự là C:\php4\ ("C:/php4/" == "C:\php4\" trong thế giới Apache).
Xong, hãy khởi động lại Apache (shut down and restart Apache if it's still running). Hãy soạn một tập tin có nội dung
phpinfo() ?>
Lưu lại với tên phpinfo.php, trong thư mục gốc của Apache (in the htdocs directory within your installation directory.).
Mở trình duyệt web và đến http://localhost/phpinfo.php - bạn thấy một trang như sau:

Nếu không thấy, thì sự lạ nào đó đã xảy ra!
So what is all this stuff? It's "info"...and a ton of it! The phpinfo() function produces this page that shows you what sorts of things are installed, your environment, your settings, and so on. The following list shows you the basic, compiled-in stuff:
This means that for the elements in the list above, you do not need to go out and find additional *.dll files. However, if you need Image Creation functions, Crypt functions, other database connectivity support functions, you need to go off and find the *.dlls for those things. A quick search of the mailing list archives should prove useful...what you'll probably find is a link to http://www.php4win.de/, where some PHP developer have donated time and energy to maintain up-to-date compilations of *.dlls for you to use. If you have any problems with the *.dll files you get from that site, remember to take that up with them, not me....
Alright, time to go back and tweak on the php.ini file. Use a text editor to open the php.ini file in C:\WINDOWS\ or wherever you placed it. The following changes are optional or just FYI.
For sending mail, find these two lines:
SMTP = localhost ;for win32 onlysendmail_from = me@localhost.com ;for win32 only
Change these to something useful, like:
SMTP = mail.yourdomain.comsendmail_from = you@yourdomain.com
If your outgoing mail server is mail.yourdomain.com and your e-mail address is you@yourdomain.com, that is.
To use additional *.dlls, put them in C:\php4\ and uncomment their entry in this block:
;Windows Extensions;extension=php_mysql.dll
;extension=php_nsmail.dll
;extension=php_calendar.dll
;extension=php_dbase.dll
;extension=php_filepro.dll
;extension=php_gd.dll
...
"Uncomment" means to take away that ";" at the beginning of the line. Notice that there's a line for the php_mysql.dll file, but remember, that's already compiled in for you. Don't think you need another one, because you don't.
That's really all there is to it; if anything blows up in your face or doesn't match what I've said, just let me know (http://www.thickbook.com/comments/index.phtml) - this has all worked for me about a zillion times now, but everybody's machine is different. Don't forget about the php-windows mailing list - it's a good place to ask questions.