Honda Accord can’t start engine when it’s hot outside (main relay)

PHP Apache and Cygwin

May 31st, 2005 at 10:15pm

Boy did I have a hard time getting PHP and Apache to work under Cygwin. I had to set the environment up for a class project so first I did what any reasonably lazy person would do–check for a Cygwin package. I only saw the Apache package but I needed PHP too so I decided to hold off on installing it. So next I did what any reasonably lazy person would do next–Google for a page posted by someone who did the work already so I wouldn’t have to.

After browsing through numerous pages of Google results, I couldn’t come up with anything for the search terms ‘cygwin apache php’. Of course now that I just re-searched for those terms, the page I ended up with at the end of my journey is the fifth result. More on that later.

Instead, this site (Index of /support/cygwin-packages/apache-modules/mod_php4) caught my eye. It was the eighth result and I thought to myself, “OMG, there’s a package available!” So off I go to download and install the package. I installed the Apache and Apache-PHP packages. Now I might not be the most experienced Cygwin user so maybe I didn’t install the package correctly because it didn’t check for any of the dependencies. After looking at the setup.hint file, I installed the required packages and I thought I was set (cygwin apache libgdbm openssl bzip2 zlib gettext libxml2 postgresql libbz2_0 libbz2_1 rebase).

To start Apache, I ran ‘/usr/sbin/apachectl start’ and I saw that it started the http daemon. Woohoo! I made a test PHP file in /var/www/htdocs but it wasn’t being parsed. What gives? I looked at /etc/apache/httpd.conf for the appropriate PHP module lines but they weren’t there. Then I realized that installing both the Apache and Apache-PHP packages at the same time must not have been a good idea. I reinstalled the Apache-PHP package and it made the appropriate changes to the httpd.conf file. Now to restart the daemon…

# /usr/sbin/apachectl start
Syntax error on line 236 of /etc/apache/httpd.conf:
Cannot load /usr/lib/apache/libphp4.dll into server: dlopen: Win32 error 998
/usr/sbin/apachectl start: httpd could not be started

Hrm? Being the reasonably lazy guy that I am, I set off to Google in search for an answer. The results were mostly mailing list archives for people getting the error message without a resolution. Some people suggested rebasing the DLL so I tried that. Nope, same error. Other people suggested running ‘cygcheck libphp4.dll’ to check for any dependency problems. I did that and received some ‘could not find something.dll’ errors. So I tried to look for them and also for any packages which might have them. I couldn’t find cyghttpd.dll or cygcrypto.dll and I googled for the packages containing them but it seems that I already had them (Apache and OpenSSL). So I just made copies of libhttpd.dll and cygcrypto-0.9.7.dll to the respective missing files and hoped that the problem would be solved. I ran cygcheck and everything was okay so I tried to start up http daemon again. Same error.

I decided to rethink the strategy to take. How about compiling PHP myself? So I downloaded the PHP source files and looked at the INSTALL file. I decided to just try ‘./configure’ without any parameters first because I didn’t want to deal with them (read: lazy). It said it couldn’t find lex. D’oh, another package to install (flex). Then I ran configure again and it started doing it’s thing.

While configure was running, I decided to go back to my Google search results and see if I could find any useful information. Then I stumbled upon this page (Cygwin/apache/php - discypus). The Google page summary was in Japanese and what’s a discypus? Who knows, let’s click on the link! Even though I’ve only had four quarters of Japanese and couldn’t read any of the kanji, I understood “Apache 1.3.29-2 + PHP 4.3.8 (2004-07-26)”. I scrolled down a little more and, “OMG! PHP compiling instructions for Cygwin!” Since this information was on a Japanese site, I cancelled my configure immediately. I followed the instructions to a T and ended up with a working Apache with PHP (minus the MySQL which I didn’t really need anyway). The Discypus wiki is a goldmine of Cygwin information (and more!). Moral of the story? Trust any Japanese sites you visit.

Here are the instructions with some translatations. All credit goes to Discypus.

1. Required Cygwin packages (in addition to the ones mentioned above):

$ grep -A20 '@ apache' setup.ini | grep require
requires: cygwin crypt libgdbm4

