How to install apache/php

Go down

How to install apache/php

Post  Admin on Mon Dec 28, 2009 3:57 am

###HOW TO INSTALL APACHE /PHP from Source###

# Download/unpack Apache2 source from the Apache httpd server website,

# In the Apache 2 source directory, create a Makefile by typing:

./configure --prefix=/usr/local/apache \
--enable-so \
--enable-cgi \
--enable-info \
--enable-rewrite \
--enable-speling \
--enable-usertrack \
--enable-deflate \
--enable-ssl \

You only need the enable-so line above. For information on other options, type ./configure --help and see "Compiling and Installing" in the Apache 2 Documentation,

# Make Apache from the just-created Makefile:


# If make is successful, install Apache as root:

make install

# Download/unpack PHP source from the PHP website,
Pick the latest from the 4.x series or 5.x series.

# In the PHP source directory, create a Makefile by typing:

./configure \
--with-apxs2=/usr/local/apache/bin/apxs \
--with-mysql \
--prefix=/usr/local/apache/php \
--with-config-file-path=/usr/local/apache/php \
--enable-force-cgi-redirect \
--disable-cgi \
--with-zlib \
--with-gettext \

You only need the --with-apxs2, and prefix lines. --with-mysql adds MySql (you need to specify the directory if it's in a unusual location (e.g., --with-mysql=/usr/local ), --with-config-file moves the php.ini file location, disable-cgi disables the CGI version, which is not needed if you use Apache modules. It also enables and installs the command line interface (CLI) version. --with-zlib allows use of gzip-type compression, --with-gettext is for internationalization, and --with-gdbm allows access to GDBM databases. For more information, type ./configure --help and see the "Installation" chapter in the PHP Manual,

# Make PHP from the just-created Makefile:


# If make is successful, type this as root to install PHP:

make install

If you are not root (I do not perform makes while root, for security and safety reasons), become root and type the following:

make install-su

# If file /usr/local/apache/modules/ does not exist or is an older version, type this (change this to for PHP 4):

cp -p .libs/ /usr/local/apache/modules

# Install the php.ini file:

cp -p php.ini-recommended /usr/local/apache/php/php.ini

# Add these directives are in /usr/local/apache/conf/httpd.conf (if already there, verify they are correct):

# Make sure there's only **1** line for each of these 2 directives:
# Use for PHP 4.x:
#LoadModule php4_module modules/
#AddHandler php-script php

# Use for PHP 5.x:
LoadModule php5_module modules/
AddHandler php5-script php

# Add index.php to your DirectoryIndex line:
DirectoryIndex index.html index.php

AddType text/html php

# PHP Syntax Coloring
# (optional but useful for reading PHP source for debugging):
AddType application/x-httpd-php-source phps

Note 1: The php documentation recommends AddType application/x-httpd-php php instead of the above. However, it causes problems with the "MultiViews" feature of HTTP. That is, if the .php extension is left off a URL, and with certain browser Accept headers, Apache will not know .php (application/x-httpd-php) is HTML and will return a 406 Not Acceptable error. Using the AddType and AddHandler as shown above fixes this problem. For details see Mark Tranchant's webpage, "Using Apache's MultiViews with PHP whilst avoid 406 errors," and PHP bug 28023.

Note 2: PHP Syntax coloring isn't required, but it's very nice for looking at your php source while debugging. Here's an example.

Note 3: just for completeness I'll mention that you should be able to use SetOutputFilter / SetInputFilter instead of AddType, but you can't use both. However, SetOutputFilter / SetInputFilter no longer works for me. It used to work with an earlier PHP 4.x or Apache 2 version, but not with Apache 2.0.47/PHP 4.3.3. I understand this (PHP as an Apache 2 filter) is experimental, so I don't use it anymore:

<Files *.php>
SetOutputFilter PHP
SetInputFilter PHP

# You're now ready to try it out. Start Apache (httpd) as root:

/usr/local/apache/bin/apachectl start

# Perform these sanity checks to verify your install went OK:

$ /usr/local/apache/bin/httpd -t
Syntax OK

$ /usr/local/apache/bin/httpd -v
Server version: Apache/2.2.2
Server built: May 29 2006 12:40:55

$ /usr/local/apache/bin/httpd -V
Server version: Apache/2.2.2
Server built: May 29 2006 12:40:55
Server's Module Magic Number: 20051115:2
Server loaded: APR 1.2.7, APR-Util 1.2.7
Compiled using: APR 1.2.7, APR-Util 1.2.7
Architecture: 32-bit
Server MPM: Prefork
threaded: no
forked: yes (variable process count)
Server compiled with....
-D APACHE_MPM_DIR="server/mpm/prefork"
-D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
-D HTTPD_ROOT="/usr/local/apache"
-D SUEXEC_BIN="/usr/local/apache/bin/suexec"
-D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
-D DEFAULT_LOCKFILE="logs/accept.lock"
-D DEFAULT_ERRORLOG="logs/error_log"
-D AP_TYPES_CONFIG_FILE="conf/mime.types"
-D SERVER_CONFIG_FILE="conf/httpd.conf"

$ /usr/local/apache/bin/httpd -S
VirtualHost configuration:
. . .

$ /usr/local/apache/bin/httpd -l
Compiled in modules:
. . .

$ /usr/local/apache/bin/httpd -M
Loaded Modules:
. . .
php5_module (shared)
Syntax OK

(the above works for Apache 2.2.x and higher only)

$ ps -ef |grep httpd
root 24069 1 0 09:17 ? 00:00:08 /usr/local/apache/bin/httpd -k s
apache 29917 24069 0 15:30 ? 00:00:00 /usr/local/apache/bin/httpd -k s
. . .

Note: on BSD-based UNIX systems, you need to use "ps -aux" instead of "ps -ef".
# Access your webserver with telnet. Type HEAD / HTTP/1.0 followed by a blank line:

$ telnet localhost 80
Connected to localhost (
Escape character is '^]'.

HTTP/1.1 200 OK
Date: Mon, 29 May 2006 23:28:18 GMT
Server: Apache/2.2.2 (Unix) mod_ssl/2.2.2 OpenSSL/0.9.7a PHP/5.1.4
X-Powered-By: PHP/5.1.4
Last-Modified: Wed, 15 Mar 2006 06:53:17 GMT
Vary: Accept-Encoding
Connection: close
Content-Type: text/html; charset=ISO-8859-1
Content-Language: en

Connection closed by foreign host.

# Access your webserver with your favorite browser. The following is a good test page to use for PHP. You only need the one line in bold is needed to display PHP configuration information. Name the file anything you want, but it must end with .php, such as phpinfo.php, and move the file to your web server content directory (for me /usr/local/apache/htdocs), with read permission set:

<title>PHP Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<h1>PHP Test</h1>
<b>An Example of PHP in Action</b><br />
<?php echo "The Current Date and Time is: <br>";
echo date("g:i A l, F j Y.");?>

<h2>PHP Information</h2>
<?php phpinfo(); ?>

Posts : 32
Join date : 2009-09-13
Age : 32
Location : Chennai

View user profile

Back to top Go down

Back to top

Permissions in this forum:
You cannot reply to topics in this forum