INSTALL 93 KB

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