$ cygcheck -cd cygwin apache crypt libgdbm4
Cygwin Package Information
Package              Version
apache               1.3.29-2
crypt                1.1-1
cygwin               1.5.10-3
libgdbm4             1.8.3-7

2. Extract the PHP source files:

$ cd /usr/local/src/php

$ tar jxvf php-4.3.8.tar.bz2

3. Run configure:

$ cd php-4.3.8

$ ./configure --with-apxs=/usr/sbin/apxs --without-mysql --enable-mbstring
creating cache ./config.cache
checking host system type... i686-pc-cygwin
creating main/internal_functions_cli.c
| License:                                                           |
| This software is subject to the PHP License, available in this     |
| distribution in the file LICENSE.  By continuing this installation |
| process, you are bound by the terms of this license agreement.     |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point.                            |
|                          *** NOTE ***                              |
|            The default for register_globals is now OFF!            |
|                                                                    |
| If your application relies on register_globals being ON, you       |
| should explicitly set it to on in your php.ini file.               |
| Note that you are strongly encouraged to read                      |
|          |
| about the implications of having register_globals set to on, and   |
| avoid using it if possible.                                        |

Thank you for using PHP.

4. Modifying the Makefile:

$ sed 's/' Makefile
$ diff Makefile

5. Run make:

$ make
Build complete.
(It is safe to ignore warnings about tempnam and tmpnam).

6. Compile the PHP libraries:

