蓝晶灵 发表于 2018-11-25 10:52:19

官方的编译 Apache 2.x 和 PHP 的说明

  内容来自来自源代码包的INSTALL文件,这才是权威的,不要被网上纷呈的例子搞混了。
  Apache 2.x on Unix systems
  Thissectioncontains notes and hints specific to Apache 2.x installs
  of PHP on Unix systems.
  Warning
  Wedonot recommend using a threaded MPM in production with Apache 2.
  Usethe prefork MPM, which is the default MPM with Apache 2.0 and 2.2.
  Forinformationonwhy,read the related FAQ entry on using Apache2
  with a threaded MPM
  The   禄 ApacheDocumentationisthemostauthoritativesourceof
  information   on   the   Apache2.xserver.Moreinformationabout
  installation options for Apache may be found there.
  ThemostrecentversionofApache HTTP Server may be obtained from
  禄 Apachedownloadsite,andafittingPHPversion from the above
  mentionedplaces.Thisquickguidecoversonlythe basics to get
  started with Apache 2.x and PHP. For more information read the 禄 Apache
  Documentation.Theversionnumbers have been omitted here, to ensure
  theinstructions are not incorrect. In the examples below, 'NN' should
  be replaced with the specific version of Apache being used.
  Therearecurrently two versions of Apache 2.x - there's 2.0 and 2.2.
  Whilethereare various reasons for choosing each, 2.2 is the current
  latestversion,andtheonethat is recommended, if that option is
  availabletoyou. However, the instructions here will work for either
  2.0 or 2.2.
  1. ObtaintheApache HTTP server from the location listed above, and
  unpack it:
  gzip -d httpd-2_x_NN.tar.gz
  tar -xf httpd-2_x_NN.tar
  2. Likewise, obtain and unpack the PHP source:
  gunzip php-NN.tar.gz
  tar -xf php-NN.tar
  3. Buildand install Apache. Consult the Apache install documentation
  for more details on building Apache.
  cd httpd-2_x_NN
  ./configure --enable-so
  make
  make install
  4. NowyouhaveApache2.x.NNavailable under /usr/local/apache2,
  configuredwithloadablemodulesupportandthestandard MPM
  prefork.Totesttheinstallation use your normal procedure for
  starting the Apache server, e.g.:
  /usr/local/apache2/bin/apachectl start
  and stop the server to go on with the configuration for PHP:
  /usr/local/apache2/bin/apachectl stop
  5. Now,configure and build PHP. This is where you customize PHP with
  variousoptions,likewhichextensionswillbeenabled.Run
  ./configure--help for a list of available options. In our example
  we'll do a simple configure with Apache 2 and MySQL support.
  IfyoubuiltApachefromsource, as described above, the below
  examplewill match your path for apxs, but if you installed Apache
  some other way, you'll need to adjust the path to apxs accordingly.
  Note that some distros may rename apxs to apxs2.
  cd ../php-NN
  ./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql
  make
  make install
  Ifyou decide to change your configure options after installation,
  you'llneed to re-run the configure, make, and make install steps.
  Youonly need to restart apache for the new module to take effect.
  A recompile of Apache is not needed.
  Notethatunless told otherwise, 'make install' will also install
  PEAR,variousPHPtools such as phpize, install the PHP CLI, and
  more.
  6. Setup your php.ini
  cp php.ini-development /usr/local/lib/php.ini
  Youmayedityour.inifileto set PHP options. If you prefer
  having php.ini in another location, use
  --with-config-file-path=/some/path in step 5.
  Ifyouinsteadchoose php.ini-production, be certain to read the
  list of changes within, as they affect how PHP behaves.
  7. Edityour httpd.conf to load the PHP module. The path on the right
  hand side of the LoadModule statement must point to the path of the
  PHPmoduleonyoursystem. The make install from above may have
  already added this for you, but be sure to check.
  LoadModule php5_module modules/libphp5.so
  8. TellApache to parse certain extensions as PHP. For example, let's
  haveApacheparse.phpfilesas PHP. Instead of only using the
  ApacheAddTypedirective,we want to avoid potentially dangerous
  uploadsandcreatedfilessuchasexploit.php.jpgfrom being
  executed   as   PHP.   Usingthisexample,youcouldhaveany
  extension(s)parse as PHP by simply adding them. We'll add .php to
  demonstrate.
  
  SetHandler application/x-httpd-php
  
  Or,if we wanted to allow .php, .php2, .php3, .php4, .php5, .php6,
  and.phtml files to be executed as PHP, but nothing else, we'd use
  this:
  
  SetHandler application/x-httpd-php
  
  Andtoallow.phps files to be handled by the php source filter,
  and displayed as syntax-highlighted source code, use this:
  
  SetHandler application/x-httpd-php-source
  
  mod_rewritemaybeusedToallow any arbitrary .php file to be
  displayedassyntax-highlightedsourcecode,without having to
  rename or copy it to a .phps file:
  RewriteEngine On
  RewriteRule (.*\.php)s$ $1
  Thephp source filter should not be enabled on production systems,
  where it may expose confidential or otherwise sensitive information
  embedded in source code.
  9. Use your normal procedure for starting the Apache server, e.g.:
  /usr/local/apache2/bin/apachectl start
  OR
  service httpd restart
  Followingthestepsabove you will have a running Apache2 web server
  withsupportforPHP as a SAPI module. Of course there are many more
  configurationoptionsavailableApache and PHP. For more information
  type ./configure --help in the corresponding source tree.
  Apachemaybe built multithreaded by selecting the worker MPM, rather
  thanthestandardprefork MPM, when Apache is built. This is done by
  addingthefollowing option to the argument passed to ./configure, in
  step 3 above:
  --with-mpm=worker
  Thisshouldnot be undertaken without being aware of the consequences
  ofthisdecision,andhavingatleast a fair understanding of the
  implications.   The   Apache   documentation   regarding禄 MPM-Modules
  discusses MPMs in a great deal more detail.
  Note:
  The Apache MultiViews FAQ discusses using multiviews with PHP.
  Note:
  Tobuilda multithreaded version of Apache, the target system must
  supportthreads.Inthiscase,PHPshouldalsobe built with
  experimental Zend Thread Safety (ZTS). Under this configuration, not
  allextensions will be available. The recommended setup is to build
  Apache with the default prefork MPM-Module.
  __________________________________________________________________
  __________________________________________________________________



页: [1]
查看完整版本: 官方的编译 Apache 2.x 和 PHP 的说明