How To Install PHP 5.2.x and PHP 5.3.x into Same Server

Step-1: Prepare your server
 #yum install gcc libxml2-devel bzip2-devel zlib-devel curl-devel libmcrypt-devel libjpeg-devel libpng-devel gd-devel mysql-devel
Step-2: Download php 5.2.x source and compile
 #wget http://us.php.net/distributions/php-5.2.17.tar.gz
 #tar -xvf php-5.2.17.tar.gz
 #cd php-5.2.17
 #./configure --prefix=/usr/local/php52 --with-config-file-path=/etc/php52 --with-config-file-scan-dir=/etc/php52/php.d --with-libdir=lib64 --with-mysql --with-mysqli --enable-bcmath --enable-calendar --enable-exif --enable-zip --enable-ftp --enable-fastcgi --enable-gd-native-ttf --enable-force-cgi-redirect --enable-mbstring --enable-pcntl --enable-wddx --with-imap-ssl --disable-debug --disable-rpath --enable-libxml --with-bz2 --with-curl --with-gettext --with-iconv --with-openssl --with-gd --with-mcrypt --with-pcre-regex --with-zlib --with-ttf --with-pdo-mysql --with-pdo-sqlite --with-ldap --with-mhash --enable-shmop --enable-soap --enable-sockets --enable-sqlite-utf8 --with-xmlrpc --with-xsl --with-pear --with-tidy

#make -j4 > /dev/null
#make install
#mkdir /etc/php52
#cp php.ini-recommended /etc/php52/php.ini

Step-3: Create a fastcgi wrapper script
create file /usr/local/php52/bin/fcgiwrapper with the following contents:

#!/bin/bash
PHP_FCGI_MAX_REQUESTS=10000
export PHP_FCGI_MAX_REQUESTS
exec /usr/local/php52/bin/php-cgi

Save it.

Assign execute permission to the wrapper script.

#chmod a+x /usr/local/php52/bin/fcgiwrapper

 

 

 

How to generate CSR for your domain

To generate CSR for your domain hosted in Apache Web server, follow the simple steps described below:Step-1: Create Server Key with 2048bit encryption

#openssl genrsa -des3 -out domain.com.key 2048

Step-2: Generate CSR for your domain.
#openssl req -new -key domain.com.key -out domain.com.csr
Step-3: Removing pass phrase from server key.
#cp domain.com.key domain.key.org
#openssl rsa -in domain.com.key.org -out domain.com.key

How to compile php 5.2 and run using fastcgi on CentOS 5.7

Step-1: Install required dev packages
#yum install httpd-devel libtool apr-devel aprgcc libxml2-devel bzip2-devel zlib-devel curl-devel libmcrypt-devel libjpeg-devel libpng-devel gd-devel mysql-devel
Step-2: Download php5.2 source and install
#wget http://cn.php.net/get/php-5.2.17.tar.bz2/from/this/mirror
#tar -xjf php-5.2.17.tar.bz2
#cd php-5.2.17
#./configure --prefix=/usr/local/php52 --with-config-file-path=/etc/php52 --with-config-file-scan-dir=/etc/php52/php.d --with-libdir=lib64 --enable-force-cgi-redirect --enable-fastcgi --with-bz2 --with-curl=/usr/local/lib --with-gd --with-gettext --with-jpeg-dir=/usr/local/lib --with-freetype-dir=/usr/local/lib --with-kerberos --with-mcrypt --with-mhash --with-mime-magic --with-mysql --with-mysqli --with-pcre-regex=/usr --with-pdo-mysql=shared --with-pdo-sqlite=shared --with-pear=/usr/local/lib/php --with-png-dir=/usr/local/lib --with-pspell --with-sqlite=shared --with-tidy --with-ttf --with-xmlrpc --with-xsl --with-zlib --with-zlib-dir=/usr/local/lib --with-openssl --with-iconv --with-libdir=lib64 --enable-bcmath --enable-calendar --enable-exif --enable-ftp --enable-gd-native-ttf --enable-libxml --enable-magic-quotes --enable-soap --enable-sockets --enable-mbstring --enable-zip --enable-wddx
#make
#make install
#mkdir /etc/php52
#cp php.ini-recommended /etc/php52/php.in

