Compile and Install SuPHP + Apache2.2.x + PHP-5.2.x or PHP-5.3.x


Compile and Install SuPHP + Apache2.2.x + PHP-5.2.x or PHP-5.3.x



***It is needed php-cgi binary file to compile SuPHP. In the default source compilation, php-cgi binary file will not be generated in PHP-5.2.x and PHP-5.3.x. So first you have to compile PHP for php-cgi. You need to compile twice in this case.

***If you are compiling Apache2.2.x with PHP-5.4.x, there is no need to compile twice. You can remove the first compilation in the script given below.

***If you have any problem with the PHP installation, please refer the following url.
http://linuxadmintips4u.blogspot.in/2013/05/complile-and-install-php-from-source.html
---------------------------------------------------------------------------------------------------------------------------------
***If you have already compiled PHP + Apache, just do only configure part and make of First compilation. Do not enter make install. Then you can manually copy 'php-cgi' from 'sapi/cgi/' to bin directory of php's installation directory. Here in my case it is /usr/local/php/bin
You can find 'sapi/cgi/' directory in the extracted tar package. php-cgi binary will generate there once you have done configure and make.

[root@vps php-5.3.24]# cp sapi/cgi/php-cgi /usr/local/php/bin/
----------------------------------------------------------------------------------------------------------------------------------


Create a script, configure.sh in the extracted source directory of php, with the following contents in it.

[root@vps php-5.3.24]# cat configure.sh
#=================================================================


#!/bin/bash
#First compilation for 'php-cgi' binary.
#Please note, --with-apxs2=/usr/local/apache/bin/apxs is excluded in the first compilation.
#Please note, --disable-cli and --enable-cgi are only in the first compilation. It is excluded in the second compilation.

"./configure" \
"--prefix=/usr/local/php" \
"--with-config-file-path=/usr/local/apache/conf" \
"--disable-debug" \
"--disable-rpath" \
"--enable-inline-optimization" \
"--enable-sockets" \
"--enable-wddx" \
"--enable-calendar" \
"--enable-ftp" \
"--enable-mbstring=all" \
"--enable-dom" \
"--enable-mbregex" \
"--enable-bcmath" \
"--with-openssl" \
"--with-kerberos" \
"--with-mcrypt" \
"--with-curl" \
"--with-gd" \
"--with-zlib-dir=/usr/lib" \
"--with-jpeg-dir=/usr/lib" \
"--with-png-dir=/usr/lib" \
"--with-freetype-dir=/usr/lib" \
"--with-regex=system" \
"--with-gettext" \
"--with-bz2" \
"--with-iconv" \
"--with-layout=GNU" \
"--with-imap=/usr/local/src/imap-2007f" \
"--with-imap-ssl" \
"--enable-ftp" \
"--enable-calendar" \
"--with-curl" \
"--enable-soap" \
"--with-snmp" \
"--with-libdir=lib64" \
"--with-mysql=/usr/local/mysql" \
"--with-pdo-mysql" \
"--disable-cli" \
"--enable-cgi"

make && make install
#Firtst compilation ends here.

make clean

#Second compilation for 'php' cli binary.

"./configure" \
"--prefix=/usr/local/php" \
"--with-apxs2=/usr/local/apache/bin/apxs" \
"--with-config-file-path=/usr/local/apache/conf" \
"--disable-debug" \
"--disable-rpath" \
"--enable-inline-optimization" \
"--enable-sockets" \
"--enable-wddx" \
"--enable-calendar" \
"--enable-ftp" \
"--enable-mbstring=all" \
"--enable-dom" \
"--enable-mbregex" \
"--enable-bcmath" \
"--with-openssl" \
"--with-kerberos" \
"--with-mcrypt" \
"--with-curl" \
"--with-gd" \
"--with-zlib-dir=/usr/lib" \
"--with-jpeg-dir=/usr/lib" \
"--with-png-dir=/usr/lib" \
"--with-freetype-dir=/usr/lib" \
"--with-regex=system" \
"--with-gettext" \
"--with-bz2" \
"--with-iconv" \
"--with-layout=GNU" \
"--with-imap=/usr/local/src/imap-2007f" \
"--with-imap-ssl" \
"--enable-ftp" \
"--enable-calendar" \
"--with-curl" \
"--enable-soap" \
"--with-snmp" \
"--with-libdir=lib64" \
"--with-mysql=/usr/local/mysql" \
"--with-pdo-mysql"

make && make install
#Second compilation ends here.

#=================================================================



[root@vps php-5.3.24]# chmod +x configure.sh

[root@vps php-5.3.24]# sh configure.sh


Complile SuPHP


[root@vps ~]# cd /usr/local/src/
[root@vps src]# wget http://www.suphp.org/download/suphp-0.7.1.tar.gz
[root@vps src]# tar -xzf suphp-0.7.1.tar.gz

