{"id":67,"date":"2012-11-20T20:53:00","date_gmt":"2012-11-20T20:53:00","guid":{"rendered":"https:\/\/www.tech-and-dev.com\/blog\/2012\/11\/20\/installing-suphp-on-centos-with-virtualmin-webmin\/"},"modified":"2021-02-22T01:01:05","modified_gmt":"2021-02-22T01:01:05","slug":"installing-suphp-on-centos-with-virtualmin-webmin","status":"publish","type":"post","link":"https:\/\/www.tech-and-dev.com\/blog\/2012\/11\/installing-suphp-on-centos-with-virtualmin-webmin.html","title":{"rendered":"Installing suPHP on CentOS With Virtualmin\/Webmin"},"content":{"rendered":"<div dir=\"ltr\" style=\"text-align: left;\">\n<p>&nbsp;<\/p>\n<div style=\"clear: both; text-align: center;\"><a style=\"margin-left: 1em; margin-right: 1em;\" href=\"https:\/\/www.tech-and-dev.com\/blog\/wp-content\/uploads\/2021\/02\/suphp_logo1.png\"><img decoding=\"async\" title=\"suPHP\" src=\"https:\/\/www.tech-and-dev.com\/blog\/wp-content\/uploads\/2021\/02\/suphp_logo1.png\" alt=\"suPHP\" border=\"0\" \/><\/a><\/div>\n<h2 style=\"text-align: left;\">What is suPHP?<\/h2>\n<div style=\"text-align: justify;\">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.<\/div>\n<div style=\"text-align: justify;\">suPHP can enhance the security because the PHP scripts will\u00a0 run as the webserver user and not as &#8220;root&#8221; or &#8220;nobody&#8221;. So if a different webuser has a vulnerable script installed, it will not affect your scripts.<\/div>\n<div style=\"text-align: justify;\"><\/div>\n<div style=\"text-align: justify;\"><\/div>\n<div style=\"text-align: justify;\">\n<h2>Installing suPHP<\/h2>\n<\/div>\n<p>Login to your root server using SSH<br \/>\nEnter the following command<\/p>\n<div style=\"background: black; padding: 5px;\"><span style=\"color: white;\">yum install mod_suphp<\/span><\/div>\n<p>If you get an error that the package doesn&#8217;t exist, you have to install RPMforge repository.<\/p>\n<p>If you don&#8217;t know what&#8217;s your server architecture (32 bit or 64 bit), you can find out using the following command:<\/p>\n<div style=\"background: black; padding: 5px;\"><span style=\"color: white;\">uname -i<\/span><\/div>\n<p><b><br \/>\n<\/b><br \/>\n<b>For CentOS 6 64 bit:<\/b><\/p>\n<div style=\"background: black; padding: 5px;\"><span style=\"color: white;\">rpm -i http:\/\/packages.sw.be\/rpmforge-release\/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm<\/span><\/div>\n<p><b>For CentOS 6 32 bit:<\/b><\/p>\n<div style=\"background: black; padding: 5px;\"><span style=\"color: white;\">rpm -i http:\/\/packages.sw.be\/rpmforge-release\/rpmforge-release-0.5.2-2.el6.rf.i686.rpm<\/span><\/div>\n<p><b>For CentOS 5 64 bit:<\/b><\/p>\n<div style=\"background: black; padding: 5px;\"><span style=\"color: white;\">rpm -i http:\/\/packages.sw.be\/rpmforge-release\/rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm<\/span><\/div>\n<p><b>For CentOS 5 32 bit:<\/b><\/p>\n<div style=\"background: black; padding: 5px;\"><span style=\"color: white;\">rpm -i http:\/\/packages.sw.be\/rpmforge-release\/rpmforge-release-0.5.2-2.el5.rf.i386.rpm<\/span><\/div>\n<p>Now install mod_suphp again:<\/p>\n<div style=\"background: black; padding: 5px;\"><span style=\"color: white;\">yum install mod_suphp<\/span><\/div>\n<div style=\"text-align: justify;\"><\/div>\n<div style=\"text-align: justify;\">\n<p>&nbsp;<\/p>\n<h2>Configuring suPHP<\/h2>\n<\/div>\n<div style=\"text-align: justify;\">\n<p>After installing suPHP, you will have two new configuration files:<br \/>\n<b>\/etc\/suphp.conf<\/b> &#8211; This is the configuration file for suPHP<br \/>\n<b>\/etc\/httpd\/conf.d\/suphp.conf<\/b> &#8211; This is the configuration file for the suPHP and Apache module<\/p>\n<p><b><span style=\"font-size: large;\">Edit the suPHP configuration file first:<\/span><\/b><\/p>\n<div style=\"background: black; padding: 5px;\"><span style=\"color: #f3f3f3;\">vi \/etc\/suphp.conf<\/span><\/div>\n<div style=\"text-align: justify;\">\n<p>Make sure that the value of <b>webserver_user=apache<\/b><\/p>\n<div style=\"background: silver; padding: 5px;\">webserver_user=apache<\/div>\n<p>Change the value <b>x-httpd-php=php:\/usr\/bin\/php<\/b> to:<\/p>\n<div style=\"background: silver; padding: 5px;\">x-httpd-php=&#8221;php:\/usr\/bin\/php-cgi&#8221;<\/div>\n<p>Change the value <b>x-suphp-cgi=execute:!self<\/b> to:<\/p>\n<\/div>\n<div style=\"background: silver; padding: 5px;\">x-suphp-cgi=&#8221;execute:!self&#8221;<\/div>\n<p>&nbsp;<\/p>\n<\/div>\n<div style=\"text-align: justify;\">\n<p>That&#8217;s how your <b>\/etc\/suphp.conf<\/b> should look like (You can just copy\/paste it if you want):<\/p>\n<div style=\"background: silver; padding: 5px;\">\n<p>[global]<br \/>\nlogfile=\/var\/log\/httpd\/suphp_log<br \/>\nloglevel=info<br \/>\nwebserver_user=apache<br \/>\ndocroot=\/<br \/>\nenv_path=\/bin:\/usr\/bin<br \/>\numask=0022<br \/>\nmin_uid=500<br \/>\nmin_gid=500<\/p>\n<p>; Security options<br \/>\nallow_file_group_writeable=true<br \/>\nallow_file_others_writeable=false<br \/>\nallow_directory_group_writeable=true<br \/>\nallow_directory_others_writeable=false<\/p>\n<p>;Check wheter script is within DOCUMENT_ROOT<br \/>\ncheck_vhost_docroot=true<\/p>\n<p>;Send minor error messages to browser<br \/>\nerrors_to_browser=false<\/p>\n<p>[handlers]<br \/>\n;Handler for php-scripts<br \/>\nx-httpd-php=&#8221;php:\/usr\/bin\/php-cgi&#8221;<\/p>\n<p>;Handler for CGI-scripts<br \/>\nx-suphp-cgi=&#8221;execute:!self&#8221;<\/p>\n<\/div>\n<p><b><span style=\"font-size: large;\">Edit \/etc\/httpd\/conf.d\/suphp.conf<\/span><\/b><\/p>\n<div style=\"background: black; padding: 5px;\"><span style=\"color: #f3f3f3;\">vi \/etc\/httpd\/conf.d\/suphp.conf<\/span><\/div>\n<p>Delete everything inside the \/etc\/httpd\/conf.d\/suphp.conf (or comment them), except the following line:<\/p>\n<div style=\"background: silver; padding: 5px;\">LoadModule suphp_module modules\/mod_suphp.so<\/div>\n<p>We do this to disable suPHP globally, specially if you have more than one virtual host and more than one user, and we enable suPHP below on the virtual hosts in order to run the php scripts as their owner user.<\/p>\n<p><b><span style=\"font-size: large;\">Editing httpd.conf<\/span><\/b><br \/>\nGo to your Webmin tab =&gt; Servers =&gt; Apache Webservers =&gt; Global Configuration =&gt; Edit Config File<\/p>\n<div style=\"clear: both; text-align: center;\"><a style=\"margin-left: 1em; margin-right: 1em;\" href=\"https:\/\/www.tech-and-dev.com\/blog\/wp-content\/uploads\/2021\/02\/editconfigvirtualhost.png\"><img decoding=\"async\" title=\"Apache Edit Config Files\" src=\"https:\/\/www.tech-and-dev.com\/blog\/wp-content\/uploads\/2021\/02\/editconfigvirtualhost.png\" alt=\"Apache Edit Config Files\" border=\"0\" \/><\/a><\/div>\n<p>Make sure the <b>\/etc\/httpd\/conf\/httpd.conf <\/b>is selected,<br \/>\nFind all the &lt;virtualHost&gt; directives and add the following inside everyone:<\/p>\n<div style=\"background: silver; padding: 5px;\">suPHP_Engine on<br \/>\nsuPHP_UserGroup <i><b>userName groupName<\/b><\/i><br \/>\nAddHandler x-httpd-php .php .php3 .php4 .php5<br \/>\nsuPHP_AddHandler x-httpd-php<\/div>\n<p>Replace <i><b>userName<\/b><\/i> and <i><b>groupName<\/b><\/i> by your linux user and group respectively.<\/p>\n<p>If you don&#8217;t know what&#8217;s your <b>userName<\/b> and <b>groupName<\/b> are, go to <b>VirtualMin<\/b> tab, choose the virtual server you&#8217;re editing and you will see the user and group name, in my case, it&#8217;s &#8220;lab&#8221; and &#8220;lab&#8221;<\/p>\n<div style=\"clear: both; text-align: center;\"><a style=\"margin-left: 1em; margin-right: 1em;\" href=\"https:\/\/www.tech-and-dev.com\/blog\/wp-content\/uploads\/2021\/02\/labtechanddev.png\"><img decoding=\"async\" title=\"lab tech and dev\" src=\"https:\/\/www.tech-and-dev.com\/blog\/wp-content\/uploads\/2021\/02\/labtechanddev.png\" alt=\"lab tech and dev\" border=\"0\" \/><\/a><\/div>\n<p>My modified Virtual Host look like the following:<\/p>\n<div style=\"background: silver; padding: 5px;\">&lt;VirtualHost *:80&gt;<br \/>\nSuexecUserGroup &#8220;#507&#8221; &#8220;#506&#8221;<br \/>\nServerName lab.tech-and-dev.com<br \/>\nServerAlias www.lab.tech-and-dev.com<br \/>\nDocumentRoot \/home\/lab\/public_html<br \/>\nScriptAlias \/cgi-bin\/ \/home\/lab\/cgi-bin\/<br \/>\nsuPHP_Engine on<br \/>\nsuPHP_UserGroup lab lab<b><br \/>\n<\/b>AddHandler x-httpd-php .php .php3 .php4 .php5<br \/>\nsuPHP_AddHandler x-httpd-php<\/div>\n<p>If you were using FastCgi (FCGI), you will have to remove (or comment) the following lines<\/p>\n<div style=\"background: silver; padding: 5px;\">AddHandler fcgid-script .php<br \/>\nAddHandler fcgid-script .php5<br \/>\nFCGIWrapper \/home\/example\/fcgi-bin\/php5.fcgi .php<br \/>\nFCGIWrapper \/home\/example\/fcgi-bin\/php5.fcgi .php5<\/div>\n<p><span style=\"font-size: large;\"><b>Editing Virtual Hosts default Template<\/b><\/span><br \/>\nOne last thing is we have to add suPHP as the default php handler for the new virtual hosts.<\/p>\n<ul>\n<li>Go to Virtualmin tab<\/li>\n<li>Click System Settings<\/li>\n<li>Click Server Templates<\/li>\n<li>Choose your template (or click on Default Settings if you haven&#8217;t created a template)<\/li>\n<li>On top, next to &#8220;Edit template section&#8221;, choose &#8220;<b>Apache Website<\/b>&#8220;<\/li>\n<li>Below the <b>DocumentRoot ${HOME}\/public_html<\/b>, add the following:<\/li>\n<li>\n<div style=\"background: none repeat scroll 0% 0% silver; padding: 5px;\">suPHP_Engine on<br \/>\nsuPHP_UserGroup ${USER} ${GROUP}<b><br \/>\n<\/b>AddHandler x-httpd-php .php .php3 .php4 .php5<br \/>\nsuPHP_AddHandler x-httpd-php<\/div>\n<\/li>\n<li>So overall it will look like this:<\/li>\n<li>\n<div style=\"background: none repeat scroll 0% 0% silver; padding: 5px;\">ServerName ${DOM}<br \/>\nServerAlias www.${DOM}<br \/>\nDocumentRoot ${HOME}\/public_html<br \/>\nsuPHP_Engine on<br \/>\nsuPHP_UserGroup ${USER} ${GROUP}<br \/>\nAddHandler x-httpd-php .php .php3 .php4 .php5<br \/>\nsuPHP_AddHandler x-httpd-php<br \/>\nErrorLog \/var\/log\/virtualmin\/${DOM}_error_log<br \/>\nCustomLog \/var\/log\/virtualmin\/${DOM}_access_log combined<\/div>\n<\/li>\n<li>Scroll down and change <b>Default PHP execution mode<\/b> to <b>Apache mod_php (run as Apache&#8217;s user)<\/b><\/li>\n<\/ul>\n<p><b><span style=\"font-size: large;\">Restart Apache<\/span><\/b><\/p>\n<div style=\"background: black; padding: 5px;\"><span style=\"color: white;\">service httpd restart<\/span><\/div>\n<p>Try to access your website now.<\/p>\n<\/div>\n<div style=\"text-align: justify;\">\n<h2>Problems and Solutions<\/h2>\n<p>If you get a 500 error, make sure your directories and files permissions are correct. Directories should have permission 755 and files should have permission 644.<\/p>\n<p><b>Any questions? Please leave your comment below!<\/b><\/p>\n<p>&nbsp;<\/p>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; What is suPHP? 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. suPHP can enhance the security because [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[48,17,11,6,22,7,81,41,82],"tags":[],"class_list":["post-67","post","type-post","status-publish","format-standard","hentry","category-apache","category-centos","category-commands","category-linux","category-php","category-ssh","category-suphp","category-virtualmin","category-webmin"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/posts\/67","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/comments?post=67"}],"version-history":[{"count":1,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/posts\/67\/revisions"}],"predecessor-version":[{"id":216,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/posts\/67\/revisions\/216"}],"wp:attachment":[{"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/media?parent=67"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/categories?post=67"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/tags?post=67"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}