• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

PHP Fastcgi

B

blaich

Guest
Hi guys,

i wish for the future an installation model with a php via fastcgi support.
I think mod_php is outdated and has a lot of disadvantages i.e. php runs as an apache worker and users can't delete sometimes their datas via ftp, because they are owned by the webserver.... or the safe_mod problem.
Nowadays every ISP without plesk has the fastcgi support.

Thank you

Greets chris
 
Hi

it´s possible to do that....so you have to create some scripts and put it in /usr/local/psa/bin
and use the event handler in the psa panel to "create" the files on "domain created"

here are the scripts

for create the vhost.file
Code:
touch /var/www/vhosts/${1}/conf/vhost.conf
echo "<Directory /var/www/vhosts/${1}/httpdocs/>" > /var/www/vhosts/${1}/conf/vhost.conf
echo "AddHandler fcgid-script .php" >> /var/www/vhosts/${1}/conf/vhost.conf
echo "Options +ExecCGI +FollowSymLinks" >> /var/www/vhosts/${1}/conf/vhost.conf
echo "FCGIWrapper /var/www/vhosts/${1}/bin/php.fcgi .php" >> /var/www/vhosts/${1}/conf/vhost.conf
echo "</Directory>" >> /var/www/vhosts/${1}/conf/vhost.conf
use this to create for every domain her own php.ini
Code:
#!/bin/bash
cp /etc/php.ini.min /var/www/vhosts/${NEW_DOMAIN_NAME}/bin/php.ini
chown ${NEW_SYSTEM_USER}:psacln /var/www/vhosts/${NEW_DOMAIN_NAME}/bin/
chown ${NEW_SYSTEM_USER}:psacln /var/www/vhosts/${NEW_DOMAIN_NAME}/bin/php.ini
cd /var/www/vhosts/${NEW_DOMAIN_NAME}/bin
and the script for the php.fcgi
Code:
#!/bin/bash
touch /var/www/vhosts/${NEW_DOMAIN_NAME}/bin/php.fcgi
chown ${NEW_SYSTEM_USER}:psacln /var/www/vhosts/${NEW_DOMAIN_NAME}/bin/
chown ${NEW_SYSTEM_USER}:psacln /var/www/vhosts/${NEW_DOMAIN_NAME}/bin/php.ini
chown ${NEW_SYSTEM_USER}:psacln /var/www/vhosts/${NEW_DOMAIN_NAME}/bin/php.fcgi
chmod 555  /var/www/vhosts/${NEW_DOMAIN_NAME}/bin/php.fcgi 
echo '#!/bin/sh' >/var/www/vhosts/${NEW_DOMAIN_NAME}/bin/php.fcgi
echo '' >> /var/www/vhosts/${NEW_DOMAIN_NAME}/bin/php.fcgi
echo 'export PHP_FCGI_CHILDREN=4' >>/var/www/vhosts/${NEW_DOMAIN_NAME}/bin/php.fcgi
echo 'export PHP_FCGI_MAX_REQUESTS=500'>>/var/www/vhosts/${NEW_DOMAIN_NAME}/bin/php.fcgi 
echo 'exec /usr/bin/php-cgi -c /var/www/vhosts/'${NEW_DOMAIN_NAME}'/bin/php.ini $@'>>/var/www/vhosts/${NEW_DOMAIN_NAME}/bin/php.fcgi
chmod 555 /var/www/vhosts/${NEW_DOMAIN_NAME}/bin/php.fcgi

then you change the suexec file with
Code:
cp /usr/local/psa/suexec/psa-suexec /usr/sbin/suexec

at least activate the "FastCGI" checkbox under setup for the domain.
This works for me perfect

best regards
ACID25
 
Apparently suPHP also solves this problem:

"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."



Would be nice if Plesk would integrate this.
 
Hi ACID25,

i tested what u said.
I created the folowing files, with exactly that what u said (copy/paste):
Code:
#
/usr/local/psa/bin/create_vhost.sh 
/usr/local/psa/bin/create_phpini.sh
/usr/local/psa/bin/create_phpfcgi.sh
/usr/local/psa/bin/mv_suexec.sh
#
After this, I created a new job -> domain created with the following commandline
Code:
#!/bin/bash
#
/usr/local/psa/bin/create_vhost.sh >> /tmp/log
/usr/local/psa/bin/create_phpini.sh >> /tmp/log
/usr/local/psa/bin/create_phpfcgi.sh >> /tmp/log
/usr/local/psa/bin/mv_suexec.sh >> /tmp/log

1. It doesn't work, there is no vhost.conf in the conf dir
2. There is no entry in the log file
3. There is no /etc/php.ini.min !?

Thx for helping....
 
how much memory is "a lot" ? How comporable to mod_suphp in features and memory use is this?
Also, does the php-cgi process run as the ftp user or does it run as apache?
So if you looked at lsof or top you would see the process running and the ftp user?
 
Hello,

the php-cgi process is running at the user which owns the requested file (often the ftp-user).
I'm sorry, but i have no comparison between mod_suphp and fastcgi memory usage.

best regards
Lars
 
I don´t understand this.

what must in the event Command line from the event handler?
all the skripts?

I need more information.

which files must in this folder? -> /usr/local/psa/bin

thx for help
 
Hello,

the php-cgi process is running at the user which owns the requested file (often the ftp-user).
I'm sorry, but i have no comparison between mod_suphp and fastcgi memory usage.

best regards
Lars

What is the average memory usage of each php-cgi process?
 
In general you need 2-4 times more RAM in your server, when you use php-cgi. So don't load up the patch on a busy server you haven't upgraded with (enough) memory. If it's a clean server with no domains you can easily implement the patch, and see how the ongoing memory consumption behaves.
But as always there's a risk with great flexibility.
 
Looks like this is no longer relevant as plesk 9.0 will natively include three different ways to run php, as a cgi, fcgi, and apache module.
 
Back
Top