$ cd libs
$ ls
$ gcc -shared -o libphp4.dll -Wl,--out-implib=libphp4.dll.a 
-Wl,--whole-archive libphp4.a /bin/cyghttpd.dll 
-Wl,--no-whole-archive -lcrypt -lresolv
Creating library file: libphp4.dll.a
Info: resolving _ap_user_id by linking to __imp__ap_user_id (auto-import)
Info: resolving _ap_group_id by linking to __imp__ap_group_id (auto-import)
Info: resolving _ap_user_name by linking to __imp__ap_user_name (auto-import)
Info: resolving _ap_max_requests_per_child by linking to __imp__ap_max_requests_
per_child (auto-import)
Info: resolving _ap_server_root by linking to __imp__ap_server_root (auto-import
Info: resolving _top_module by linking to __imp__top_module (auto-import)
$ ls
libphp4.a  libphp4.dll  libphp4.dll.a

7. Run make install:

$ cd ..
$ make install
Installing PHP SAPI module:       apache
[activating module `php4' in /etc/apache/httpd.conf]
cp libs/libphp4.dll /usr/lib/apache/libphp4.dll
chmod 755 /usr/lib/apache/libphp4.dll
cp /etc/apache/httpd.conf /etc/apache/httpd.conf.bak
cp /etc/apache/ /etc/apache/httpd.conf
rm /etc/apache/
Installing PHP CLI binary:        /usr/local/bin/
Installing PHP CLI man page:      /usr/local/man/man1/
Installing PEAR environment:      /usr/local/lib/php/
[PEAR] Archive_Tar    - installed: 1.1
[PEAR] Console_Getopt - installed: 1.2
[PEAR] PEAR           - installed: 1.3.2
Wrote PEAR system config file at: /usr/local/etc/pear.conf
You may want to add: /usr/local/lib/php to your php.ini include_path
[PEAR] DB             - installed: 1.6.2
[PEAR] HTTP           - installed: 1.2.2
[PEAR] Mail           - installed: 1.1.3
[PEAR] Net_SMTP       - installed: 1.2.3
[PEAR] Net_Socket     - installed: 1.0.1
[PEAR] XML_Parser     - installed: 1.0.1
[PEAR] XML_RPC        - installed: 1.1.0
Installing build environment:     /usr/local/lib/php/build/
Installing header files:          /usr/local/include/php/
Installing helper programs:       /usr/local/bin/
  program: phpize
  program: php-config
  program: phpextdist

8. Make sure the following two lines were added to /etc/apache/httpd.conf (if not, add them):

LoadModule php4_module        lib/apache/libphp4.dll
AddModule mod_php4.c

9. Add the following two lines to the same file in the appropriate section (I just added the first line to the end of the file):

# Document types.

   # for PHP 4.x
   AddType application/x-httpd-php .php
   AddType application/x-httpd-php-source .phps

10. Check the contents of httpd.conf:

$ /usr/sbin/apachectl configtest
Syntax OK

11. Start the http daemon

12. Create a test file /var/www/htdocs/phpinfo.php:

<?php phpinfo(); ?>

13. Test the file at http://localhost/phpinfo.php

Entry Filed under: computers

18 Comments Add your own

  • 1. Paul Eastlund  |  March 1st, 2006 at 9:15 pm

    You just saved me hours of agony. Thank you, thank you, thank you.

  • 2. PmmR  |  March 15th, 2006 at 3:31 pm

    I have the following error message when I run make…

    $ make
    MAKE Version 5.2 Copyright (c) 1987, 1998 Inprise Corp.
    Error makefile 174: Colon expected
    *** 1 errors during make ***

    I verified the line 174 in Makefile but I haven’t idea where to put the colon that he expected…
    I appreciate any help…

  • 3. chuonthis  |  March 15th, 2006 at 9:12 pm

    Here’s my lines 170-185. Hope this pastes correctly!

    distclean: clean
    	rm -f config.cache config.log config.status Makefile.objects Makefile.fragments libtool main/php_config.h stamp-h php4.spec sapi/apache/libphp4.module buildmk.stamp
    	egrep define'.*include/php' configure|sed 's/.*>//'|xargs rm -f
    	find . -name Makefile | xargs rm -f
    .PHONY: all clean install distclean test
    install-cli: $(SAPI_CLI_PATH)
    	@echo "Installing PHP CLI binary:        $(INSTALL_ROOT)$(bindir)/"
    	@echo "Installing PHP CLI man page:      $(INSTALL_ROOT)$(mandir)/man1/"
    	@$(mkinstalldirs) $(INSTALL_ROOT)$(mandir)/man1
    	@$(INSTALL_DATA) sapi/cli/php.1 $(INSTALL_ROOT)$(mandir)/man1/php.1
  • 4. PmmR  |  March 16th, 2006 at 9:25 am

    I compared line per line and no great differences are between I have and you pass to me… Anyway, I replaced the lines and tried one more time, now display me more errors:
    $ make
    MAKE Version 5.2 Copyright (c) 1987, 1998 Inprise Corp.
    Error makefile 186: Command syntax error
    Error makefile 187: No match found for wildcard ‘define’.*include/php'’
    Error makefile 187: No match found for wildcard ‘’s/.*>//’|xargs’
    Error makefile 187: Command syntax error
    Error makefile 188: Command syntax error
    Error makefile 191: Colon expected
    Error makefile 197: Redefinition of target ’sapi/cli/php.exe’
    Error makefile 197: Command syntax error
    Error makefile 198: Redefinition of target ‘@echo’
    Error makefile 199: Command syntax error
    Error makefile 200: Command syntax error
    *** 11 errors during make ***

    These are the versions of the packages that I have installed..
    $ cygcheck.exe -cd cygwin apache crypt libgdbm4
    Cygwin Package Information
    Package Version
    apache 1.3.33-2
    crypt 1.1-1
    cygwin 1.5.19-4
    libgdbm4 1.8.3-7
    and I trying to compile php-4.4.2, the different version of php I use can be a problem?
    thanks again…

  • 5. André  |  April 2nd, 2006 at 8:31 pm

    You and Discypus are doing a great job! But I need some help:

    $ make
    MAKE Version 5.2 Copyright (c) 1987, 2000 Borland
    Error makefile 35: Command syntax error
    Error makefile 36: Command syntax error
    Error makefile 37: Command syntax error
    Error makefile 72: Colon expected
    *** 4 errors during make ***

    Lines 35, 36 and 37 are includes:

    include $(top_srcdir)/build/
    include $(top_srcdir)/build/
    include $(top_srcdir)/build/

    And the line 72 is simply:


    The versions of the packages are the same as PmmR, except php: 4.2.0-1.

    Thanks a lot.

  • 6. chuonthis  |  April 2nd, 2006 at 8:44 pm

    Hey guys, I’ll try downloading version 4.2.0 or 4.2.2 this week and give it a try and see if what happens.

  • 7. chuonthis  |  April 3rd, 2006 at 11:01 am

    Just tried this with the 4.2.2 source files. I was able to run MAKE without any problems. I updated my posts to use PRE tags instead of CODE tags so hopefully you can read those parts better (notice the horizontal scrollbars). Can you guys give it another try? Just blow away the php-x.x.x directory and try again. I’m thinking there were problems copying/pasting the SED command which caused the problems in Makefile.

  • 8. PmmR  |  April 18th, 2006 at 8:15 am

    At this right moment I wasn’t able to run Apache+PHP on cygwin… This subject was converted on a karma…

  • 9. Ppkk  |  June 6th, 2006 at 9:30 am

    Are you sure it’s all right to use Borland Inprise make utility?
    Delete path to Borland make or place it after path to “good” make (i.e. Cygwin) utility.

  • 10. mo  |  June 19th, 2006 at 12:52 am

    I could not complete the compilation of PHP5 with apache2 on Cygwin though I tried to do step by step as decribed in this page like php4 with apache 1.3. How do I do ….

  • 11. Brett Graham  |  August 7th, 2006 at 3:11 am

    I failed at step 6 becuase I didn’t have /bin/cyghttpd.dll.

    I tried re-building apache 1.3 but it would only generate libhttpd.dll.

    I tried searing on the internet, and everything seemed to suggest that it was the same as cyghttpd.dll, so I replaced it in the gcc line (I didn’t rename the file!) and it worked fine!

    It would be nice if one of us could come up with a list of dependancies, as the one above is too short. I found myself repeatedly running the cygwin setup to get different bits and bobs, as and when things failed. If I’d known how many there’d be when I started out, I would made notes, and pasted them here. Oh, well.

  • 12. thanh  |  August 7th, 2006 at 5:19 am

    make install ok

    $ /usr/sbin/apachectl configtest
    Syntax error on line 239 of /etc/apache/httpd.conf:
    Cannot load /usr/lib/apache/libphp4.dll into server: Bad address

    help me

    $ cygcheck.exe -cd cygwin apache crypt libgdbm4
    Cygwin Package Information
    Package Version
    apache 1.3.33-2
    crypt 1.1-1
    cygwin 1.5.21-2
    libgdbm4 1.8.3-7

  • 13. Jason  |  August 23rd, 2006 at 6:07 pm

    Thank you!!! I’ve gone through at least 3 days of trying anything i could think of or find. This works great.

  • 14. Kutschenreuter  |  November 12th, 2006 at 1:07 pm

    Much thanks to the author of this installation description. If I would not have found this description, I would not have been able to run PHP under cygwin. But now it is running.

    I only want to add that if you want to use graphical functions like imagesetpixel or imageline in your php script you have add
    –with-zlib –with-gd to the command line in the run configure step.

  • 15. bob  |  May 30th, 2007 at 12:36 pm

    I failed at Step 10: Check the contents of httpd.conf:

    Syntax error on line 239 of /etc/apache/httpd.conf:
    Can’t locate API module structure `php5_module’ in file /usr/lib/apache/libphp5.dll: No such file or directory

    This is what I have in httpd.conf
    LoadModule php5_module lib/apache/libphp5.dll

    The file is in fact located in C:\cygwin\lib\apache

    Can anyone help.

  • 16. System  |  July 16th, 2007 at 1:37 pm

    ^ if you’re using apache2 (which you should with php5) and it’s the cygwin package of apache2, the dso modules are in /usr/lib/apache2

    you can check the directory prefix that apache2 is using by greping the server root:
    `grep -i serverroot /etc/apache2/httpd.conf`

  • 17. nelson  |  September 29th, 2007 at 1:05 pm

    now how do you add MySQL server to this equasion?

  • 18. Sergey  |  May 22nd, 2009 at 2:41 pm

    Thank you very mach!

Leave a Comment


Required, hidden

Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>

Trackback this post  |  Subscribe to the comments via RSS Feed


May 2005
    Jun »

Most Recent Posts