Php configure with libdir
This section contains notes and hints specific to Apache 2.x installs of PHP on Unix systems.
We do not recommend using a threaded MPM in production with Apache 2. Use the prefork MPM, which is the default MPM with Apache 2.0 and 2.2. For information on why, read the related FAQ entry on using Apache2 with a threaded MPM
The » Apache Documentation is the most authoritative source of information on the Apache 2.x server. More information about installation options for Apache may be found there.
The most recent version of Apache HTTP Server may be obtained from » Apache download site, and a fitting PHP version from the above mentioned places. This quick guide covers only the basics to get started with Apache 2.x and PHP. For more information read the » Apache Documentation. The version numbers have been omitted here, to ensure the instructions are not incorrect. In the examples below, ‘NN’ should be replaced with the specific version of Apache being used.
There are currently two versions of Apache 2.x — there’s 2.4 and 2.2. While there are various reasons for choosing each, 2.4 is the current latest version, and the one that is recommended, if that option is available to you. However, the instructions here will work for either 2.4 or 2.2. Note that Apache httpd 2.2 is officially End Of Life, and no new development or patches are being issued for it.
- Obtain the Apache HTTP server from the location listed above, and unpack it:
cd httpd-2_x_NN ./configure --enable-so make make install
/usr/local/apache2/bin/apachectl start
/usr/local/apache2/bin/apachectl stop
cd ../php-NN ./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-pdo-mysql make make install
cp php.ini-development /usr/local/lib/php.ini
LoadModule php_module modules/libphp.so
LoadModule php7_module modules/libphp7.so
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
And to allow .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_rewrite may be used To allow any arbitrary .php file to be displayed as syntax-highlighted source code, without having to rename or copy it to a .phps file:
RewriteEngine On RewriteRule (.*\.php)s$ $1 [H=application/x-httpd-php-source]
/usr/local/apache2/bin/apachectl start
Following the steps above you will have a running Apache2 web server with support for PHP as a SAPI module. Of course there are many more configuration options available Apache and PHP. For more information type ./configure —help in the corresponding source tree.
Apache may be built multithreaded by selecting the worker MPM, rather than the standard prefork MPM, when Apache is built. This is done by adding the following option to the argument passed to ./configure, in step 3 above:
This should not be undertaken without being aware of the consequences of this decision, and having at least 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:
To build a multithreaded version of Apache, the target system must support threads. In this case, PHP should also be built with Zend Thread Safety (ZTS). Under this configuration, not all extensions will be available. The recommended setup is to build Apache with the default prefork MPM-Module.
User Contributed Notes 16 notes
I had just installed php8.1.12 on a machine used for writing C code.
Below are some libraries that I needed to download on a debian-based OS.
apt-get install libpcre3 libpcre3-dev
apt-get install apache2-dev
apt-get install libxml2-dev
apt-get install libsqlite3-dev
These were the missing packages that I required.
If you get an error regarding a missing package or library, for example when I needed sqlite3, run the command:
And you’ll be able to see if there’s any dev or lib packages.
The apache2 instructions worked flawlessly at the time of php8.1.12; and in order to get certain requirements for an application, I had to run the php configure file like so:
./configure —with-apxs2=/usr/local/apache2/bin/apxs —with-pdo-mysql —with-mysqli —with-zip —enable-gd
The extra flags allowed me to use both types of mysql, allowed me to utilize PHP zip archiving, and allowed me to use Gnatt stuff.
When I upgrade to apache 2.2, this:
AddType application/x-httpd-php .php5
AddType application/x-httpd-php .php42
AddType application/x-httpd-php .php4
AddType application/x-httpd-php .php3
AddType application/x-httpd-php .php
AddType application/x-httpd-php .phtm
AddType application/x-httpd-php .phtml
AddType application/x-httpd-php .asp
. does not worked for me, so I did this:
Another interesting point with Apache 2.2 is following.
Let suppose we installed PHP as module. But for some directory, we need to use PHP as CGI (probably because of custom configuration). This can be done using:
AddType application/x-httpd-php-custom .php
Action application/x-httpd-php-custom /cgi-bin/php-huge
Note type must be different than «application/x-httpd-php» and also you need to deactivate the handler on sertain extention. You can do mixed configuration:
AddType application/x-httpd-php-custom .php
Action application/x-httpd-php-custom /cgi-bin/php-huge
in such case files like *.php5 and so on will be parsed via module, but *.php will go to php-huge executable.
Building php 7.1.3 with mysql 5.7.17 and httpd 2.4.25 on Debian 8, step 5 failed for me. Instead of
I’ve (painfully) discovered that installing PHP5 with «make install» under SuSe 9.2 is NOT a good idea.
http://www.aditus.nu/jpgraph/apache2suse.php
This page explains how to install it without breaking everything that’s php-related in the Apache2 configuration. Its first purpose, though, is to show how to have php 4 and 5 to cohabit properly.
I have successfully installed Apache 2.2.11 and PHP 5.2.8 under Red Hat 9.0 on a Pentium 166 with 32 MB of RAM.
While I used RH9, the worst possible case, these notes are probably good for RH-based distributions too (Red Hat Enterprise, Fedora, CentOS. )
If you want to install MySQL, it needs to be installed before PHP because PHP requires some libraries be available.
One think important when picking up a binary distribution of MySQL is to download all four packages: MySQL-server, MySQL-devel, MySQL-client and MySQL-shared. Note: The MySQL was bundled with PHP 4 but is not anymore in PHP 5.
Then you need to install Apache before PHP, because again PHP needs some libraries be available. I installed Apache 2 from source, using the very last version available, which is 2.2.11.
I installed PHP 5.2.8 from source. Here, I had a number of problems, but none which I could not resolve easily, some of them with a little help from different forums I found through Google.
Rembember: When it says you need a package named xyz and you notice there is also one named xyz-devel, grab it.
Most of the packages I got from:
http://legacy.redhat.com/pub/redhat/linux/9/en/os/i386/RedHat/RPMS/
A similar page exists for other versions of Red Hat
and:
http://rpmfind.net/
This site has an updated version of some of the packages. Make sure to use only the one labeled for you version (in my case, Red Hat 9.0) or it will not likely work.
You already have glibc and glibc-common installed, but you need to get glibc-devel and glibc-kernheaders. Make sure to match glibc’s version (rpm -q glibc). Note: When it says kernel-header is a required dependency, that’s glibc-kernheader (not kernel-source). You will also need binutils (no need to match the version), and gcc and cpp (version must match).
You need zlib-devel (zlib is probably already installed, match the version you have).
If you install the GD extension, the actual library is already bundled with PHP 5 (use that one, they have done some changes in there, so don’t upgrade), but you will need to install libpng and libpng-devel (match version, or disable in configure if you don’t want) and libjpeg (no -devel with that one).
You will also need libxml2. Now there were a problem, because PHP requires libxml2 be 2.6 or greater, but Red Hat only supplied 2.5.4-1 for RH9 (if you have a more recent distro, you might be more lucky). After looking for a while, I decided to grab the source code for the most recent distribution at the official website (http://xmlsoft.org/) and compiled.
Hope my post is useful to someone. Please, share your experience when compiling/installing for your particular platform and setup. Remember how hard it’s been for you the very first time. I confess, my very first server installation took me nearly a week and I was glad others helped me.
Php configure with libdir
Below is a partial list of configure options used by the PHP configure scripts when compiling in Unix-like environments. Most configure options are listed in their appropriate locations on the extension reference pages and not here. For a complete up-to-date list of configure options, run ./configure —help in your PHP source directory after running autoconf (see also the Installation chapter). You may also be interested in reading the » GNU configure documentation for information on additional configure options such as —prefix=PREFIX .
Note:
These are only used at compile time. If you want to alter PHP’s runtime configuration, please see the chapter on Runtime Configuration.
Configure Options in PHP
Misc options
Compile with debugging symbols.
—with-layout=TYPE
Sets how installed files will be laid out. Type is one of PHP (default) or GNU.
—with-pear=DIR
Install PEAR in DIR (default PREFIX/lib/php).
—without-pear
—enable-sigchild
Enable PHP’s own SIGCHLD handler.
—disable-rpath
Disable passing additional runtime library search paths.
—enable-libgcc
Enable explicitly linking against libgcc.
—enable-php-streams
Include experimental PHP streams. Do not use unless you are testing the code!
—with-zlib-dir[=DIR]
Define the location of zlib install directory.
—with-tsrm-pthreads
Use POSIX threads (default).
—enable-shared[=PKGS]
Build shared libraries [default=yes].
—enable-static[=PKGS]
Build static libraries [default=yes].
—enable-fast-install[=PKGS]
Optimize for fast installation [default=yes].
Assume the C compiler uses GNU ld [default=no].
—disable-libtool-lock
Avoid locking (might break parallel builds).
Try to use only PIC/non-PIC objects [default=use both].
—enable-versioning
Export only required symbols. See INSTALL for more information.
PHP options
Enable make rules and dependencies not useful (and sometimes confusing) to the casual installer.
—with-config-file-path=PATH
Sets the path in which to look for php.ini , defaults to PREFIX/lib .
—disable-short-tags
Specifies the directory where the libraries to build PHP exist on a Unix system. For 64bit systems, its needed to specify this argument to the lib64 directory like: —with-libdir=lib64 .
Enables thread safety. Prior to PHP 8.0.0 on non-Windows systems, the option was called —enable-maintainer-zts.
SAPI options
The following list contains the available SAPI&s ( Server Application Programming Interface ) for PHP.
—with-apxs[=FILE]
Build shared Apache module. FILE is the optional pathname to the Apache apxs tool; defaults to apxs. Make sure you specify the version of apxs that is actually installed on your system and NOT the one that is in the apache source tarball.
—with-apache[=DIR]
Build a static Apache module. DIR is the top-level Apache build directory, defaults to /usr/local/apache .
—with-mod_charset
Enable transfer tables for mod_charset (Russian Apache).
—with-apxs2[=FILE]
Build shared Apache 2.0 module. FILE is the optional pathname to the Apache apxs tool; defaults to apxs.
Disable building the CLI version of PHP (this forces —without-pear). More information is available in the section about Using PHP from the command line.
—enable-phpdbg
Enable phpdbg interactive debugger SAPI module support.
—enable-embed[=TYPE]
Enable building of the embedded SAPI library. TYPE is either shared or static , which defaults to shared .
—with-servlet[=DIR]
Include servlet support. DIR is the base install directory for the JSDK. This SAPI requires the java extension must be built as a shared dl.
Disable building CGI version of PHP.
This argument also enables FastCGI.