Step-3: Install Mod-FastCGI

# wget http://www.fastcgi.com/dist/mod_fastcgi-current.tar.gz
#Untar tar ball, type:
# tar -zxvf mod_fastcgi-current.tar.gz
# cd mod_fastcgi-2.4.6/

Make a copy of Makefile.AP2, enter:

# cp Makefile.AP2 Makefile

Compile and install mod_fastcgi for 32 bit system, enter:

# make top_dir=/usr/lib/httpd
# make install top_dir=/usr/lib/httpd

Compile and install mod_fastcgi for 64 bit system, enter:

# make top_dir=/usr/lib64/httpd
# make install top_dir=/usr/lib64/httpd

Sample output:

make install top_dir=/usr/lib64/httpd

make[1]: Entering directory `/tmp/mod_fastcgi-2.4.6′
/usr/lib64/apr-1/build/libtool –silent –mode=install cp mod_fastcgi.la /usr/lib64/httpd/modules/
make[1]: Leaving directory `/tmp/mod_fastcgi-2.4.6′
Configure mod_fastcgi
#cd /var/www/cgi-bin
#vi php.fcgi and add the followings:
####################################
#!/bin/bash
# Shell Script To Run PHP5 using mod_fastcgi under Apache 2.x
# Tested under Red Hat Enterprise Linux / CentOS 5.x
### Set PATH ###
PHP_CGI=/usr/local/php52/bin/php-cgi
PHP_FCGI_CHILDREN=4
PHP_FCGI_MAX_REQUESTS=1000
### no editing below ###
export PHP_FCGI_CHILDREN
export PHP_FCGI_MAX_REQUESTS
exec $PHP_CGI
##################################

 

Open /etc/httpd/conf.d/mod_fastcgi.conf file
# vi /etc/httpd/conf.d/mod_fastcgi.conf
Add an entry to it like this:
LoadModule fastcgi_module modules/mod_fastcgi.so
Save and close the file. Restart httpd, enter:
# service httpd restart

 

Step-4: Setup your virtualhost to use fastcgi for processing php
#vi /etc/httpd/conf/httpd.conf
 <VirtualHost *:80>
 ServerAdmin webmaster@example.com
 DocumentRoot "/var/www/php52"
 ServerName example.com
 ServerAlias www.example.com
 ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
<Directory "/var/www/php52">
 Options -Indexes FollowSymLinks +ExecCGI
 AllowOverride AuthConfig FileInfo
 AddHandler php5-fastcgi .php
 Action php5-fastcgi /cgi-bin/php.fcgi
 Order allow,deny
 Allow from all
 </Directory>
</VirtualHost>
 #service httpd restart

How to setup php-fpm with apache on CentOS 5.7

FastCGI is a protocol for interfacing interactive programs with a web server. FastCGI’s main aim is to reduce the overhead associated with interfacing the web server and CGI programs, allowing a server to handle more web page requests at once.
Also, PHP is not recommended with multithreaded Apache2 (worker MPM) because of performance and some 3rd party PHP extensions are not not guaranteed thread-safe.
nginx and lighttpd has inbuilt support for FastCGI. For Apache web server you need to use either mod_fastcgi or mod_fcgid.

In this quick tutorial, you will learn about Apache 2 + mod_fastcgi + PHP installation and configuration under Red Hat Enterprise Linux / CentOS Linux version 5.x+.

Step-1: Install mod_fastcgi

Make sure required packages are installed (httpd-devel and apr-devel required to compile mod_fastcgi), Issue the command
# yum install libtool httpd-devel apr-devel apr php php-fpm

Next, grab the latest mod_fastcgi source code, enter:
# cd /opt
# wget http://www.fastcgi.com/dist/mod_fastcgi-current.tar.gz

