You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2066 lines
92 KiB

22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
21 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
28 years ago
28 years ago
28 years ago
22 years ago
28 years ago
28 years ago
28 years ago
28 years ago
28 years ago
28 years ago
28 years ago
28 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
17 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
22 years ago
  1. __________________________________________________________________
  2. Installing PHP
  3. __________________________________________________________________
  4. * General Installation Considerations
  5. * Installation on Unix systems
  6. + Apache 1.3.x on Unix systems
  7. + Apache 2.x on Unix systems
  8. + Lighttpd 1.4 on Unix systems
  9. + Sun, iPlanet and Netscape servers on Sun Solaris
  10. + CGI and command line setups
  11. + HP-UX specific installation notes
  12. + OpenBSD installation notes
  13. + Solaris specific installation tips
  14. + Debian GNU/Linux installation notes
  15. * Installation on Mac OS X
  16. + Using Packages
  17. + Using the bundled PHP
  18. + Compiling PHP on Mac OS X
  19. * Installation of PECL extensions
  20. + Introduction to PECL Installations
  21. + Downloading PECL extensions
  22. + Installing a PHP extension on Windows
  23. + Compiling shared PECL extensions with the pecl command
  24. + Compiling shared PECL extensions with phpize
  25. + Compiling PECL extensions statically into PHP
  26. * Problems?
  27. + Read the FAQ
  28. + Other problems
  29. + Bug reports
  30. * Runtime Configuration
  31. + The configuration file
  32. + .user.ini files
  33. + Where a configuration setting may be set
  34. + How to change configuration settings
  35. * Installation
  36. __________________________________________________________________
  37. __________________________________________________________________
  38. Preface
  39. These installation instructions were generated from the HTML version of
  40. the PHP Manual so formatting and linking have been altered. See the
  41. online and updated version at: http://php.net/install.unix
  42. __________________________________________________________________
  43. General Installation Considerations
  44. Before starting the installation, first you need to know what do you
  45. want to use PHP for. There are three main fields you can use PHP, as
  46. described in the What can PHP do? section:
  47. * Websites and web applications (server-side scripting)
  48. * Command line scripting
  49. * Desktop (GUI) applications
  50. For the first and most common form, you need three things: PHP itself,
  51. a web server and a web browser. You probably already have a web
  52. browser, and depending on your operating system setup, you may also
  53. have a web server (e.g. Apache on Linux and MacOS X; IIS on Windows).
  54. You may also rent webspace at a company. This way, you don't need to
  55. set up anything on your own, only write your PHP scripts, upload it to
  56. the server you rent, and see the results in your browser.
  57. In case of setting up the server and PHP on your own, you have two
  58. choices for the method of connecting PHP to the server. For many
  59. servers PHP has a direct module interface (also called SAPI). These
  60. servers include Apache, Microsoft Internet Information Server, Netscape
  61. and iPlanet servers. Many other servers have support for ISAPI, the
  62. Microsoft module interface (OmniHTTPd for example). If PHP has no
  63. module support for your web server, you can always use it as a CGI or
  64. FastCGI processor. This means you set up your server to use the CGI
  65. executable of PHP to process all PHP file requests on the server.
  66. If you are also interested to use PHP for command line scripting (e.g.
  67. write scripts autogenerating some images for you offline, or processing
  68. text files depending on some arguments you pass to them), you always
  69. need the command line executable. For more information, read the
  70. section about writing command line PHP applications. In this case, you
  71. need no server and no browser.
  72. With PHP you can also write desktop GUI applications using the PHP-GTK
  73. extension. This is a completely different approach than writing web
  74. pages, as you do not output any HTML, but manage windows and objects
  75. within them. For more information about PHP-GTK, please » visit the
  76. site dedicated to this extension. PHP-GTK is not included in the
  77. official PHP distribution.
  78. From now on, this section deals with setting up PHP for web servers on
  79. Unix and Windows with server module interfaces and CGI executables. You
  80. will also find information on the command line executable in the
  81. following sections.
  82. PHP source code and binary distributions for Windows can be found at »
  83. http://www.php.net/downloads.php. We recommend you to choose a » mirror
  84. nearest to you for downloading the distributions.
  85. __________________________________________________________________
  86. __________________________________________________________________
  87. Installation on Unix systems
  88. Table of Contents
  89. * Apache 1.3.x on Unix systems
  90. * Apache 2.x on Unix systems
  91. * Lighttpd 1.4 on Unix systems
  92. * Sun, iPlanet and Netscape servers on Sun Solaris
  93. * CGI and command line setups
  94. * HP-UX specific installation notes
  95. * OpenBSD installation notes
  96. * Solaris specific installation tips
  97. * Debian GNU/Linux installation notes
  98. This section will guide you through the general configuration and
  99. installation of PHP on Unix systems. Be sure to investigate any
  100. sections specific to your platform or web server before you begin the
  101. process.
  102. As our manual outlines in the General Installation Considerations
  103. section, we are mainly dealing with web centric setups of PHP in this
  104. section, although we will cover setting up PHP for command line usage
  105. as well.
  106. There are several ways to install PHP for the Unix platform, either
  107. with a compile and configure process, or through various pre-packaged
  108. methods. This documentation is mainly focused around the process of
  109. compiling and configuring PHP. Many Unix like systems have some sort of
  110. package installation system. This can assist in setting up a standard
  111. configuration, but if you need to have a different set of features
  112. (such as a secure server, or a different database driver), you may need
  113. to build PHP and/or your web server. If you are unfamiliar with
  114. building and compiling your own software, it is worth checking to see
  115. whether somebody has already built a packaged version of PHP with the
  116. features you need.
  117. Prerequisite knowledge and software for compiling:
  118. * Basic Unix skills (being able to operate "make" and a C compiler)
  119. * An ANSI C compiler
  120. * A web server
  121. * Any module specific components (such as GD, PDF libs, etc.)
  122. When building directly from SVN sources or after custom modifications
  123. you might also need:
  124. * autoconf: 2.13
  125. * automake: 1.4+
  126. * libtool: 1.4.x+ (except 1.4.2)
  127. * re2c: Version 0.13.4 or newer
  128. * flex: Version 2.5.4 (for PHP <= 5.2)
  129. * bison: Version 1.28 (preferred), 1.35, or 1.75
  130. The initial PHP setup and configuration process is controlled by the
  131. use of the command line options of the configure script. You could get
  132. a list of all available options along with short explanations running
  133. ./configure --help. Our manual documents the different options
  134. separately. You will find the core options in the appendix, while the
  135. different extension specific options are descibed on the reference
  136. pages.
  137. When PHP is configured, you are ready to build the module and/or
  138. executables. The command make should take care of this. If it fails and
  139. you can't figure out why, see the Problems section.
  140. __________________________________________________________________
  141. Apache 1.3.x on Unix systems
  142. This section contains notes and hints specific to Apache installs of
  143. PHP on Unix platforms. We also have instructions and notes for Apache 2
  144. on a separate page.
  145. You can select arguments to add to the configure on line 10 below from
  146. the list of core configure options and from extension specific options
  147. described at the respective places in the manual. The version numbers
  148. have been omitted here, to ensure the instructions are not incorrect.
  149. You will need to replace the 'xxx' here with the correct values from
  150. your files.
  151. Example #1 Installation Instructions (Apache Shared Module Version) for
  152. PHP
  153. 1. gunzip apache_xxx.tar.gz
  154. 2. tar -xvf apache_xxx.tar
  155. 3. gunzip php-xxx.tar.gz
  156. 4. tar -xvf php-xxx.tar
  157. 5. cd apache_xxx
  158. 6. ./configure --prefix=/www --enable-module=so
  159. 7. make
  160. 8. make install
  161. 9. cd ../php-xxx
  162. 10. Now, configure your PHP. This is where you customize your PHP
  163. with various options, like which extensions will be enabled. Do a
  164. ./configure --help for a list of available options. In our example
  165. we'll do a simple configure with Apache 1 and MySQL support. Your
  166. path to apxs may differ from our example.
  167. ./configure --with-mysql --with-apxs=/www/bin/apxs
  168. 11. make
  169. 12. make install
  170. If you decide to change your configure options after installation,
  171. you only need to repeat the last three steps. You only need to
  172. restart apache for the new module to take effect. A recompile of
  173. Apache is not needed.
  174. Note that unless told otherwise, 'make install' will also install PEAR,
  175. various PHP tools such as phpize, install the PHP CLI, and more.
  176. 13. Setup your php.ini file:
  177. cp php.ini-development /usr/local/lib/php.ini
  178. You may edit your .ini file to set PHP options. If you prefer your
  179. php.ini in another location, use --with-config-file-path=/some/path in
  180. step 10.
  181. If you instead choose php.ini-production, be certain to read the list
  182. of changes within, as they affect how PHP behaves.
  183. 14. Edit your httpd.conf to load the PHP module. The path on the right hand
  184. side of the LoadModule statement must point to the path of the PHP
  185. module on your system. The make install from above may have already
  186. added this for you, but be sure to check.
  187. LoadModule php5_module libexec/libphp5.so
  188. 15. And in the AddModule section of httpd.conf, somewhere under the
  189. ClearModuleList, add this:
  190. AddModule mod_php5.c
  191. 16. Tell Apache to parse certain extensions as PHP. For example,
  192. let's have Apache parse the .php extension as PHP. You could
  193. have any extension(s) parse as PHP by simply adding more, with
  194. each separated by a space. We'll add .phtml to demonstrate.
  195. AddType application/x-httpd-php .php .phtml
  196. It's also common to setup the .phps extension to show highlighted PHP
  197. source, this can be done with:
  198. AddType application/x-httpd-php-source .phps
  199. 17. Use your normal procedure for starting the Apache server. (You must
  200. stop and restart the server, not just cause the server to reload by
  201. using a HUP or USR1 signal.)
  202. Alternatively, to install PHP as a static object:
  203. Example #2 Installation Instructions (Static Module Installation for
  204. Apache) for PHP
  205. 1. gunzip -c apache_1.3.x.tar.gz | tar xf -
  206. 2. cd apache_1.3.x
  207. 3. ./configure
  208. 4. cd ..
  209. 5. gunzip -c php-5.x.y.tar.gz | tar xf -
  210. 6. cd php-5.x.y
  211. 7. ./configure --with-mysql --with-apache=../apache_1.3.x
  212. 8. make
  213. 9. make install
  214. 10. cd ../apache_1.3.x
  215. 11. ./configure --prefix=/www --activate-module=src/modules/php5/libphp5.a
  216. (The above line is correct! Yes, we know libphp5.a does not exist at this
  217. stage. It isn't supposed to. It will be created.)
  218. 12. make
  219. (you should now have an httpd binary which you can copy to your Apache bin d
  220. ir if
  221. it is your first install then you need to "make install" as well)
  222. 13. cd ../php-5.x.y
  223. 14. cp php.ini-development /usr/local/lib/php.ini
  224. 15. You can edit /usr/local/lib/php.ini file to set PHP options.
  225. Edit your httpd.conf or srm.conf file and add:
  226. AddType application/x-httpd-php .php
  227. Depending on your Apache install and Unix variant, there are many
  228. possible ways to stop and restart the server. Below are some typical
  229. lines used in restarting the server, for different apache/unix
  230. installations. You should replace /path/to/ with the path to these
  231. applications on your systems.
  232. Example #3 Example commands for restarting Apache
  233. 1. Several Linux and SysV variants:
  234. /etc/rc.d/init.d/httpd restart
  235. 2. Using apachectl scripts:
  236. /path/to/apachectl stop
  237. /path/to/apachectl start
  238. 3. httpdctl and httpsdctl (Using OpenSSL), similar to apachectl:
  239. /path/to/httpsdctl stop
  240. /path/to/httpsdctl start
  241. 4. Using mod_ssl, or another SSL server, you may want to manually
  242. stop and start:
  243. /path/to/apachectl stop
  244. /path/to/apachectl startssl
  245. The locations of the apachectl and http(s)dctl binaries often vary. If
  246. your system has locate or whereis or which commands, these can assist
  247. you in finding your server control programs.
  248. Different examples of compiling PHP for apache are as follows:
  249. ./configure --with-apxs --with-pgsql
  250. This will create a libphp5.so shared library that is loaded into Apache
  251. using a LoadModule line in Apache's httpd.conf file. The PostgreSQL
  252. support is embedded into this library.
  253. ./configure --with-apxs --with-pgsql=shared
  254. This will create a libphp5.so shared library for Apache, but it will
  255. also create a pgsql.so shared library that is loaded into PHP either by
  256. using the extension directive in php.ini file or by loading it
  257. explicitly in a script using the dl() function.
  258. ./configure --with-apache=/path/to/apache_source --with-pgsql
  259. This will create a libmodphp5.a library, a mod_php5.c and some
  260. accompanying files and copy this into the src/modules/php5 directory in
  261. the Apache source tree. Then you compile Apache using
  262. --activate-module=src/modules/php5/libphp5.a and the Apache build
  263. system will create libphp5.a and link it statically into the httpd
  264. binary. The PostgreSQL support is included directly into this httpd
  265. binary, so the final result here is a single httpd binary that includes
  266. all of Apache and all of PHP.
  267. ./configure --with-apache=/path/to/apache_source --with-pgsql=shared
  268. Same as before, except instead of including PostgreSQL support directly
  269. into the final httpd you will get a pgsql.so shared library that you
  270. can load into PHP from either the php.ini file or directly using dl().
  271. When choosing to build PHP in different ways, you should consider the
  272. advantages and drawbacks of each method. Building as a shared object
  273. will mean that you can compile apache separately, and don't have to
  274. recompile everything as you add to, or change, PHP. Building PHP into
  275. apache (static method) means that PHP will load and run faster. For
  276. more information, see the Apache » web page on DSO support.
  277. Note:
  278. Apache's default httpd.conf currently ships with a section that
  279. looks like this:
  280. User nobody
  281. Group "#-1"
  282. Unless you change that to "Group nogroup" or something like that
  283. ("Group daemon" is also very common) PHP will not be able to open
  284. files.
  285. Note:
  286. Make sure you specify the installed version of apxs when using
  287. --with-apxs=/path/to/apxs . You must NOT use the apxs version that
  288. is in the apache sources but the one that is actually installed on
  289. your system.
  290. __________________________________________________________________
  291. __________________________________________________________________
  292. Apache 2.x on Unix systems
  293. This section contains notes and hints specific to Apache 2.x installs
  294. of PHP on Unix systems.
  295. Warning
  296. We do not recommend using a threaded MPM in production with Apache 2.
  297. Use the prefork MPM, which is the default MPM with Apache 2.0 and 2.2.
  298. For information on why, read the related FAQ entry on using Apache2
  299. with a threaded MPM
  300. The » Apache Documentation is the most authoritative source of
  301. information on the Apache 2.x server. More information about
  302. installation options for Apache may be found there.
  303. The most recent version of Apache HTTP Server may be obtained from »
  304. Apache download site, and a fitting PHP version from the above
  305. mentioned places. This quick guide covers only the basics to get
  306. started with Apache 2.x and PHP. For more information read the » Apache
  307. Documentation. The version numbers have been omitted here, to ensure
  308. the instructions are not incorrect. In the examples below, 'NN' should
  309. be replaced with the specific version of Apache being used.
  310. There are currently two versions of Apache 2.x - there's 2.0 and 2.2.
  311. While there are various reasons for choosing each, 2.2 is the current
  312. latest version, and the one that is recommended, if that option is
  313. available to you. However, the instructions here will work for either
  314. 2.0 or 2.2.
  315. 1. Obtain the Apache HTTP server from the location listed above, and
  316. unpack it:
  317. gzip -d httpd-2_x_NN.tar.gz
  318. tar -xf httpd-2_x_NN.tar
  319. 2. Likewise, obtain and unpack the PHP source:
  320. gunzip php-NN.tar.gz
  321. tar -xf php-NN.tar
  322. 3. Build and install Apache. Consult the Apache install documentation
  323. for more details on building Apache.
  324. cd httpd-2_x_NN
  325. ./configure --enable-so
  326. make
  327. make install
  328. 4. Now you have Apache 2.x.NN available under /usr/local/apache2,
  329. configured with loadable module support and the standard MPM
  330. prefork. To test the installation use your normal procedure for
  331. starting the Apache server, e.g.:
  332. /usr/local/apache2/bin/apachectl start
  333. and stop the server to go on with the configuration for PHP:
  334. /usr/local/apache2/bin/apachectl stop
  335. 5. Now, configure and build PHP. This is where you customize PHP with
  336. various options, like which extensions will be enabled. Run
  337. ./configure --help for a list of available options. In our example
  338. we'll do a simple configure with Apache 2 and MySQL support.
  339. If you built Apache from source, as described above, the below
  340. example will match your path for apxs, but if you installed Apache
  341. some other way, you'll need to adjust the path to apxs accordingly.
  342. Note that some distros may rename apxs to apxs2.
  343. cd ../php-NN
  344. ./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql
  345. make
  346. make install
  347. If you decide to change your configure options after installation,
  348. you'll need to re-run the configure, make, and make install steps.
  349. You only need to restart apache for the new module to take effect.
  350. A recompile of Apache is not needed.
  351. Note that unless told otherwise, 'make install' will also install
  352. PEAR, various PHP tools such as phpize, install the PHP CLI, and
  353. more.
  354. 6. Setup your php.ini
  355. cp php.ini-development /usr/local/lib/php.ini
  356. You may edit your .ini file to set PHP options. If you prefer
  357. having php.ini in another location, use
  358. --with-config-file-path=/some/path in step 5.
  359. If you instead choose php.ini-production, be certain to read the
  360. list of changes within, as they affect how PHP behaves.
  361. 7. Edit your httpd.conf to load the PHP module. The path on the right
  362. hand side of the LoadModule statement must point to the path of the
  363. PHP module on your system. The make install from above may have
  364. already added this for you, but be sure to check.
  365. LoadModule php5_module modules/libphp5.so
  366. 8. Tell Apache to parse certain extensions as PHP. For example, let's
  367. have Apache parse .php files as PHP. Instead of only using the
  368. Apache AddType directive, we want to avoid potentially dangerous
  369. uploads and created files such as exploit.php.jpg from being
  370. executed as PHP. Using this example, you could have any
  371. extension(s) parse as PHP by simply adding them. We'll add .php to
  372. demonstrate.
  373. <FilesMatch \.php$>
  374. SetHandler application/x-httpd-php
  375. </FilesMatch>
  376. Or, if we wanted to allow .php, .php2, .php3, .php4, .php5, .php6,
  377. and .phtml files to be executed as PHP, but nothing else, we'd use
  378. this:
  379. <FilesMatch "\.ph(p[2-6]?|tml)$">
  380. SetHandler application/x-httpd-php
  381. </FilesMatch>
  382. And to allow .phps files to be handled by the php source filter,
  383. and displayed as syntax-highlighted source code, use this:
  384. <FilesMatch "\.phps$">
  385. SetHandler application/x-httpd-php-source
  386. </FilesMatch>
  387. mod_rewrite may be used To allow any arbitrary .php file to be
  388. displayed as syntax-highlighted source code, without having to
  389. rename or copy it to a .phps file:
  390. RewriteEngine On
  391. RewriteRule (.*\.php)s$ $1 [H=application/x-httpd-php-source]
  392. The php source filter should not be enabled on production systems,
  393. where it may expose confidential or otherwise sensitive information
  394. embedded in source code.
  395. 9. Use your normal procedure for starting the Apache server, e.g.:
  396. /usr/local/apache2/bin/apachectl start
  397. OR
  398. service httpd restart
  399. Following the steps above you will have a running Apache2 web server
  400. with support for PHP as a SAPI module. Of course there are many more
  401. configuration options available Apache and PHP. For more information
  402. type ./configure --help in the corresponding source tree.
  403. Apache may be built multithreaded by selecting the worker MPM, rather
  404. than the standard prefork MPM, when Apache is built. This is done by
  405. adding the following option to the argument passed to ./configure, in
  406. step 3 above:
  407. --with-mpm=worker
  408. This should not be undertaken without being aware of the consequences
  409. of this decision, and having at least a fair understanding of the
  410. implications. The Apache documentation regarding » MPM-Modules
  411. discusses MPMs in a great deal more detail.
  412. Note:
  413. The Apache MultiViews FAQ discusses using multiviews with PHP.
  414. Note:
  415. To build a multithreaded version of Apache, the target system must
  416. support threads. In this case, PHP should also be built with
  417. experimental Zend Thread Safety (ZTS). Under this configuration, not
  418. all extensions will be available. The recommended setup is to build
  419. Apache with the default prefork MPM-Module.
  420. __________________________________________________________________
  421. __________________________________________________________________
  422. Lighttpd 1.4 on Unix systems
  423. This section contains notes and hints specific to Lighttpd 1.4 installs
  424. of PHP on Unix systems.
  425. Please use the » Lighttpd trac to learn how to install Lighttpd
  426. properly before continuing.
  427. Fastcgi is the preferred SAPI to connect PHP and Lighttpd. Fastcgi is
  428. automagically enabled in php-cgi in PHP 5.3, but for older versions
  429. configure PHP with --enable-fastcgi. To confirm that PHP has fastcgi
  430. enabled, php -v should contain PHP 5.2.5 (cgi-fcgi) Before PHP 5.2.3,
  431. fastcgi was enabled on the php binary (there was no php-cgi).
  432. Letting Lighttpd spawn php processes
  433. To configure Lighttpd to connect to php and spawn fastcgi processes,
  434. edit lighttpd.conf. Sockets are preferred to connect to fastcgi
  435. processes on the local system.
  436. Example #1 Partial lighttpd.conf
  437. server.modules += ( "mod_fastcgi" )
  438. fastcgi.server = ( ".php" =>
  439. ((
  440. "socket" => "/tmp/php.socket",
  441. "bin-path" => "/usr/local/bin/php-cgi",
  442. "bin-environment" => (
  443. "PHP_FCGI_CHILDREN" => "16",
  444. "PHP_FCGI_MAX_REQUESTS" => "10000"
  445. ),
  446. "min-procs" => 1,
  447. "max-procs" => 1,
  448. "idle-timeout" => 20
  449. ))
  450. )
  451. The bin-path directive allows lighttpd to spawn fastcgi processes
  452. dynamically. PHP will spawn children according to the PHP_FCGI_CHILDREN
  453. environment variable. The "bin-environment" directive sets the
  454. environment for the spawned processes. PHP will kill a child process
  455. after the number of requests specified by PHP_FCGI_MAX_REQUESTS is
  456. reached. The directives "min-procs" and "max-procs" should generally be
  457. avoided with PHP. PHP manages its own children and opcode caches like
  458. APC will only share among children managed by PHP. If "min-procs" is
  459. set to something greater than 1, the total number of php responders
  460. will be multiplied PHP_FCGI_CHILDREN (2 min-procs * 16 children gives
  461. 32 responders).
  462. Spawning with spawn-fcgi
  463. Lighttpd provides a program called spawn-fcgi to ease the process of
  464. spawning fastcgi processes easier.
  465. Spawning php-cgi
  466. It is possible to spawn processes without spawn-fcgi, though a bit of
  467. heavy-lifting is required. Setting the PHP_FCGI_CHILDREN environment
  468. var controls how many children PHP will spawn to handle incoming
  469. requests. Setting PHP_FCGI_MAX_REQUESTS will determine how long (in
  470. requests) each child will live. Here's a simple bash script to help
  471. spawn php responders.
  472. Example #2 Spawning FastCGI Responders
  473. #!/bin/sh
  474. # Location of the php-cgi binary
  475. PHP=/usr/local/bin/php-cgi
  476. # PID File location
  477. PHP_PID=/tmp/php.pid
  478. # Binding to an address
  479. #FCGI_BIND_ADDRESS=10.0.1.1:10000
  480. # Binding to a domain socket
  481. FCGI_BIND_ADDRESS=/tmp/php.sock
  482. PHP_FCGI_CHILDREN=16
  483. PHP_FCGI_MAX_REQUESTS=10000
  484. env -i PHP_FCGI_CHILDREN=$PHP_FCGI_CHILDREN \
  485. PHP_FCGI_MAX_REQUESTS=$PHP_FCGI_MAX_REQUESTS \
  486. $PHP -b $FCGI_BIND_ADDRESS &
  487. echo $! > "$PHP_PID"
  488. Connecting to remote FCGI instances
  489. Fastcgi instances can be spawned on multiple remote machines in order
  490. to scale applications.
  491. Example #3 Connecting to remote php-fastcgi instances
  492. fastcgi.server = ( ".php" =>
  493. (( "host" => "10.0.0.2", "port" => 1030 ),
  494. ( "host" => "10.0.0.3", "port" => 1030 ))
  495. )
  496. __________________________________________________________________
  497. __________________________________________________________________
  498. Sun, iPlanet and Netscape servers on Sun Solaris
  499. This section contains notes and hints specific to Sun Java System Web
  500. Server, Sun ONE Web Server, iPlanet and Netscape server installs of PHP
  501. on Sun Solaris.
  502. From PHP 4.3.3 on you can use PHP scripts with the NSAPI module to
  503. generate custom directory listings and error pages. Additional
  504. functions for Apache compatibility are also available. For support in
  505. current web servers read the note about subrequests.
  506. You can find more information about setting up PHP for the Netscape
  507. Enterprise Server (NES) here: »
  508. http://benoit.noss.free.fr/php/install-php4.html
  509. To build PHP with Sun JSWS/Sun ONE WS/iPlanet/Netscape web servers,
  510. enter the proper install directory for the --with-nsapi=[DIR] option.
  511. The default directory is usually /opt/netscape/suitespot/. Please also
  512. read /php-xxx-version/sapi/nsapi/nsapi-readme.txt.
  513. 1. Install the following packages from » http://www.sunfreeware.com/
  514. or another download site:
  515. + autoconf-2.13
  516. + automake-1.4
  517. + bison-1_25-sol26-sparc-local
  518. + flex-2_5_4a-sol26-sparc-local
  519. + gcc-2_95_2-sol26-sparc-local
  520. + gzip-1.2.4-sol26-sparc-local
  521. + m4-1_4-sol26-sparc-local
  522. + make-3_76_1-sol26-sparc-local
  523. + mysql-3.23.24-beta (if you want mysql support)
  524. + perl-5_005_03-sol26-sparc-local
  525. + tar-1.13 (GNU tar)
  526. 2. Make sure your path includes the proper directories
  527. PATH=.:/usr/local/bin:/usr/sbin:/usr/bin:/usr/ccs/bin and make it
  528. available to your system export PATH.
  529. 3. gunzip php-x.x.x.tar.gz (if you have a .gz dist, otherwise go to
  530. 4).
  531. 4. tar xvf php-x.x.x.tar
  532. 5. Change to your extracted PHP directory: cd ../php-x.x.x
  533. 6. For the following step, make sure /opt/netscape/suitespot/ is where
  534. your netscape server is installed. Otherwise, change to the correct
  535. path and run:
  536. ./configure --with-mysql=/usr/local/mysql \
  537. --with-nsapi=/opt/netscape/suitespot/ \
  538. --enable-libgcc
  539. 7. Run make followed by make install.
  540. After performing the base install and reading the appropriate readme
  541. file, you may need to perform some additional configuration steps.
  542. Configuration Instructions for Sun/iPlanet/Netscape
  543. Firstly you may need to add some paths to the LD_LIBRARY_PATH
  544. environment for the server to find all the shared libs. This can best
  545. done in the start script for your web server. The start script is often
  546. located in: /path/to/server/https-servername/start. You may also need
  547. to edit the configuration files that are located in:
  548. /path/to/server/https-servername/config/.
  549. 1. Add the following line to mime.types (you can do that by the
  550. administration server):
  551. type=magnus-internal/x-httpd-php exts=php
  552. 2. Edit magnus.conf (for servers >= 6) or obj.conf (for servers < 6)
  553. and add the following, shlib will vary depending on your system, it
  554. will be something like /opt/netscape/suitespot/bin/libphp4.so. You
  555. should place the following lines after mime types init.
  556. Init fn="load-modules" funcs="php4_init,php4_execute,php4_auth_trans" shlib="/op
  557. t/netscape/suitespot/bin/libphp4.so"
  558. Init fn="php4_init" LateInit="yes" errorString="Failed to initialize PHP!" [php_
  559. ini="/path/to/php.ini"]
  560. (PHP >= 4.3.3) The php_ini parameter is optional but with it you
  561. can place your php.ini in your web server config directory.
  562. 3. Configure the default object in obj.conf (for virtual server
  563. classes [version 6.0+] in their vserver.obj.conf):
  564. <Object name="default">
  565. .
  566. .
  567. .
  568. .#NOTE this next line should happen after all 'ObjectType' and before all 'AddLo
  569. g' lines
  570. Service fn="php4_execute" type="magnus-internal/x-httpd-php" [inikey=value inike
  571. y=value ...]
  572. .
  573. .
  574. </Object>
  575. (PHP >= 4.3.3) As additional parameters you can add some special
  576. php.ini-values, for example you can set a
  577. docroot="/path/to/docroot" specific to the context php4_execute is
  578. called. For boolean ini-keys please use 0/1 as value, not
  579. "On","Off",... (this will not work correctly), e.g.
  580. zlib.output_compression=1 instead of zlib.output_compression="On"
  581. 4. This is only needed if you want to configure a directory that only
  582. consists of PHP scripts (same like a cgi-bin directory):
  583. <Object name="x-httpd-php">
  584. ObjectType fn="force-type" type="magnus-internal/x-httpd-php"
  585. Service fn=php4_execute [inikey=value inikey=value ...]
  586. </Object>
  587. After that you can configure a directory in the Administration
  588. server and assign it the style x-httpd-php. All files in it will
  589. get executed as PHP. This is nice to hide PHP usage by renaming
  590. files to .html.
  591. 5. Setup of authentication: PHP authentication cannot be used with any
  592. other authentication. ALL AUTHENTICATION IS PASSED TO YOUR PHP
  593. SCRIPT. To configure PHP Authentication for the entire server, add
  594. the following line to your default object:
  595. <Object name="default">
  596. AuthTrans fn=php4_auth_trans
  597. .
  598. .
  599. .
  600. </Object>
  601. 6. To use PHP Authentication on a single directory, add the following:
  602. <Object ppath="d:\path\to\authenticated\dir\*">
  603. AuthTrans fn=php4_auth_trans
  604. </Object>
  605. Note:
  606. The stacksize that PHP uses depends on the configuration of the web
  607. server. If you get crashes with very large PHP scripts, it is
  608. recommended to raise it with the Admin Server (in the section
  609. "MAGNUS EDITOR").
  610. CGI environment and recommended modifications in php.ini
  611. Important when writing PHP scripts is the fact that Sun JSWS/Sun ONE
  612. WS/iPlanet/Netscape is a multithreaded web server. Because of that all
  613. requests are running in the same process space (the space of the web
  614. server itself) and this space has only one environment. If you want to
  615. get CGI variables like PATH_INFO, HTTP_HOST etc. it is not the correct
  616. way to try this in the old PHP way with getenv() or a similar way
  617. (register globals to environment, $_ENV). You would only get the
  618. environment of the running web server without any valid CGI variables!
  619. Note:
  620. Why are there (invalid) CGI variables in the environment?
  621. Answer: This is because you started the web server process from the
  622. admin server which runs the startup script of the web server, you
  623. wanted to start, as a CGI script (a CGI script inside of the admin
  624. server!). This is why the environment of the started web server has
  625. some CGI environment variables in it. You can test this by starting
  626. the web server not from the administration server. Use the command
  627. line as root user and start it manually - you will see there are no
  628. CGI-like environment variables.
  629. Simply change your scripts to get CGI variables in the correct way for
  630. PHP 4.x by using the superglobal $_SERVER. If you have older scripts
  631. which use $HTTP_HOST, etc., you should turn on register_globals in
  632. php.ini and change the variable order too (important: remove "E" from
  633. it, because you do not need the environment here):
  634. variables_order = "GPCS"
  635. register_globals = On
  636. Special use for error pages or self-made directory listings (PHP >= 4.3.3)
  637. You can use PHP to generate the error pages for "404 Not Found" or
  638. similar. Add the following line to the object in obj.conf for every
  639. error page you want to overwrite:
  640. Error fn="php4_execute" code=XXX script="/path/to/script.php" [inikey=value inik
  641. ey=value...]
  642. where XXX is the HTTP error code. Please delete any other Error
  643. directives which could interfere with yours. If you want to place a
  644. page for all errors that could exist, leave the code parameter out.
  645. Your script can get the HTTP status code with $_SERVER['ERROR_TYPE'].
  646. Another possibility is to generate self-made directory listings. Just
  647. create a PHP script which displays a directory listing and replace the
  648. corresponding default Service line for type="magnus-internal/directory"
  649. in obj.conf with the following:
  650. Service fn="php4_execute" type="magnus-internal/directory" script="/path/to/scri
  651. pt.php" [inikey=value inikey=value...]
  652. For both error and directory listing pages the original URI and
  653. translated URI are in the variables $_SERVER['PATH_INFO'] and
  654. $_SERVER['PATH_TRANSLATED'].
  655. Note about nsapi_virtual() and subrequests (PHP >= 4.3.3)
  656. The NSAPI module now supports the nsapi_virtual() function (alias:
  657. virtual()) to make subrequests on the web server and insert the result
  658. in the web page. This function uses some undocumented features from the
  659. NSAPI library. On Unix the module automatically looks for the needed
  660. functions and uses them if available. If not, nsapi_virtual() is
  661. disabled.
  662. Note:
  663. But be warned: Support for nsapi_virtual() is EXPERIMENTAL!!!
  664. __________________________________________________________________
  665. __________________________________________________________________
  666. CGI and command line setups
  667. By default, PHP is built as both a CLI and CGI program, which can be
  668. used for CGI processing. If you are running a web server that PHP has
  669. module support for, you should generally go for that solution for
  670. performance reasons. However, the CGI version enables users to run
  671. different PHP-enabled pages under different user-ids.
  672. Warning
  673. A server deployed in CGI mode is open to several possible
  674. vulnerabilities. Please read our CGI security section to learn how to
  675. defend yourself from such attacks.
  676. Testing
  677. If you have built PHP as a CGI program, you may test your build by
  678. typing make test. It is always a good idea to test your build. This way
  679. you may catch a problem with PHP on your platform early instead of
  680. having to struggle with it later.
  681. Using Variables
  682. Some server supplied environment variables are not defined in the
  683. current » CGI/1.1 specification. Only the following variables are
  684. defined there: AUTH_TYPE, CONTENT_LENGTH, CONTENT_TYPE,
  685. GATEWAY_INTERFACE, PATH_INFO, PATH_TRANSLATED, QUERY_STRING,
  686. REMOTE_ADDR, REMOTE_HOST, REMOTE_IDENT, REMOTE_USER, REQUEST_METHOD,
  687. SCRIPT_NAME, SERVER_NAME, SERVER_PORT, SERVER_PROTOCOL, and
  688. SERVER_SOFTWARE. Everything else should be treated as 'vendor
  689. extensions'.
  690. __________________________________________________________________
  691. __________________________________________________________________
  692. HP-UX specific installation notes
  693. This section contains notes and hints specific to installing PHP on
  694. HP-UX systems.
  695. There are two main options for installing PHP on HP-UX systems. Either
  696. compile it, or install a pre-compiled binary.
  697. Official pre-compiled packages are located here: »
  698. http://software.hp.com/
  699. Until this manual section is rewritten, the documentation about
  700. compiling PHP (and related extensions) on HP-UX systems has been
  701. removed. For now, consider reading the following external resource: »
  702. Building Apache and PHP on HP-UX 11.11
  703. __________________________________________________________________
  704. __________________________________________________________________
  705. OpenBSD installation notes
  706. This section contains notes and hints specific to installing PHP on »
  707. OpenBSD 3.6.
  708. Using Binary Packages
  709. Using binary packages to install PHP on OpenBSD is the recommended and
  710. simplest method. The core package has been separated from the various
  711. modules, and each can be installed and removed independently from the
  712. others. The files you need can be found on your OpenBSD CD or on the
  713. FTP site.
  714. The main package you need to install is php4-core-4.3.8.tgz, which
  715. contains the basic engine (plus gettext and iconv). Next, take a look
  716. at the module packages, such as php4-mysql-4.3.8.tgz or
  717. php4-imap-4.3.8.tgz. You need to use the phpxs command to activate and
  718. deactivate these modules in your php.ini.
  719. Example #1 OpenBSD Package Install Example
  720. # pkg_add php4-core-4.3.8.tgz
  721. # /usr/local/sbin/phpxs -s
  722. # cp /usr/local/share/doc/php4/php.ini-recommended /var/www/conf/php.ini
  723. (add in mysql)
  724. # pkg_add php4-mysql-4.3.8.tgz
  725. # /usr/local/sbin/phpxs -a mysql
  726. (add in imap)
  727. # pkg_add php4-imap-4.3.8.tgz
  728. # /usr/local/sbin/phpxs -a imap
  729. (remove mysql as a test)
  730. # pkg_delete php4-mysql-4.3.8
  731. # /usr/local/sbin/phpxs -r mysql
  732. (install the PEAR libraries)
  733. # pkg_add php4-pear-4.3.8.tgz
  734. Read the » packages(7) manual page for more information about binary
  735. packages on OpenBSD.
  736. Using Ports
  737. You can also compile up PHP from source using the » ports tree.
  738. However, this is only recommended for users familiar with OpenBSD. The
  739. PHP 4 port is split into two sub-directories: core and extensions. The
  740. extensions directory generates sub-packages for all of the supported
  741. PHP modules. If you find you do not want to create some of these
  742. modules, use the no_* FLAVOR. For example, to skip building the imap
  743. module, set the FLAVOR to no_imap.
  744. Common Problems
  745. * The default install of Apache runs inside a » chroot(2) jail, which
  746. will restrict PHP scripts to accessing files under /var/www. You
  747. will therefore need to create a /var/www/tmp directory for PHP
  748. session files to be stored, or use an alternative session backend.
  749. In addition, database sockets need to be placed inside the jail or
  750. listen on the localhost interface. If you use network functions,
  751. some files from /etc such as /etc/resolv.conf and /etc/services
  752. will need to be moved into /var/www/etc. The OpenBSD PEAR package
  753. automatically installs into the correct chroot directories, so no
  754. special modification is needed there. More information on the
  755. OpenBSD Apache is available in the » OpenBSD FAQ.
  756. * The OpenBSD 3.6 package for the » gd extension requires XFree86 to
  757. be installed. If you do not wish to use some of the font features
  758. that require X11, install the php4-gd-4.3.8-no_x11.tgz package
  759. instead.
  760. Older Releases
  761. Older releases of OpenBSD used the FLAVORS system to compile up a
  762. statically linked PHP. Since it is hard to generate binary packages
  763. using this method, it is now deprecated. You can still use the old
  764. stable ports trees if you wish, but they are unsupported by the OpenBSD
  765. team. If you have any comments about this, the current maintainer for
  766. the port is Anil Madhavapeddy (avsm at openbsd dot org).
  767. __________________________________________________________________
  768. __________________________________________________________________
  769. Solaris specific installation tips
  770. This section contains notes and hints specific to installing PHP on
  771. Solaris systems.
  772. Required software
  773. Solaris installs often lack C compilers and their related tools. Read
  774. this FAQ for information on why using GNU versions for some of these
  775. tools is necessary. The required software is as follows:
  776. * gcc (recommended, other C compilers may work)
  777. * make
  778. * flex
  779. * bison
  780. * m4
  781. * autoconf
  782. * automake
  783. * perl
  784. * gzip
  785. * tar
  786. * GNU sed
  787. In addition, you will need to install (and possibly compile) any
  788. additional software specific to your configuration, such as Oracle or
  789. MySQL.
  790. Using Packages
  791. You can simplify the Solaris install process by using pkgadd to install
  792. most of your needed components.
  793. __________________________________________________________________
  794. __________________________________________________________________
  795. Debian GNU/Linux installation notes
  796. This section contains notes and hints specific to installing PHP on »
  797. Debian GNU/Linux.
  798. Warning
  799. Unofficial builds from third-parties are not supported here. Any bugs
  800. should be reported to the Debian team unless they can be reproduced
  801. using the latest builds from our » download area.
  802. While the instructions for building PHP on Unix apply to Debian as
  803. well, this manual page contains specific information for other options,
  804. such as using either the apt-get or aptitude commands. This manual page
  805. uses these two commands interchangeably.
  806. Using APT
  807. First, note that other related packages may be desired like
  808. libapache2-mod-php5 to integrate with Apache 2, and php-pear for PEAR.
  809. Second, before installing a package, it's wise to ensure the package
  810. list is up to date. Typically, this is done by running the command
  811. apt-get update.
  812. Example #1 Debian Install Example with Apache 2
  813. # apt-get install php5-common libapache2-mod-php5 php5-cli
  814. APT will automatically install the PHP 5 module for Apache 2 and all of
  815. its dependencies, and then activate it. Apache should be restarted in
  816. order for the changes take place. For example:
  817. Example #2 Stopping and starting Apache once PHP is installed
  818. # /etc/init.d/apache2 stop
  819. # /etc/init.d/apache2 start
  820. Better control of configuration
  821. In the last section, PHP was installed with only core modules. It's
  822. very likely that additional modules will be desired, such as MySQL,
  823. cURL, GD, etc. These may also be installed via the apt-get command.
  824. Example #3 Methods for listing additional PHP 5 packages
  825. # apt-cache search php5
  826. # aptitude search php5
  827. # aptitude search php5 |grep -i mysql
  828. The examples will show a lot of packages including several PHP specific
  829. ones like php5-cgi, php5-cli and php5-dev. Determine which are needed
  830. and install them like any other with either apt-get or aptitude. And
  831. because Debian performs dependency checks, it'll prompt for those so
  832. for example to install MySQL and cURL:
  833. Example #4 Install PHP with MySQL, cURL
  834. # apt-get install php5-mysql php5-curl
  835. APT will automatically add the appropriate lines to the different
  836. php.ini related files like /etc/php5/apache2/php.ini,
  837. /etc/php5/conf.d/pdo.ini, etc. and depending on the extension will add
  838. entries similar to extension=foo.so. However, restarting the web server
  839. (like Apache) is required before these changes take affect.
  840. Common Problems
  841. * If the PHP scripts are not parsing via the web server, then it's
  842. likely that PHP was not added to the web server's configuration
  843. file, which on Debian may be /etc/apache2/apache2.conf or similar.
  844. See the Debian manual for further details.
  845. * If an extension was seemingly installed yet the functions are
  846. undefined, be sure that the appropriate ini file is being loaded
  847. and/or the web server was restarted after installation.
  848. * There are two basic commands for installing packages on Debian (and
  849. other linux variants): apt-get and aptitude. However, explaining
  850. the subtle differences between these commands goes beyond the scope
  851. of this manual.
  852. __________________________________________________________________
  853. __________________________________________________________________
  854. __________________________________________________________________
  855. Installation on Mac OS X
  856. Table of Contents
  857. * Using Packages
  858. * Using the bundled PHP
  859. * Compiling PHP on Mac OS X
  860. This section contains notes and hints specific to installing PHP on Mac
  861. OS X. PHP is bundled with Macs, and compiling is similar to the Unix
  862. installation guide.
  863. __________________________________________________________________
  864. Using Packages
  865. There are a few pre-packaged and pre-compiled versions of PHP for Mac
  866. OS X. This can help in setting up a standard configuration, but if you
  867. need to have a different set of features (such as a secure server, or a
  868. different database driver), you may need to build PHP and/or your web
  869. server yourself. If you are unfamiliar with building and compiling your
  870. own software, it's worth checking whether somebody has already built a
  871. packaged version of PHP with the features you need.
  872. The following resources offer easy to install packages and precompiled
  873. binaries for PHP on Mac OS:
  874. * MacPorts: » http://www.macports.org/
  875. * Entropy: » http://www.entropy.ch/software/macosx/php/
  876. * Fink: » http://www.finkproject.org/
  877. * Homebrew: » http://github.com/mxcl/homebrew
  878. __________________________________________________________________
  879. __________________________________________________________________
  880. Using the bundled PHP
  881. PHP has come standard with Macs since OS X version 10.0.0. Enabling PHP
  882. with the default web server requires uncommenting a few lines in the
  883. Apache configuration file httpd.conf whereas the CGI and/or CLI are
  884. enabled by default (easily accessible via the Terminal program).
  885. Enabling PHP using the instructions below is meant for quickly setting
  886. up a local development environment. It's highly recommended to always
  887. upgrade PHP to the newest version. Like most live software, newer
  888. versions are created to fix bugs and add features and PHP being is no
  889. different. See the appropriate MAC OS X installation documentation for
  890. further details. The following instructions are geared towards a
  891. beginner with details provided for getting a default setup to work. All
  892. users are encouraged to compile, or install a new packaged version.
  893. The standard installation type is using mod_php, and enabling the
  894. bundled mod_php on Mac OS X for the Apache web server (the default web
  895. server, that is accessible via System Preferences) involves the
  896. following steps:
  897. 1. Locate and open the Apache configuration file. By default, the
  898. location is as follows: /private/etc/apache2/httpd.conf Using
  899. Finder or Spotlight to find this file may prove difficult as by
  900. default it's private and owned by the root user.
  901. Note: One way to open this is by using a Unix based text editor in
  902. the Terminal, for example nano, and because the file is owned by
  903. root we'll use the sudo command to open it (as root) so for example
  904. type the following into the Terminal Application (after, it will
  905. prompt for a password): sudo nano /private/etc/apache2/httpd.conf
  906. Noteworthy nano commands: ^w (search), ^o (save), and ^x (exit)
  907. where ^ represents the Ctrl key.
  908. Note: Versions of Mac OS X prior to 10.5 were bundled with older
  909. versions of PHP and Apache. As such, the Apache configuration file
  910. on legacy machines may be /etc/httpd/httpd.conf.
  911. 2. With a text editor, uncomment the lines (by removing the #) that
  912. look similar to the following (these two lines are often not
  913. together, locate them both in the file):
  914. # LoadModule php5_module libexec/httpd/libphp5.so
  915. # AddModule mod_php5.c
  916. Notice the location/path. When building PHP in the future, the
  917. above files should be replaced or commented out.
  918. 3. Be sure the desired extensions will parse as PHP (examples: .php
  919. .html and .inc)
  920. Due to the following statement already existing in httpd.conf (as
  921. of Mac Panther), once PHP is enabled the .php files will
  922. automatically parse as PHP.
  923. <IfModule mod_php5.c>
  924. # If php is turned on, we respect .php and .phps files.
  925. AddType application/x-httpd-php .php
  926. AddType application/x-httpd-php-source .phps
  927. # Since most users will want index.php to work we
  928. # also automatically enable index.php
  929. <IfModule mod_dir.c>
  930. DirectoryIndex index.html index.php
  931. </IfModule>
  932. </IfModule>
  933. Note:
  934. Before OS X 10.5 (Leopard), PHP 4 was bundled instead of PHP 5 in
  935. which case the above instructions will differ slightly by changing
  936. 5's to 4's.
  937. 4. Be sure the DirectoryIndex loads the desired default index file
  938. This is also set in httpd.conf. Typically index.php and index.html
  939. are used. By default index.php is enabled because it's also in the
  940. PHP check shown above. Adjust accordingly.
  941. 5. Set the php.ini location or use the default A typical default
  942. location on Mac OS X is /usr/local/php/php.ini and a call to
  943. phpinfo() will reveal this information. If a php.ini is not used,
  944. PHP will use all default values. See also the related FAQ on
  945. finding php.ini.
  946. 6. Locate or set the DocumentRoot This is the root directory for all
  947. the web files. Files in this directory are served from the web
  948. server so the PHP files will parse as PHP before outputting them to
  949. the browser. A typical default path is /Library/WebServer/Documents
  950. but this can be set to anything in httpd.conf. Alternatively, the
  951. default DocumentRoot for individual users is
  952. /Users/yourusername/Sites
  953. 7. Create a phpinfo() file
  954. The phpinfo() function will display information about PHP. Consider
  955. creating a file in the DocumentRoot with the following PHP code:
  956. <?php phpinfo(); ?>
  957. 8. Restart Apache, and load the PHP file created above To restart,
  958. either execute sudo apachectl graceful in the shell or stop/start
  959. the "Personal Web Server" option in the OS X System Preferences. By
  960. default, loading local files in the browser will have an URL like
  961. so: http://localhost/info.php Or using the DocumentRoot in the user
  962. directory is another option and would end up looking like:
  963. http://localhost/~yourusername/info.php
  964. The CLI (or CGI in older versions) is appropriately named php and
  965. likely exists as /usr/bin/php. Open up the terminal, read the command
  966. line section of the PHP manual, and execute php -v to check the PHP
  967. version of this PHP binary. A call to phpinfo() will also reveal this
  968. information.
  969. __________________________________________________________________
  970. __________________________________________________________________
  971. Compiling PHP on Mac OS X
  972. Use the Unix installation guide to compile PHP on Mac OS X.
  973. __________________________________________________________________
  974. __________________________________________________________________
  975. __________________________________________________________________
  976. Installation of PECL extensions
  977. Table of Contents
  978. * Introduction to PECL Installations
  979. * Downloading PECL extensions
  980. * Installing a PHP extension on Windows
  981. * Compiling shared PECL extensions with the pecl command
  982. * Compiling shared PECL extensions with phpize
  983. * Compiling PECL extensions statically into PHP
  984. __________________________________________________________________
  985. Introduction to PECL Installations
  986. » PECL is a repository of PHP extensions that are made available to you
  987. via the » PEAR packaging system. This section of the manual is intended
  988. to demonstrate how to obtain and install PECL extensions.
  989. These instructions assume /your/phpsrcdir/ is the path to the PHP
  990. source distribution, and that extname is the name of the PECL
  991. extension. Adjust accordingly. These instructions also assume a
  992. familiarity with the » pear command. The information in the PEAR manual
  993. for the pear command also applies to the pecl command.
  994. To be useful, a shared extension must be built, installed, and loaded.
  995. The methods described below provide you with various instructions on
  996. how to build and install the extensions, but they do not automatically
  997. load them. Extensions can be loaded by adding an extension directive.
  998. To this php.ini file, or through the use of the dl() function.
  999. When building PHP modules, it's important to have known-good versions
  1000. of the required tools (autoconf, automake, libtool, etc.) See the »
  1001. Anonymous SVN Instructions for details on the required tools, and
  1002. required versions.
  1003. __________________________________________________________________
  1004. __________________________________________________________________
  1005. Downloading PECL extensions
  1006. There are several options for downloading PECL extensions, such as:
  1007. * The pecl install extname command downloads the extensions code
  1008. automatically, so in this case there is no need for a separate
  1009. download.
  1010. * » http://pecl.php.net/ The PECL web site contains information about
  1011. the different extensions that are offered by the PHP Development
  1012. Team. The information available here includes: ChangeLog, release
  1013. notes, requirements and other similar details.
  1014. * pecl download extname PECL extensions that have releases listed on
  1015. the PECL web site are available for download and installation using
  1016. the » pecl command. Specific revisions may also be specified.
  1017. * SVN Most PECL extensions also reside in SVN. A web-based view may
  1018. be seen at » http://svn.php.net/viewvc/pecl/. To download straight
  1019. from SVN, the following sequence of commands may be used:
  1020. $ svn checkout http://svn.php.net/repository/pecl/extname/trunk
  1021. extname
  1022. * Windows downloads At this time the PHP project does not compile
  1023. Windows binaries for PECL extensions. However, to compile PHP under
  1024. Windows see the chapter titled building PHP for Windows.
  1025. __________________________________________________________________
  1026. __________________________________________________________________
  1027. Installing a PHP extension on Windows
  1028. On Windows, you have two ways to load a PHP extension: either compile
  1029. it into PHP, or load the DLL. Loading a pre-compiled extension is the
  1030. easiest and preferred way.
  1031. To load an extension, you need to have it available as a ".dll" file on
  1032. your system. All the extensions are automatically and periodically
  1033. compiled by the PHP Group (see next section for the download).
  1034. To compile an extension into PHP, please refer to building from source
  1035. documentation.
  1036. To compile a standalone extension (aka a DLL file), please refer to
  1037. building from source documentation. If the DLL file is available
  1038. neither with your PHP distribution nor in PECL, you may have to compile
  1039. it before you can start using the extension.
  1040. Where to find an extension?
  1041. PHP extensions are usually called "php_*.dll" (where the star
  1042. represents the name of the extension) and they are located under the
  1043. "PHP\ext" ("PHP\extensions" in PHP4) folder.
  1044. PHP ships with the extensions most useful to the majority of
  1045. developers. They are called "core" extensions.
  1046. However, if you need functionality not provided by any core extension,
  1047. you may still be able to find one in PECL. The PHP Extension Community
  1048. Library (PECL) is a repository for PHP Extensions, providing a
  1049. directory of all known extensions and hosting facilities for
  1050. downloading and development of PHP extensions.
  1051. If you have developed an extension for your own uses, you might want to
  1052. think about hosting it on PECL so that others with the same needs can
  1053. benefit from your time. A nice side effect is that you give them a good
  1054. chance to give you feedback, (hopefully) thanks, bug reports and even
  1055. fixes/patches. Before you submit your extension for hosting on PECL,
  1056. please read http://pecl.php.net/package-new.php.
  1057. Which extension to download?
  1058. Many times, you will find several versions of each DLL:
  1059. * Different version numbers (at least the first two numbers should
  1060. match)
  1061. * Different thread safety settings
  1062. * Different processor architecture (x86, x64, ...)
  1063. * Different debugging settings
  1064. * etc.
  1065. You should keep in mind that your extension settings should match all
  1066. the settings of the PHP executable you are using. The following PHP
  1067. script will tell you all about your PHP settings:
  1068. Example #1 phpinfo() call
  1069. <?php
  1070. phpinfo();
  1071. ?>
  1072. Or from the command line, run:
  1073. drive:\\path\to\php\executable\php.exe -i
  1074. Loading an extension
  1075. The most common way to load a PHP extension is to include it in your
  1076. php.ini configuration file. Please note that many extensions are
  1077. already present in your php.ini and that you only need to remove the
  1078. semicolon to activate them.
  1079. ;extension=php_extname.dll
  1080. extension=php_extname.dll
  1081. However, some web servers are confusing because they do not use the
  1082. php.ini located alongside your PHP executable. To find out where your
  1083. actual php.ini resides, look for its path in phpinfo():
  1084. Configuration File (php.ini) Path C:\WINDOWS
  1085. Loaded Configuration File C:\Program Files\PHP\5.2\php.ini
  1086. After activating an extension, save php.ini, restart the web server and
  1087. check phpinfo() again. The new extension should now have its own
  1088. section.
  1089. Resolving problems
  1090. If the extension does not appear in phpinfo(), you should check your
  1091. logs to learn where the problem comes from.
  1092. If you are using PHP from the command line (CLI), the extension loading
  1093. error can be read directly on screen.
  1094. If you are using PHP with a web server, the location and format of the
  1095. logs vary depending on your software. Please read your web server
  1096. documentation to locate the logs, as it does not have anything to do
  1097. with PHP itself.
  1098. Common problems are the location of the DLL, the value of the "
  1099. extension_dir" setting inside php.ini and compile-time setting
  1100. mismatches.
  1101. If the problem lies in a compile-time setting mismatch, you probably
  1102. didn't download the right DLL. Try downloading again the extension with
  1103. the right settings. Again, phpinfo() can be of great help.
  1104. __________________________________________________________________
  1105. __________________________________________________________________
  1106. Compiling shared PECL extensions with the pecl command
  1107. PECL makes it easy to create shared PHP extensions. Using the » pecl
  1108. command, do the following:
  1109. $ pecl install extname
  1110. This will download the source for extname, compile, and install
  1111. extname.so into your extension_dir. extname.so may then be loaded via
  1112. php.ini
  1113. By default, the pecl command will not install packages that are marked
  1114. with the alpha or beta state. If no stable packages are available, you
  1115. may install a beta package using the following command:
  1116. $ pecl install extname-beta
  1117. You may also install a specific version using this variant:
  1118. $ pecl install extname-0.1
  1119. Note:
  1120. After enabling the extension in php.ini, restarting the web service
  1121. is required for the changes to be picked up.
  1122. __________________________________________________________________
  1123. __________________________________________________________________
  1124. Compiling shared PECL extensions with phpize
  1125. Sometimes, using the pecl installer is not an option. This could be
  1126. because you're behind a firewall, or it could be because the extension
  1127. you want to install is not available as a PECL compatible package, such
  1128. as unreleased extensions from SVN. If you need to build such an
  1129. extension, you can use the lower-level build tools to perform the build
  1130. manually.
  1131. The phpize command is used to prepare the build environment for a PHP
  1132. extension. In the following sample, the sources for an extension are in
  1133. a directory named extname:
  1134. $ cd extname
  1135. $ phpize
  1136. $ ./configure
  1137. $ make
  1138. # make install
  1139. A successful install will have created extname.so and put it into the
  1140. PHP extensions directory. You'll need to and adjust php.ini and add an
  1141. extension=extname.so line before you can use the extension.
  1142. If the system is missing the phpize command, and precompiled packages
  1143. (like RPM's) are used, be sure to also install the appropriate devel
  1144. version of the PHP package as they often include the phpize command
  1145. along with the appropriate header files to build PHP and its
  1146. extensions.
  1147. Execute phpize --help to display additional usage information.
  1148. __________________________________________________________________
  1149. __________________________________________________________________
  1150. Compiling PECL extensions statically into PHP
  1151. You might find that you need to build a PECL extension statically into
  1152. your PHP binary. To do this, you'll need to place the extension source
  1153. under the php-src/ext/ directory and tell the PHP build system to
  1154. regenerate its configure script.
  1155. $ cd /your/phpsrcdir/ext
  1156. $ pecl download extname
  1157. $ gzip -d < extname.tgz | tar -xvf -
  1158. $ mv extname-x.x.x extname
  1159. This will result in the following directory:
  1160. /your/phpsrcdir/ext/extname
  1161. From here, force PHP to rebuild the configure script, and then build
  1162. PHP as normal:
  1163. $ cd /your/phpsrcdir
  1164. $ rm configure
  1165. $ ./buildconf --force
  1166. $ ./configure --help
  1167. $ ./configure --with-extname --enable-someotherext --with-foobar
  1168. $ make
  1169. $ make install
  1170. Note: To run the 'buildconf' script you need autoconf 2.13 and
  1171. automake 1.4+ (newer versions of autoconf may work, but are not
  1172. supported).
  1173. Whether --enable-extname or --with-extname is used depends on the
  1174. extension. Typically an extension that does not require external
  1175. libraries uses --enable. To be sure, run the following after buildconf:
  1176. $ ./configure --help | grep extname
  1177. __________________________________________________________________
  1178. __________________________________________________________________
  1179. __________________________________________________________________
  1180. Problems?
  1181. Table of Contents
  1182. * Read the FAQ
  1183. * Other problems
  1184. * Bug reports
  1185. __________________________________________________________________
  1186. Read the FAQ
  1187. Some problems are more common than others. The most common ones are
  1188. listed in the PHP FAQ, part of this manual.
  1189. __________________________________________________________________
  1190. __________________________________________________________________
  1191. Other problems
  1192. If you are still stuck, someone on the PHP installation mailing list
  1193. may be able to help you. You should check out the archive first, in
  1194. case someone already answered someone else who had the same problem as
  1195. you. The archives are available from the support page on »
  1196. http://www.php.net/support.php. To subscribe to the PHP installation
  1197. mailing list, send an empty mail to »
  1198. php-install-subscribe@lists.php.net. The mailing list address is »
  1199. php-install@lists.php.net.
  1200. If you want to get help on the mailing list, please try to be precise
  1201. and give the necessary details about your environment (which operating
  1202. system, what PHP version, what web server, if you are running PHP as
  1203. CGI or a server module, safe mode, etc.), and preferably enough code to
  1204. make others able to reproduce and test your problem.
  1205. __________________________________________________________________
  1206. __________________________________________________________________
  1207. Bug reports
  1208. If you think you have found a bug in PHP, please report it. The PHP
  1209. developers probably don't know about it, and unless you report it,
  1210. chances are it won't be fixed. You can report bugs using the
  1211. bug-tracking system at » http://bugs.php.net/. Please do not send bug
  1212. reports in mailing list or personal letters. The bug system is also
  1213. suitable to submit feature requests.
  1214. Read the » How to report a bug document before submitting any bug
  1215. reports!
  1216. __________________________________________________________________
  1217. __________________________________________________________________
  1218. __________________________________________________________________
  1219. Runtime Configuration
  1220. Table of Contents
  1221. * The configuration file
  1222. * .user.ini files
  1223. * Where a configuration setting may be set
  1224. * How to change configuration settings
  1225. __________________________________________________________________
  1226. The configuration file
  1227. The configuration file (php.ini) is read when PHP starts up. For the
  1228. server module versions of PHP, this happens only once when the web
  1229. server is started. For the CGI and CLI version, it happens on every
  1230. invocation.
  1231. php.ini is searched in these locations (in order):
  1232. * SAPI module specific location (PHPIniDir directive in Apache 2, -c
  1233. command line option in CGI and CLI, php_ini parameter in NSAPI,
  1234. PHP_INI_PATH environment variable in THTTPD)
  1235. * The PHPRC environment variable. Before PHP 5.2.0 this was checked
  1236. after the registry key mentioned below.
  1237. * As of PHP 5.2.0, the location of the php.ini file can be set for
  1238. different versions of PHP. The following registry keys are examined
  1239. in order: [HKEY_LOCAL_MACHINE\SOFTWARE\PHP\x.y.z],
  1240. [HKEY_LOCAL_MACHINE\SOFTWARE\PHP\x.y] and
  1241. [HKEY_LOCAL_MACHINE\SOFTWARE\PHP\x], where x, y and z mean the PHP
  1242. major, minor and release versions. If there is a value for
  1243. IniFilePath in these keys, then the first one found will be used as
  1244. the location of the php.ini (Windows only).
  1245. * [HKEY_LOCAL_MACHINE\SOFTWARE\PHP], value of IniFilePath (Windows
  1246. only).
  1247. * Current working directory (except CLI)
  1248. * The web server's directory (for SAPI modules), or directory of PHP
  1249. (otherwise in Windows)
  1250. * Windows directory (C:\windows or C:\winnt) (for Windows), or
  1251. --with-config-file-path compile time option
  1252. If php-SAPI.ini exists (where SAPI is used SAPI, so the filename is
  1253. e.g. php-cli.ini or php-apache.ini), it's used instead of php.ini. SAPI
  1254. name can be determined by php_sapi_name().
  1255. Note:
  1256. The Apache web server changes the directory to root at startup
  1257. causing PHP to attempt to read php.ini from the root filesystem if
  1258. it exists.
  1259. The php.ini directives handled by extensions are documented
  1260. respectively on the pages of the extensions themselves. The list of the
  1261. core directives is available in the appendix. Probably not all PHP
  1262. directives are documented in the manual though. For a complete list of
  1263. directives available in your PHP version, please read your well
  1264. commented php.ini file. Alternatively, you may find the » the latest
  1265. php.ini from SVN helpful too.
  1266. Example #1 php.ini example
  1267. ; any text on a line after an unquoted semicolon (;) is ignored
  1268. [php] ; section markers (text within square brackets) are also ignored
  1269. ; Boolean values can be set to either:
  1270. ; true, on, yes
  1271. ; or false, off, no, none
  1272. register_globals = off
  1273. track_errors = yes
  1274. ; you can enclose strings in double-quotes
  1275. include_path = ".:/usr/local/lib/php"
  1276. ; backslashes are treated the same as any other character
  1277. include_path = ".;c:\php\lib"
  1278. Since PHP 5.1.0, it is possible to refer to existing .ini variables
  1279. from within .ini files. Example: open_basedir = ${open_basedir}
  1280. ":/new/dir".
  1281. __________________________________________________________________
  1282. __________________________________________________________________
  1283. .user.ini files
  1284. Since PHP 5.3.0, PHP includes support for .htaccess-style INI files on
  1285. a per-directory basis. These files are processed only by the
  1286. CGI/FastCGI SAPI. This functionality obsoletes the PECL htscanner
  1287. extension. If you are using Apache, use .htaccess files for the same
  1288. effect.
  1289. In addition to the main php.ini file, PHP scans for INI files in each
  1290. directory, starting with the directory of the requested PHP file, and
  1291. working its way up to the current document root (as set in
  1292. $_SERVER['DOCUMENT_ROOT']). In case the PHP file is outside the
  1293. document root, only its directory is scanned.
  1294. Only INI settings with the modes PHP_INI_PERDIR and PHP_INI_USER will
  1295. be recognized in .user.ini-style INI files.
  1296. Two new INI directives, user_ini.filename and user_ini.cache_ttl
  1297. control the use of user INI files.
  1298. user_ini.filename sets the name of the file PHP looks for in each
  1299. directory; if set to an empty string, PHP doesn't scan at all. The
  1300. default is .user.ini.
  1301. user_ini.cache_ttl controls how often user INI files are re-read. The
  1302. default is 300 seconds (5 minutes).
  1303. __________________________________________________________________
  1304. __________________________________________________________________
  1305. Where a configuration setting may be set
  1306. These modes determine when and where a PHP directive may or may not be
  1307. set, and each directive within the manual refers to one of these modes.
  1308. For example, some settings may be set within a PHP script using
  1309. ini_set(), whereas others may require php.ini or httpd.conf.
  1310. For example, the output_buffering setting is PHP_INI_PERDIR therefore
  1311. it may not be set using ini_set(). However, the display_errors
  1312. directive is PHP_INI_ALL therefore it may be set anywhere, including
  1313. with ini_set().
  1314. CAPTION: Definition of PHP_INI_* modes
  1315. Mode Value Meaning
  1316. PHP_INI_USER 1 Entry can be set in user scripts (like with ini_set())
  1317. or in the Windows registry
  1318. PHP_INI_PERDIR 6 Entry can be set in php.ini, .htaccess or httpd.conf
  1319. PHP_INI_SYSTEM 4 Entry can be set in php.ini or httpd.conf
  1320. PHP_INI_ALL 7 Entry can be set anywhere
  1321. __________________________________________________________________
  1322. __________________________________________________________________
  1323. How to change configuration settings
  1324. Running PHP as an Apache module
  1325. When using PHP as an Apache module, you can also change the
  1326. configuration settings using directives in Apache configuration files
  1327. (e.g. httpd.conf) and .htaccess files. You will need "AllowOverride
  1328. Options" or "AllowOverride All" privileges to do so.
  1329. There are several Apache directives that allow you to change the PHP
  1330. configuration from within the Apache configuration files. For a listing
  1331. of which directives are PHP_INI_ALL, PHP_INI_PERDIR, or PHP_INI_SYSTEM,
  1332. have a look at the List of php.ini directives appendix.
  1333. php_value name value
  1334. Sets the value of the specified directive. Can be used only with
  1335. PHP_INI_ALL and PHP_INI_PERDIR type directives. To clear a
  1336. previously set value use none as the value.
  1337. Note: Don't use php_value to set boolean values. php_flag (see
  1338. below) should be used instead.
  1339. php_flag name on|off
  1340. Used to set a boolean configuration directive. Can be used only
  1341. with PHP_INI_ALL and PHP_INI_PERDIR type directives.
  1342. php_admin_value name value
  1343. Sets the value of the specified directive. This can not be used
  1344. in .htaccess files. Any directive type set with php_admin_value
  1345. can not be overridden by .htaccess or ini_set(). To clear a
  1346. previously set value use none as the value.
  1347. php_admin_flag name on|off
  1348. Used to set a boolean configuration directive. This can not be
  1349. used in .htaccess files. Any directive type set with
  1350. php_admin_flag can not be overridden by .htaccess or ini_set().
  1351. Example #1 Apache configuration example
  1352. <IfModule mod_php5.c>
  1353. php_value include_path ".:/usr/local/lib/php"
  1354. php_admin_flag engine on
  1355. </IfModule>
  1356. <IfModule mod_php4.c>
  1357. php_value include_path ".:/usr/local/lib/php"
  1358. php_admin_flag engine on
  1359. </IfModule>
  1360. Caution
  1361. PHP constants do not exist outside of PHP. For example, in httpd.conf
  1362. you can not use PHP constants such as E_ALL or E_NOTICE to set the
  1363. error_reporting directive as they will have no meaning and will
  1364. evaluate to 0. Use the associated bitmask values instead. These
  1365. constants can be used in php.ini
  1366. Changing PHP configuration via the Windows registry
  1367. When running PHP on Windows, the configuration values can be modified
  1368. on a per-directory basis using the Windows registry. The configuration
  1369. values are stored in the registry key HKLM\SOFTWARE\PHP\Per Directory
  1370. Values, in the sub-keys corresponding to the path names. For example,
  1371. configuration values for the directory c:\inetpub\wwwroot would be
  1372. stored in the key HKLM\SOFTWARE\PHP\Per Directory
  1373. Values\c\inetpub\wwwroot. The settings for the directory would be
  1374. active for any script running from this directory or any subdirectory
  1375. of it. The values under the key should have the name of the PHP
  1376. configuration directive and the string value. PHP constants in the
  1377. values are not parsed. However, only configuration values changeable in
  1378. PHP_INI_USER can be set this way, PHP_INI_PERDIR values can not.
  1379. Other interfaces to PHP
  1380. Regardless of how you run PHP, you can change certain values at runtime
  1381. of your scripts through ini_set(). See the documentation on the
  1382. ini_set() page for more information.
  1383. If you are interested in a complete list of configuration settings on
  1384. your system with their current values, you can execute the phpinfo()
  1385. function, and review the resulting page. You can also access the values
  1386. of individual configuration directives at runtime using ini_get() or
  1387. get_cfg_var().
  1388. __________________________________________________________________
  1389. __________________________________________________________________
  1390. __________________________________________________________________
  1391. Installation
  1392. This section holds common questions about the way to install PHP. PHP
  1393. is available for almost any OS (except maybe for MacOS before OSX), and
  1394. almost any web server.
  1395. To install PHP, follow the instructions in Installing PHP.
  1396. 1. Why shouldn't I use Apache2 with a threaded MPM in a production
  1397. environment?
  1398. 2. Unix/Windows: Where should my php.ini file be located?
  1399. 3. Unix: I installed PHP, but every time I load a document, I get the
  1400. message 'Document Contains No Data'! What's going on here?
  1401. 4. Unix: I installed PHP using RPMS, but Apache isn't processing the
  1402. PHP pages! What's going on here?
  1403. 5. Unix: I patched Apache with the FrontPage extensions patch, and
  1404. suddenly PHP stopped working. Is PHP incompatible with the Apache
  1405. FrontPage extensions?
  1406. 6. Unix/Windows: I have installed PHP, but when I try to access a PHP
  1407. script file via my browser, I get a blank screen.
  1408. 7. Unix/Windows: I have installed PHP, but when try to access a PHP
  1409. script file via my browser, I get a server 500 error.
  1410. 8. Some operating systems: I have installed PHP without errors, but
  1411. when I try to start Apache I get undefined symbol errors:
  1412. [mybox:user /src/php5] root# apachectl configtest apachectl:
  1413. /usr/local/apache/bin/httpd Undefined symbols: _compress
  1414. _uncompress
  1415. 9. Windows: I have installed PHP, but when I try to access a PHP
  1416. script file via my browser, I get the error: cgi error: The
  1417. specified CGI application misbehaved by not returning a complete
  1418. set of HTTP headers. The headers it did return are:
  1419. 10. Windows: I've followed all the instructions, but still can't get
  1420. PHP and IIS to work together!
  1421. 11. When running PHP as CGI with IIS, PWS, OmniHTTPD or Xitami, I get
  1422. the following error: Security Alert! PHP CGI cannot be accessed
  1423. directly..
  1424. 12. How do I know if my php.ini is being found and read? It seems like
  1425. it isn't as my changes aren't being implemented.
  1426. 13. How do I add my PHP directory to the PATH on Windows?
  1427. 14. How do I make the php.ini file available to PHP on windows?
  1428. 15. Is it possible to use Apache content negotiation (MultiViews
  1429. option) with PHP?
  1430. 16. Is PHP limited to process GET and POST request methods only?
  1431. Why shouldn't I use Apache2 with a threaded MPM in a production
  1432. environment?
  1433. PHP is glue. It is the glue used to build cool web applications
  1434. by sticking dozens of 3rd-party libraries together and making it
  1435. all appear as one coherent entity through an intuitive and easy
  1436. to learn language interface. The flexibility and power of PHP
  1437. relies on the stability and robustness of the underlying
  1438. platform. It needs a working OS, a working web server and
  1439. working 3rd-party libraries to glue together. When any of these
  1440. stop working PHP needs ways to identify the problems and fix
  1441. them quickly. When you make the underlying framework more
  1442. complex by not having completely separate execution threads,
  1443. completely separate memory segments and a strong sandbox for
  1444. each request to play in, further weaknesses are introduced into
  1445. PHP's system.
  1446. If you feel you have to use a threaded MPM, look at a FastCGI
  1447. configuration where PHP is running in its own memory space.
  1448. And finally, this warning against using a threaded MPM is not as
  1449. strong for Windows systems because most libraries on that
  1450. platform tend to be threadsafe.
  1451. Unix/Windows: Where should my php.ini file be located?
  1452. By default on Unix it should be in /usr/local/lib which is
  1453. <install-path>/lib. Most people will want to change this at
  1454. compile-time with the --with-config-file-path flag. You would,
  1455. for example, set it with something like:
  1456. --with-config-file-path=/etc
  1457. And then you would copy php.ini-development from the
  1458. distribution to /etc/php.ini and edit it to make any local
  1459. changes you want.
  1460. --with-config-file-scan-dir=PATH
  1461. On Windows the default path for the php.ini file is the Windows
  1462. directory. If you're using the Apache webserver, php.ini is
  1463. first searched in the Apaches install directory, e.g. c:\program
  1464. files\apache group\apache. This way you can have different
  1465. php.ini files for different versions of Apache on the same
  1466. machine.
  1467. See also the chapter about the configuration file.
  1468. Unix: I installed PHP, but every time I load a document, I get the
  1469. message 'Document Contains No Data'! What's going on here?
  1470. This probably means that PHP is having some sort of problem and
  1471. is core-dumping. Look in your server error log to see if this is
  1472. the case, and then try to reproduce the problem with a small
  1473. test case. If you know how to use 'gdb', it is very helpful when
  1474. you can provide a backtrace with your bug report to help the
  1475. developers pinpoint the problem. If you are using PHP as an
  1476. Apache module try something like:
  1477. + Stop your httpd processes
  1478. + gdb httpd
  1479. + Stop your httpd processes
  1480. + > run -X -f /path/to/httpd.conf
  1481. + Then fetch the URL causing the problem with your browser
  1482. + > run -X -f /path/to/httpd.conf
  1483. + If you are getting a core dump, gdb should inform you of this
  1484. now
  1485. + type: bt
  1486. + You should include your backtrace in your bug report. This
  1487. should be submitted to » http://bugs.php.net/
  1488. If your script uses the regular expression functions
  1489. (preg_match() and friends), you should make sure that you
  1490. compiled PHP and Apache with the same regular expression
  1491. package. This should happen automatically with PHP and Apache
  1492. 1.3.x
  1493. Unix: I installed PHP using RPMS, but Apache isn't processing the PHP
  1494. pages! What's going on here?
  1495. Assuming you installed both Apache and PHP from RPM packages,
  1496. you need to uncomment or add some or all of the following lines
  1497. in your httpd.conf file:
  1498. # Extra Modules
  1499. AddModule mod_php.c
  1500. AddModule mod_perl.c
  1501. # Extra Modules
  1502. LoadModule php_module modules/mod_php.so
  1503. LoadModule php5_module modules/libphp5.so
  1504. LoadModule perl_module modules/libperl.so
  1505. And add:
  1506. AddType application/x-httpd-php .php
  1507. ... to the global properties, or to the properties of the
  1508. VirtualDomain you want to have PHP support added to.
  1509. Unix: I patched Apache with the FrontPage extensions patch, and
  1510. suddenly PHP stopped working. Is PHP incompatible with the
  1511. Apache FrontPage extensions?
  1512. No, PHP works fine with the FrontPage extensions. The problem is
  1513. that the FrontPage patch modifies several Apache structures,
  1514. that PHP relies on. Recompiling PHP (using 'make clean ; make')
  1515. after the FP patch is applied would solve the problem.
  1516. Unix/Windows: I have installed PHP, but when I try to access a PHP
  1517. script file via my browser, I get a blank screen.
  1518. Do a 'view source' in the web browser and you will probably find
  1519. that you can see the source code of your PHP script. This means
  1520. that the web server did not send the script to PHP for
  1521. interpretation. Something is wrong with the server configuration
  1522. - double check the server configuration against the PHP
  1523. installation instructions.
  1524. Unix/Windows: I have installed PHP, but when try to access a PHP script
  1525. file via my browser, I get a server 500 error.
  1526. Something went wrong when the server tried to run PHP. To get to
  1527. see a sensible error message, from the command line, change to
  1528. the directory containing the PHP executable (php.exe on Windows)
  1529. and run php -i. If PHP has any problems running, then a suitable
  1530. error message will be displayed which will give you a clue as to
  1531. what needs to be done next. If you get a screen full of HTML
  1532. codes (the output of the phpinfo() function) then PHP is
  1533. working, and your problem may be related to your server
  1534. configuration which you should double check.
  1535. Some operating systems: I have installed PHP without errors, but when I
  1536. try to start Apache I get undefined symbol errors:
  1537. [mybox:user /src/php5] root# apachectl configtest
  1538. apachectl: /usr/local/apache/bin/httpd Undefined symbols:
  1539. _compress
  1540. _uncompress
  1541. This has actually nothing to do with PHP, but with the MySQL
  1542. client libraries. Some need --with-zlib , others do not. This is
  1543. also covered in the MySQL FAQ.
  1544. Windows: I have installed PHP, but when I try to access a PHP script
  1545. file via my browser, I get the error:
  1546. cgi error:
  1547. The specified CGI application misbehaved by not
  1548. returning a complete set of HTTP headers.
  1549. The headers it did return are:
  1550. This error message means that PHP failed to output anything at
  1551. all. To get to see a sensible error message, from the command
  1552. line, change to the directory containing the PHP executable
  1553. (php.exe on Windows) and run php -i. If PHP has any problems
  1554. running, then a suitable error message will be displayed which
  1555. will give you a clue as to what needs to be done next. If you
  1556. get a screen full of HTML codes (the output of the phpinfo()
  1557. function) then PHP is working.
  1558. Once PHP is working at the command line, try accessing the
  1559. script via the browser again. If it still fails then it could be
  1560. one of the following:
  1561. + File permissions on your PHP script, php.exe, php5ts.dll,
  1562. php.ini or any PHP extensions you are trying to load are such
  1563. that the anonymous internet user ISUR_<machinename> cannot
  1564. access them.
  1565. + The script file does not exist (or possibly isn't where you
  1566. think it is relative to your web root directory). Note that
  1567. for IIS you can trap this error by ticking the 'check file
  1568. exists' box when setting up the script mappings in the
  1569. Internet Services Manager. If a script file does not exist
  1570. then the server will return a 404 error instead. There is also
  1571. the additional benefit that IIS will do any authentication
  1572. required for you based on the NTLanMan permissions on your
  1573. script file.
  1574. Windows: I've followed all the instructions, but still can't get PHP
  1575. and IIS to work together!
  1576. Make sure any user who needs to run a PHP script has the rights
  1577. to run php.exe! IIS uses an anonymous user which is added at the
  1578. time IIS is installed. This user needs rights to php.exe. Also,
  1579. any authenticated user will also need rights to execute php.exe.
  1580. And for IIS4 you need to tell it that PHP is a script engine.
  1581. Also, you will want to read this faq.
  1582. When running PHP as CGI with IIS, PWS, OmniHTTPD or Xitami, I get the
  1583. following error: Security Alert! PHP CGI cannot be accessed
  1584. directly..
  1585. You must set the cgi.force_redirect directive to 0. It defaults
  1586. to 1 so be sure the directive isn't commented out (with a ;).
  1587. Like all directives, this is set in php.ini
  1588. Because the default is 1, it's critical that you're 100% sure
  1589. that the correct php.ini file is being read. Read this faq for
  1590. details.
  1591. How do I know if my php.ini is being found and read? It seems like it
  1592. isn't as my changes aren't being implemented.
  1593. To be sure your php.ini is being read by PHP, make a call to
  1594. phpinfo(). Near the top, there will be a listing called
  1595. Configuration File (php.ini). This will tell you where PHP is
  1596. looking for php.ini and whether or not it's being read. If just
  1597. a directory PATH exists, then it's not being read, and you
  1598. should put your php.ini in that directory. If php.ini is
  1599. included within the PATH, it is being read.
  1600. If php.ini is being read and you're running PHP as a module,
  1601. then be sure to restart your web server after making changes to
  1602. php.ini
  1603. See also php_ini_loaded_file().
  1604. How do I add my PHP directory to the PATH on Windows?
  1605. On Windows NT+ and Windows Server 2000+:
  1606. + Go to Control Panel and open the System icon (Start ->
  1607. Settings -> Control Panel -> System, or just Start -> Control
  1608. Panel -> System for Windows XP/2003+)
  1609. + Go to the Advanced tab
  1610. + Click on the 'Environment Variables' button
  1611. + Look into the 'System Variables' pane
  1612. + Find the Path entry (you may need to scroll to find it)
  1613. + Double click on the Path entry
  1614. + Enter your PHP directory at the end, including ';' before
  1615. (e.g. ;C:\php)
  1616. + Press OK
  1617. On Windows 98/Me you need to edit the autoexec.bat file:
  1618. + Open the Notepad (Start -> Run and enter notepad)
  1619. + Open the C:\autoexec.bat file
  1620. + Locate the line with PATH=C:\WINDOWS;C:\WINDOWS\COMMAND;.....
  1621. and add: ;C:\php to the end of the line
  1622. + Save the file and restart your computer
  1623. Note: Be sure to reboot after following the steps above to ensure
  1624. that the PATH changes are applied.
  1625. The PHP manual used to promote the copying of files into the
  1626. Windows system directory, this is because this directory
  1627. (C:\Windows, C:\WINNT, etc.) is by default in the systems PATH.
  1628. Copying files into the Windows system directory has long since
  1629. been deprecated and may cause problems.
  1630. How do I make the php.ini file available to PHP on windows?
  1631. There are several ways of doing this. If you are using Apache,
  1632. read their installation specific instructions (Apache 1, Apache
  1633. 2), otherwise you must set the PHPRC environment variable:
  1634. On Windows NT, 2000, XP and 2003:
  1635. + Go to Control Panel and open the System icon (Start ->
  1636. Settings -> Control Panel -> System, or just Start -> Control
  1637. Panel -> System for Windows XP/2003)
  1638. + Go to the Advanced tab
  1639. + Click on the 'Environment Variables' button
  1640. + Look into the 'System variables' pane
  1641. + Click on 'New' and enter 'PHPRC' as the variable name and the
  1642. directory where php.ini is located as the variable value (e.g.
  1643. C:\php)
  1644. + Press OK and restart your computer
  1645. On Windows 98/Me you need to edit the autoexec.bat file:
  1646. + Open the Notepad (Start -> Run and enter notepad)
  1647. + Open the C:\autoexec.bat file
  1648. + Add a new line to the end of the file: set PHPRC=C:\php
  1649. (replace C:\php with the directory where php.ini is located).
  1650. Please note that the path cannot contain spaces. For instance,
  1651. if you have installed PHP in C:\Program Files\PHP, you would
  1652. enter C:\PROGRA~1\PHP instead.
  1653. + Save the file and restart your computer
  1654. Is it possible to use Apache content negotiation (MultiViews option)
  1655. with PHP?
  1656. If links to PHP files include extension, everything works
  1657. perfect. This FAQ is only for the case when links to PHP files
  1658. don't include extension and you want to use content negotiation
  1659. to choose PHP files from URL with no extension. In this case,
  1660. replace the line AddType application/x-httpd-php .php with:
  1661. AddHandler php5-script php
  1662. AddType text/html php
  1663. This solution doesn't work for Apache 1 as PHP module doesn't
  1664. catch php-script.
  1665. Is PHP limited to process GET and POST request methods only?
  1666. No, it is possible to handle any request method, e.g. CONNECT.
  1667. Proper response status can be sent with header(). If only GET
  1668. and POST methods should be handled, it can be achieved with this
  1669. Apache configuration:
  1670. <LimitExcept GET POST>
  1671. Deny from all
  1672. </LimitExcept>