Installing suPHP on CentOS

Installing suPHP in centOS.

Download the suPHP package first thru terminal.

wget http://www.suphp.org/download/suphp-0.7.1.tar.gz

then extract it.

tar -zxvf suphp-0.7.1.tar.gz

cd suphp-0.7.1.tar.gz

yum install gcc gcc-c++ httpd-devel

yum install make

./configure –with-apr=/usr/bin/apr-1-config –with-apache-user=apache –prefix=/usr

make && make install

vi /etc/httpd/conf/httpd.conf
Add below line
LoadModule suphp_module modules/mod_suphp.so

Add below line in the <Directory /> section of your websites.

suPHP_Engine on
suPHP_AddHandler application/x-httpd-php .php
suPHP_UserGroup webroot webroot

vi /etc/httpd/conf.d/php.conf

Add below line,

AddType application/x-httpd-php .php

Create a file called suphp.conf and should be place to /etc directory.

vi /etc/suphp.conf

[global]
;Path to logfile
logfile=/var/log/suphp/suphp.log

;Loglevel
loglevel=info

;User Apache is running as
webserver_user=apache

;Path all scripts have to be in
docroot=/var/www/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=true

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

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

; Minimum UID
min_uid=408

; Minimum GID
min_gid=400

[handlers]
;Handler for php-scripts
;x-httpd-php=”php:/usr/bin/php-cgi”

;Handler for CGI-scripts
x-suphp-cgi=”execute:!self”
application/x-httpd-php=”php:/usr/bin/php”
application/x-httpd-php4=”php:/usr/php4/bin/php”
application/x-httpd-php5=”php:/usr/bin/php”

Restart the service by executing the command below.

/etc/init.d/httpd restart

Create two users as an example.

 

adduser choi; add choi as a user

adduser cool; add cool as a user

Upload a test script for example whoami.php

/***********code starts here****************/

<?php
echo “Output of the ‘whoami’ command:<br /><br />”;
echo exec(‘/usr/bin/whoami’);
?>

/***********code ends here****************/

Change the owner of whoami.php file to the users that you have just created.

chown choi:choi whoami.php

-rwxr-xr-x 1 choi  choi    94 Nov 30 16:37 whoami.php

chown cool:cool whoami.php

-rwxr-xr-x 1 cool  cool    94 Nov 30 16:37 whoami.php

chmod 755 whoami.php

-rwxr-xr-x 1 cool  cool    94 Nov 30 16:37 whoami.php
-rwxr-xr-x 1 cool  cool    94 Nov 30 16:37 whoami.php

NOTE: the script will only be viewable at this permission 644 – 755; if > 755 then it will show an error message.

 

Leave a Reply