An apache php fastcgid suexec cpanel story
I wanted to get fastcgid running on cpanel/whm, so I went to easyApache and selected to compile apche with fastcgid support and php with fastcgi support, but guess what – it wasn’t working! they just ignored the settings and php was compiled without fastcgi in it.
So back to the beggining, dreaming of my lost time figuring out what the heck was wrong with whm/cpanel/easyapache I turned to plan B.
I recompiled apache still with easyapache from whm but without php. Further more I also choosed MPM worker module to improve the way static content is served. (!!! mpm worker is not compatible with PHP as an apache module)
Next step I compiled php from source – see my other article regarding compiling php from source and checking what I used as ./configure command.
Note: if you don’t have mod_fcgid module installed do this command in the directory you extracted the mod_fcgid archive that you got from apache website:
./configure.apxs
make
make install
I went to httpd.cnf -> on my system was on /usr/local/apache/conf and added the following lines:
AddHandler fcgid-script .php
Options +ExecCGI
FcgidWrapper /home/user/php-wrapper .php
Order allow,deny
Allow from all
Now I create the wrapper that will execute the php:
cd /home/user
sudo vi php-wrapper
add this inside the file:
#!/bin/sh
exec /usr/local/php-5.3.2-fcgi/bin/php-cgi
then, some security aspects (it’s required by suexec and it’s nice organizing things a little):
sudo chown user.nobody php-wrapper
sudo chmod 550 php-wrapper
cd ..
sudo chown -R user.nobody user/public_html
sudo chmod -R 0750 user/public_html
as a real world example:
chown alex.nobody /home/alex/php-wrapper
chmod 550 /home/alex/php-wrapper
chown -R alex.nobody /home/alex/public_html
chmod -R 0750 /home/alex/public_html
chmod -R g+s /home/alex/public_html
!Make sure you change the path of the fcgid wrapper to fit your php directory you have just compiled.
make sure suexec is enabled (it’s installed by default in whm, and you can enabled from php&sexec configuration section)
Restart apache and that’s it, or should I say… good luck 🙂
Note: you need to learn how to optimize fcgid config variables and because mpm worker was also installed, it’s corresponding configuration variables as well. But till you do, the default will be just fine.
Please study the instructions and make sure you understand them before breaking a live server