Untar tar ball, type:
# tar -zxvf mod_fastcgi-current.tar.gz
# cd mod_fastcgi-2.4.6/

Make a copy of Makefile.AP2, enter:
# cp Makefile.AP2 Makefile

Compile and install mod_fastcgi for 32 bit system, enter:
# make top_dir=/usr/lib/httpd
# make install top_dir=/usr/lib/httpd

Compile and install mod_fastcgi for 64 bit system, enter:
# make top_dir=/usr/lib64/httpd
# make install top_dir=/usr/lib64/httpd

Sample output:

make install top_dir=/usr/lib64/httpd
make[1]: Entering directory `/tmp/mod_fastcgi-2.4.6′
/usr/lib64/apr-1/build/libtool –silent –mode=install cp mod_fastcgi.la /usr/lib64/httpd/modules/
make[1]: Leaving directory `/tmp/mod_fastcgi-2.4.6′
Configure mod_fastcgi

Open /etc/httpd/conf.d/mod_fastcgi.conf file
# vi /etc/httpd/conf.d/mod_fastcgi.conf

Add an entry to it like this:
LoadModule fastcgi_module modules/mod_fastcgi.so

Save and close the file. Restart httpd, enter:
# service httpd restart

Sample output:

[Mon Dec 29 23:24:44 2008] [notice] caught SIGTERM, shutting down
[Mon Dec 29 23:24:44 2008] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Mon Dec 29 23:24:44 2008] [notice] Digest: generating secret for digest authentication …
[Mon Dec 29 23:24:44 2008] [notice] Digest: done
[Mon Dec 29 23:24:44 2008] [notice] FastCGI: process manager initialized (pid 4785)
[Mon Dec 29 23:24:44 2008] [notice] Apache/2.2.3 (CentOS) configured — resuming normal operations

Step-2: Configure PHP as FastCGI process

First, you need to disable mod_php5, enter:
# mv /etc/httpd/conf.d/php.conf /etc/httpd/conf.d/php.conf.disable

Create a file named fastcgi.conf
#vi /etc/httpd/conf.d/fastcgi.conf
Add the followings lines

####
LoadModule fastcgi_module modules/mod_fastcgi.so
#

# FastCGIExternalServer /usr/sbin/php-fpm -host 127.0.0.1:9000
FastCgiExternalServer /usr/sbin/php-fpm -socket /var/run/php-fpm/php-fpm.sock

AddHandler php-fastcgi .php
SetHandler php-fastcgi-virt
Action php-fastcgi-virt /usr/sbin/php-fpm.fcgi virtual

Action php-fastcgi /usr/sbin/php-fpm.fcgi
ScriptAlias /usr/sbin/php-fpm.fcgi /usr/sbin/php-fpm
Options ExecCGI FollowSymLinks
SetHandler fastcgi-script
Order allow,deny
Allow from all
#######################

Step-3: Configure php-fpm

#vi /etc/php-fpm.d/www.conf

Change the line below so that we can use socket instead of port

#listen = 127.0.0.1:9000

listen = /var/run/php-fpm/php-fpm.sock

#/etc/init.d/php-fpm restart

# service httpd restart

How to check if you’re behind a transparent caching proxy

Go to Start -> Run -> type cmd and press ENTER.
In the cmd window, type:
Code:
telnet 1.1.1.1 80

And press ENTER.
if Telnet freezes at “connecting to 1.1.1.1″ and then shows “failed to connect to host”, you’re not behind a transparent proxy.
if you see a black screen for about 20 seconds, and then a message about losing the connection to the host, then you are behind a transparent proxy.

To get extra details about this by sending a request When you get the black window, copy the following and right-click -> Paste it on Telnet:
Code:
TRACE / HTTP/1.1
Host: 1.1.1.1
Max-Forwards: 0

Then press ENTER twice. Depending on the server, you could get a response, for example:

Code:
HTTP/1.1 200 OK
Date: Fri, 29 Sep 2006 14:49:05 GMT
Content-Length: 82
Content-Type: message/http
Server: NetCache appliance (NetApp/6.0.3D2)