How to Compile suPHP+Apache2+PHP

คัดลอกจาก http://planetmy.com/blog/?p=67

Finally I’m manage to make my PHP 5.1.2 compiled with suPHP successful today suPHP is a tool for executing PHP scripts with the permissions of their owners. It consists of an Apache module (mod_suphp) and a setuid root binary (suphp) that is called by the Apache module to change the uid of the process executing the PHP interpreter.

I just would like to share about “How’s To Compile PHP + suPHP + Apache” as below:

Compile Apache Download Apache 2.0.5x

./configure –prefix=/usr/local/apache2 –enable-layout=Apache –enable-modules=all –enable-mods-shared=all –enable-proxy –enable-suexec –enable-so –with-mpm=prefork –with-suexec-caller=www –with-suexec-userdir=www –with-suexec-docroot=/home –with-suexec-logfile=/dev/null –with-suexec-safepath=/usr/local/bin:/usr/bin:/bin:/usr/home:/usr/sbin –disable-dav –disable-dav-fs

make; make install

Compile PHP Download PHP 5.1.2 * Remember you must have PHP CGI version to make suPHP work.

./configure –with-mysql=/var/lib/mysql –with-config-file-path=/etc –enable-force-cgi-redirect –enable-mbstring –with-jpeg-dir=/usr/lib –with-png-dir=/usr/lib –with-zlib-dir=/usr/lib –with-freetype-dir=/usr/lib –without-sqlite –with-mysql-sock=/tmp

make;make install

  • cp /root/software/php/php-5.1.2/sapi/cli/php /usr/local/bin/php.cli
  • cp /root/software/php/php-5.1.2/sapi/cli/php /usr/local/bin/php
  • cp /root/software/php/php-5.1.2/sapi/cgi/php /usr/local/bin/php.cgi

Compile suPHP Download suPHP

./configure –prefix=/usr/local –with-apache-user=www –with-logfile=/var/log/suphp.log –with-apxs=/usr/local/apache2/bin/apxs –with-min-uid=500 –with-min-gid=500 –with-php=/usr/local/bin/php.cgi

make;make install

  • cp /root/software/php/suphp-0.6.1/doc/suphp.conf-example /usr/local/etc/suphp.conf

vi /usr/local/etc/suphp.conf – and make sure correct:

logfile=/var/log/suphp.log webserver_user=www docroot=/ min_uid=500 min_gid=500 x-httpd-php=php:/usr/local/bin/php.cgi

Modify Apache2 – httpd.conf vi /usr/local/apache2/conf/httpd.conf

LoadModule suphp_module modules/mod_suphp.so AddHandler x-httpd-php .php AddType application/x-httpd-php-source .phps #Example: ServerAdmin admin@yourdomain.com DocumentRoot /home/yourdomainusername/www TransferLog /dev/null ErrorLog /var/apachelog/yourusername.com-error.log ServerName yourdomain.com SuexecUserGroup yourdomainusername yourdomainusername suPHP_Engine on suPHP_AddHandler x-httpd-php suPHP_UserGroup yourdomainusername yourdomainusername suPHP_ConfigPath /etc/

Testing vi /home/youdomainusername/www/info.php

< ? phpinfo(); ?>

Save the info.php file

  • chmod yourdomainusername.yourdomainusername info.php
  • Make sure yourdomainusername uid & gid is above 500
  • chmod 755 /home/yourdomainusername

vi /home/youdomainusername/www/write.php

< ?php $your_data = “write your data into this file.”; // Open the file and erase the contents if any $fp = fopen(“mywritefile.txt”, “w”); // Write the data to the file fwrite($fp, $your_data); // Close the file fclose($fp); echo ‘Write to the file done!’; ?>

Save the write.php file

  • chmod yourdomainusername.yourdomainusername write.php
  • Restart your apache server

/usr/local/apache2/bin/apachectl -t /usr/local/apache2/bin/apachectl stop /usr/local/apache2/bin/apachectl start

Open your browser and go to URL:

http://localhost/info.php

and

http://localhost/write.php

Gongratulations! if you can see info.php page and get a new file mywritefile.txt

If you need further help, you may check out suPHP malling list

Leave a Reply

Your email address will not be published. Required fields are marked *