***The package, suphp-0.7.1.tar.gz cannot install with Apache2.4.x. You will get errors while using 'make'. You need to patch it before using it.
***There is no need to patch suphp-0.7.1 if you are compiling with Apache-2.2.x and Apache-2.0.x


[root@vps src]# wget -O fix1.diff https://sites.google.com/site/sudosuin/fix.diff
[root@vps src]# patch -Np1 -d suphp-0.7.1 < fix.diff
patching file configure.ac
patching file src/Makefile.am
patching file src/Makefile.in


[root@vps src]# cd suphp-0.7.1

-------------------------------------------------------------------------------------------------------------------------------------
Locate the location of 'php-cgi' binary file and the binary file location must be specifiled as --with-php=<php-cgi path>
[root@vps ~]# locate php-cgi
/usr/local/php/bin/php-cgi

Locate the location of 'apxs' binary file and the binary file location must be specifiled as --with-apxs=<apxs path>
[root@vps ~]# locate apxs
/usr/local/apache/bin/apxs

Locate the location of 'apr-1-config' binary file and the binary file location must be specifiled as --with-apr=<apr-1-config path>
[root@vps ~]# locate apr-1-config
/usr/local/apr/bin/apr-1-config

---------------------------------------------------------------------------------------------------------------------------------------


[root@vps suphp-0.7.1]# ./configure \
--with-logfile=/var/log/suphp.log \
--with-apxs=/usr/local/apache/bin/apxs \
--with-php=/usr/local/php/bin/php-cgi \
--with-apr=/usr/local/apr/bin/apr-1-config \
--with-setid-mode=paranoid \
--with-gnu-ld \
--disable-checkpath \
--with-apache-user=apache


[root@vps suphp-0.7.1]# make

If there is any error in 'make' try the following two steps also. You can find header files missing error in 'make'. In that case you have to do the header files copy steps as shown below.

Here i have installed apr in /usr/local/apr , apr-uil in /usr/local/apr-util and apache in /usr/local/apache. If you have installed these in any other locations, you have to modify the document root of apr, apr-util and apache in the following two copy commands.

[root@vps ~]# cp /usr/local/apr/include/apr-1/*.h /usr/local/apache/include/
[root@vps ~]# cp /usr/local/apr-util/include/apr-1/*.h /usr/local/apache/include/


[root@vps suphp-0.7.1]# make install

Once you have successfully compiled suphp, you have to do the following configurations.

----------------------------------------------------------------------------------------------
Create a file named /usr/local/apache/conf/suphp.conf with the following contents.

[root@vps ~]# cat /usr/local/apache/conf/suphp.conf
LoadModule suphp_module modules/mod_suphp.so
suPHP_Engine on
AddType application/x-httpd-php .php
suPHP_AddHandler application/x-httpd-php
suPHP_UserGroup apache apache

----------------------------------------------------------------------------------------------


Create a file named /etc/suphp.conf with the following contents.

[root@vps ~]# cat /etc/suphp.conf
[global]
;Path to logfile
logfile=/var/log/suphp.log

;Loglevel
loglevel=info

;User Apache is running as
webserver_user=apache

;Path all scripts have to be in
;docroot=/var/www:${HOME}/public_html:/home/httpd/html/

;Path to chroot() to before executing script
;chroot=/mychroot

; Security options
allow_file_group_writeable=false
allow_file_others_writeable=false
allow_directory_group_writeable=false
allow_directory_others_writeable=false

;Check wheter script is within DOCUMENT_ROOT
check_vhost_docroot=true

;Send minor error messages to browser
errors_to_browser=false

;PATH environment variable
env_path=/bin:/usr/bin:/usr/local/php/bin

;Umask to set, specify in octal notation
umask=0022

; Minimum UID
min_uid=0

; Minimum GID
min_gid=0

[handlers]
application/x-httpd-php="php:/usr/local/php/bin/php-cgi"
x-suphp-cgi="execute:!self"

---------------------------------------------------------------------------------------------------

Open Apache configuration file (httpd.conf) and remove the following entry

LoadModule php5_module        modules/libphp5.so

----------------------------------------------------------------------------------------------------
Add the following entry in httpd.conf

Include conf/suphp.conf

----------------------------------------------------------------------------------------------------

Change the following entriens as follows in httpd.conf

User apache
Group apache

------------------------------------------------------------------------------------------------------

Once you have done the following settings, restart apache service and check suphp module is loaded or not.

[root@vps ~]# httpd -M | grep suphp
 suphp_module (shared)

Create a phpinfo page in /usr/local/apache/htdocs and given permission 644 and owner, group as apache and apache. Check if the php page is loading or not. If it is not loading, check the error in /usr/local/apache/logs/error_log.





Notes:-

Here i have used following url to install PHP-5.2.x and PHP-5.3.x
http://linuxadmintips4u.blogspot.in/2013/05/complile-and-install-php-from-source.html

Here i have used the following url to install Apache-2.2.x
http://www.sudosu.in/2012/07/configure-apache.html


This entry was posted in by Unknown. Bookmark the permalink.

Leave a Reply