{"id":7,"date":"2005-05-31T22:15:26","date_gmt":"2005-06-01T05:15:26","guid":{"rendered":"http:\/\/www.chuonthis.com\/tips\/?p=7"},"modified":"2006-04-03T10:51:29","modified_gmt":"2006-04-03T17:51:29","slug":"php-apache-and-cygwin","status":"publish","type":"post","link":"https:\/\/chuonthis.com\/tips\/2005\/05\/31\/php-apache-and-cygwin\/","title":{"rendered":"PHP Apache and Cygwin"},"content":{"rendered":"<p>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&#8211;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&#8211;Google for a page posted by someone who did the work already so I wouldn&#8217;t have to.<br \/>\n<!--more--><br \/>\nAfter browsing through numerous pages of Google results, I couldn&#8217;t come up with anything for the search terms &#8216;cygwin apache php&#8217;.  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.<\/p>\n<p>Instead, this site (<a href=\"http:\/\/apache.dev.wapme.net\/support\/cygwin-packages\/apache-modules\/mod_php4\/\">Index of \/support\/cygwin-packages\/apache-modules\/mod_php4<\/a>) caught my eye.  It was the eighth result and I thought to myself, &#8220;OMG, there&#8217;s a package available!&#8221;  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&#8217;t install the package correctly because it didn&#8217;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).<\/p>\n<p>To start Apache, I ran &#8216;\/usr\/sbin\/apachectl start&#8217; and I saw that it started the http daemon.  Woohoo!  I made a test PHP file in \/var\/www\/htdocs but it wasn&#8217;t being parsed.  What gives?  I looked at \/etc\/apache\/httpd.conf for the appropriate PHP module lines but they weren&#8217;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&#8230;<\/p>\n<pre># \/usr\/sbin\/apachectl start\r\nSyntax error on line 236 of \/etc\/apache\/httpd.conf:\r\nCannot load \/usr\/lib\/apache\/libphp4.dll into server: dlopen: Win32 error 998\r\n\/usr\/sbin\/apachectl start: httpd could not be started<\/pre>\n<p>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 &#8216;cygcheck libphp4.dll&#8217; to check for any dependency problems.  I did that and received some &#8216;could not find something.dll&#8217; errors.  So I tried to look for them and also for any packages which might have them.  I couldn&#8217;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.<\/p>\n<p>I decided to rethink the strategy to take.  How about compiling PHP myself?  So I downloaded the <a href=\"http:\/\/www.php.net\/downloads.php\">PHP source files<\/a> and looked at the INSTALL file.  I decided to just try &#8216;.\/configure&#8217; without any parameters first because I didn&#8217;t want to deal with them (read: lazy).  It said it couldn&#8217;t find lex.  D&#8217;oh, another package to install (flex).  Then I ran configure again and it started doing it&#8217;s thing.<\/p>\n<p>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 (<a href=\"http:\/\/discypus.jp\/wiki\/?Cygwin%2Fapache%2Fphp\">Cygwin\/apache\/php &#8211; discypus<\/a>).  The Google page summary was in Japanese and what&#8217;s a discypus?  Who knows, let&#8217;s click on the link!  Even though I&#8217;ve only had four quarters of Japanese and couldn&#8217;t read any of the kanji, I understood &#8220;Apache 1.3.29-2 + PHP 4.3.8 (2004-07-26)&#8221;.  I scrolled down a little more and, &#8220;OMG! PHP compiling instructions for Cygwin!&#8221;  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&#8217;t really need anyway).  The <a href=\"http:\/\/discypus.jp\/wiki\/\">Discypus wiki<\/a> is a goldmine of Cygwin information (and more!).  Moral of the story?  Trust any Japanese sites you visit.<\/p>\n<hr \/>\n<p>Here are the instructions with some translatations.  All credit goes to Discypus.<\/p>\n<p>1. Required Cygwin packages (in addition to the ones mentioned above):<\/p>\n<pre>$ grep -A20 '@ apache' setup.ini | grep require\r\nrequires: cygwin crypt libgdbm4\r\n\r\n$ cygcheck -cd cygwin apache crypt libgdbm4\r\nCygwin Package Information\r\nPackage              Version\r\napache               1.3.29-2\r\ncrypt                1.1-1\r\ncygwin               1.5.10-3\r\nlibgdbm4             1.8.3-7<\/pre>\n<p>2. Extract the PHP source files:<\/p>\n<pre>$ cd \/usr\/local\/src\/php\r\n\r\n$ tar jxvf php-4.3.8.tar.bz2\r\nphp-4.3.8\/\r\nphp-4.3.8\/ext\/\r\n:\r\nphp-4.3.8\/README.UNIX-BUILD-SYSTEM\r\nphp-4.3.8\/php4.spec.in<\/pre>\n<p>3. Run configure:<\/p>\n<pre>$ cd php-4.3.8\r\n\r\n$ .\/configure --with-apxs=\/usr\/sbin\/apxs --without-mysql --enable-mbstring\r\ncreating cache .\/config.cache\r\nchecking host system type... i686-pc-cygwin\r\n:\r\ncreating main\/internal_functions_cli.c\r\n+--------------------------------------------------------------------+\r\n| License:                                                           |\r\n| This software is subject to the PHP License, available in this     |\r\n| distribution in the file LICENSE.  By continuing this installation |\r\n| process, you are bound by the terms of this license agreement.     |\r\n| If you do not agree with the terms of this license, you must abort |\r\n| the installation process at this point.                            |\r\n+--------------------------------------------------------------------+\r\n|                          *** NOTE ***                              |\r\n|            The default for register_globals is now OFF!            |\r\n|                                                                    |\r\n| If your application relies on register_globals being ON, you       |\r\n| should explicitly set it to on in your php.ini file.               |\r\n| Note that you are strongly encouraged to read                      |\r\n| http:\/\/www.php.net\/manual\/en\/security.registerglobals.php          |\r\n| about the implications of having register_globals set to on, and   |\r\n| avoid using it if possible.                                        |\r\n+--------------------------------------------------------------------+\r\n\r\nThank you for using PHP.<\/pre>\n<p>4. Modifying the Makefile:<\/p>\n<pre>$ sed -i.org 's\/libphp4\\.so\/libphp4.dll\/g' Makefile\r\n$ diff Makefile.org Makefile\r\n:<\/pre>\n<p>5. Run make:<\/p>\n<pre>$ make\r\n:\r\nBuild complete.\r\n(It is safe to ignore warnings about tempnam and tmpnam).<\/pre>\n<p>6. Compile the PHP libraries:<\/p>\n<pre>$ cd libs\r\n$ ls\r\nlibphp4.a  libphp4.la\r\n$ gcc -shared -o libphp4.dll -Wl,--out-implib=libphp4.dll.a \\\r\n-Wl,--export-all-symbols \\\r\n-Wl,--whole-archive libphp4.a \/bin\/cyghttpd.dll \\\r\n-Wl,--no-whole-archive -lcrypt -lresolv\r\nCreating library file: libphp4.dll.a\r\nInfo: resolving _ap_user_id by linking to __imp__ap_user_id (auto-import)\r\nInfo: resolving _ap_group_id by linking to __imp__ap_group_id (auto-import)\r\nInfo: resolving _ap_user_name by linking to __imp__ap_user_name (auto-import)\r\nInfo: resolving _ap_max_requests_per_child by linking to __imp__ap_max_requests_\r\nper_child (auto-import)\r\nInfo: resolving _ap_server_root by linking to __imp__ap_server_root (auto-import\r\n)\r\nInfo: resolving _top_module by linking to __imp__top_module (auto-import)\r\n$ ls\r\nlibphp4.a  libphp4.dll  libphp4.dll.a  libphp4.la<\/pre>\n<p>7. Run make install:<\/p>\n<pre>$ cd ..\r\n$ make install\r\nInstalling PHP SAPI module:       apache\r\n[activating module `php4' in \/etc\/apache\/httpd.conf]\r\ncp libs\/libphp4.dll \/usr\/lib\/apache\/libphp4.dll\r\nchmod 755 \/usr\/lib\/apache\/libphp4.dll\r\ncp \/etc\/apache\/httpd.conf \/etc\/apache\/httpd.conf.bak\r\ncp \/etc\/apache\/httpd.conf.new \/etc\/apache\/httpd.conf\r\nrm \/etc\/apache\/httpd.conf.new\r\nInstalling PHP CLI binary:        \/usr\/local\/bin\/\r\nInstalling PHP CLI man page:      \/usr\/local\/man\/man1\/\r\nInstalling PEAR environment:      \/usr\/local\/lib\/php\/\r\n[PEAR] Archive_Tar    - installed: 1.1\r\n[PEAR] Console_Getopt - installed: 1.2\r\n[PEAR] PEAR           - installed: 1.3.2\r\nWrote PEAR system config file at: \/usr\/local\/etc\/pear.conf\r\nYou may want to add: \/usr\/local\/lib\/php to your php.ini include_path\r\n[PEAR] DB             - installed: 1.6.2\r\n[PEAR] HTTP           - installed: 1.2.2\r\n[PEAR] Mail           - installed: 1.1.3\r\n[PEAR] Net_SMTP       - installed: 1.2.3\r\n[PEAR] Net_Socket     - installed: 1.0.1\r\n[PEAR] XML_Parser     - installed: 1.0.1\r\n[PEAR] XML_RPC        - installed: 1.1.0\r\nInstalling build environment:     \/usr\/local\/lib\/php\/build\/\r\nInstalling header files:          \/usr\/local\/include\/php\/\r\nInstalling helper programs:       \/usr\/local\/bin\/\r\n  program: phpize\r\n  program: php-config\r\n  program: phpextdist<\/pre>\n<p>8. Make sure the following two lines were added to \/etc\/apache\/httpd.conf (if not, add them):<\/p>\n<pre>LoadModule php4_module        lib\/apache\/libphp4.dll\r\nAddModule mod_php4.c<\/pre>\n<p>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):<\/p>\n<pre>#\r\n# Document types.\r\n#\r\n<ifmodule mod_mime.c>\r\n:\r\n   # for PHP 4.x\r\n   #\r\n   AddType application\/x-httpd-php .php\r\n   AddType application\/x-httpd-php-source .phps<\/ifmodule><\/pre>\n<p>10. Check the contents of httpd.conf:<\/p>\n<pre>$ \/usr\/sbin\/apachectl configtest\r\nSyntax OK<\/pre>\n<p>11. Start the http daemon<\/p>\n<p>12. Create a test file \/var\/www\/htdocs\/phpinfo.php:<\/p>\n<pre>&lt;?php phpinfo(); ?&gt;<\/pre>\n<p>13. Test the file at http:\/\/localhost\/phpinfo.php<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&#8211;check for a Cygwin package. I only saw the Apache package but I needed PHP too so I decided to hold off on installing&hellip; <a class=\"continue-reading-link\" href=\"https:\/\/chuonthis.com\/tips\/2005\/05\/31\/php-apache-and-cygwin\/\">Continue reading <span class=\"screen-reader-text\">PHP Apache and Cygwin<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-7","post","type-post","status-publish","format-standard","hentry","category-computers","entry"],"_links":{"self":[{"href":"https:\/\/chuonthis.com\/tips\/wp-json\/wp\/v2\/posts\/7","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/chuonthis.com\/tips\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/chuonthis.com\/tips\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/chuonthis.com\/tips\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/chuonthis.com\/tips\/wp-json\/wp\/v2\/comments?post=7"}],"version-history":[{"count":0,"href":"https:\/\/chuonthis.com\/tips\/wp-json\/wp\/v2\/posts\/7\/revisions"}],"wp:attachment":[{"href":"https:\/\/chuonthis.com\/tips\/wp-json\/wp\/v2\/media?parent=7"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/chuonthis.com\/tips\/wp-json\/wp\/v2\/categories?post=7"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/chuonthis.com\/tips\/wp-json\/wp\/v2\/tags?post=7"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}