Add PHP-FPM Support for Apache2
+1 vote
You can vote here
https://bugs.vestacp.com/issues/307
a2enmod proxy_fcgi actions alias fastcgi
a2dismod php mpm_prefork
a2enmod mpm_event
apt-get install php5-fpm
a2enconf php5-fpm
service apache2 reload
## php5-fpm.tpl
_Note i added the %backend_lsnr_cust% var, i will replace that with the .sh file_
/usr/local/vesta/data/templates/web/apache2/
<VirtualHost %ip%:%web_port%>
ServerName %domain_idn%
%alias_string%
ServerAdmin %email%
DocumentRoot %docroot%
ScriptAlias /cgi-bin/ %home%/%user%/web/%domain%/cgi-bin/
Alias /vstats/ %home%/%user%/web/%domain%/stats/
Alias /error/ %home%/%user%/web/%domain%/document_errors/
SuexecUserGroup %user% %group%
CustomLog /var/log/%web_system%/domains/%domain%.bytes bytes
CustomLog /var/log/%web_system%/domains/%domain%.log combined
ErrorLog /var/log/%web_system%/domains/%domain%.error.log
<Directory %docroot%>
AllowOverride All
Options +Includes -Indexes +ExecCGI
DirectoryIndex index.php index.html index.htm
<FilesMatch \.php$>
SetHandler "proxy:fcgi://%backend_lsnr_cust%"
</FilesMatch>
</Directory>
<Directory %home%/%user%/web/%domain%/stats>
AllowOverride All
</Directory>
IncludeOptional %home%/%user%/conf/web/%web_system%.%domain%.conf*
</VirtualHost>
## php5-fpm.stpl
_Note i added the %backend_lsnr_cust% var, i will replace that with the .sh file_
/usr/local/vesta/data/templates/web/apache2/
<VirtualHost %ip%:%web_ssl_port%>
ServerName %domain_idn%
%alias_string%
ServerAdmin %email%
DocumentRoot %sdocroot%
ScriptAlias /cgi-bin/ %home%/%user%/web/%domain%/cgi-bin/
Alias /vstats/ %home%/%user%/web/%domain%/stats/
Alias /error/ %home%/%user%/web/%domain%/document_errors/
SuexecUserGroup %user% %group%
CustomLog /var/log/%web_system%/domains/%domain%.bytes bytes
CustomLog /var/log/%web_system%/domains/%domain%.log combined
ErrorLog /var/log/%web_system%/domains/%domain%.error.log
<Directory %sdocroot%>
SSLRequireSSL
AllowOverride All
Options +Includes -Indexes +ExecCGI
DirectoryIndex index.php index.html index.htm
<FilesMatch \.php$>
SetHandler "proxy:fcgi://%backend_lsnr_cust%"
</FilesMatch>
</Directory>
<Directory %home%/%user%/web/%domain%/stats>
AllowOverride All
</Directory>
SSLEngine on
SSLVerifyClient none
SSLCertificateFile %ssl_crt%
SSLCertificateKeyFile %ssl_key%
%ssl_ca_str%SSLCertificateChainFile %ssl_ca%
IncludeOptional %home%/%user%/conf/web/s%web_system%.%domain%.conf*
</VirtualHost>
## php5-fpm.sh
/usr/local/vesta/data/templates/web/apache2/
user="$1"
domain="$2"
ip="$3"
home_dir="$4"
docroot="/home/$user/web/$domain/public_html"
WEB_BACKEND="php5-fpm"
template="php5-dynamic"
WEBTPL="/usr/local/vesta/data/templates/web/php5-fpm"
if [ -d "/etc/php-fpm.d" ]; then
pool="/etc/php-fpm.d"
fi
if [ -d "/etc/php5/fpm/pool.d" ]; then
pool="/etc/php5/fpm/pool.d"
fi
if [ ! -e "$pool" ]; then
pool=$(find /etc/php* -type d \( -name "pool.d" -o -name "*fpm.d" \))
if [ ! -e "$pool" ]; then
check_result $E_NOTEXIST "php-fpm pool doesn't exist"
fi
fi
ubic="$pool/$domain.conf"
# Allocating backend port
if [ ! -e "$ubic" ]; then
#PHP-FPM 5 starts in 9000
backend_port=9000
ports=$(grep -v '^;' $pool/* 2>/dev/null |grep listen |grep -o :[0-9].*)
ports=$(echo "$ports" |sed "s/://" |sort -n)
for port in $ports; do
if [ "$backend_port" -eq "$port" ]; then
backend_port=$((backend_port + 1))
fi
done
fi
if [ -e "$ubic" ]; then
ports=$(grep -v '^;' $pool/$2.conf 2>/dev/null |grep listen |grep -o :[0-9].*)
ports=$(echo "$ports" |sed "s/://" |sort -n)
backend_port=$ports
fi
# Adding backend config
cat $WEBTPL/$template.tpl |\
sed -e "s|%backend_port%|$backend_port|" \
-e "s|%user%|$1|g"\
-e "s|%domain%|$2|"\
-e "s|%docroot%|$docroot|"\
-e "s|%backend%|$2|g" > $pool/$2.conf
sed -i -e "s/%backend_lsnr_cust%/127.0.0.1:$backend_port/g" /home/$user/conf/web/apache2.conf > /dev/null
sed -i -e "s/%backend_lsnr_cust%/127.0.0.1:$backend_port/g" /home/$user/conf/web/sapache2.conf > /dev/null
service $WEB_BACKEND restart >/dev/null
## php5-dynamic.tpl
This goes on the php5-fpm folder _/usr/local/vesta/data/templates/web/php5-fpm/_
[%backend%]
listen = 127.0.0.1:%backend_port%
listen.allowed_clients = 127.0.0.1
user = %user%
group = %user%
pm = dynamic
pm.max_children = 2
pm.start_servers = 1
pm.min_spare_servers = 1
pm.max_spare_servers = 2
pm.max_requests = 500
pm.status_path = /status
request_terminate_timeout = 30s
rlimit_files = 131072
php_admin_value[open_basedir] = %docroot%:/home/%user%/tmp:/bin:/usr/bin:/usr/local/bin:/var/www/html:/tmp:/usr/share:/etc/phpMyAdmin:/etc/phpmyadmin:/var/lib/phpmyadmin:/etc/roundcubemail:/var/lib/roundcube:/var/run/nginx-cache
php_admin_value[upload_tmp_dir] = /home/%user%/tmp
php_admin_value[session.save_path] = /home/%user%/tmp
php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f info@%domain%
php_admin_value[upload_max_filesize] = 32M
php_admin_value[max_execution_time] = 30
php_admin_value[max_input_time] = 60
php_admin_value[post_max_size] = 64M
php_admin_value[memory_limit] = 256M
php_admin_flag[mysql.allow_persistent] = off
php_admin_flag[safe_mode] = off
php_admin_flag[enable_dl] = off
php_admin_value[disable_functions] = passthru,pcntl_exec,popen,openlog,allow_url_fopen
env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp
dont forget to chmod +x your php5-fpm.sh file.
i will post the complete modification in the forum, including using multi-php.
@huloza
Thank you, but an official supported integration would be better.
* BUMP *
Hello, this should be started worked on vestacp. I got many problem on my side when using mpm_prefork, I tried to change it to mpm_worker and after I see the configuration, I'm horrified, it all use php_admin_value, and I don't know how to change the config so it will persist on each vhost, because I constantly got apache crash because of prefork.. it's ram always ramping up till the server have no ram. I've 4gb ram server and it's very crasy to apache to fill it up till OOM.
The only way for now, I limit the php config and move backup at night but this's only temp solution, and most of my site that use vestacp really doesn't have high traffic, even lowest traffic possible, is there anyway to work on this matter?
@benyaminl
what distribution you are using?
Sorry I forgot to tell.
I read your thread on Forum and set a new PHP-FPM config with apache, and
disable mpm_prefork and use mpm_worker.
But I still encounter slow of loading page, with SSD disk, 2gb ram and 2cpu
core.
Anyway my other question is(because I tried to register on forum and till
now doesn't get any confirmation email), how to make it faster, and what
mod that can be safely disabled on apache that won't affect the web server?
Thanks.
Regards,
Benyamin Limanto
sent from my Sony XPERIA XZ Premium
On Tue, 11 Aug 2020, 02:10 dpeca, notifications@github.com wrote:
@benyaminl https://github.com/benyaminl
what distribution you are using?.—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/serghey-rodin/vesta/issues/1038#issuecomment-671535800,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AAVP2NDHU755HPPY4APNWQDSABA3BANCNFSM4C5BTV5A
.
@benyaminl
again, what linux distribution you are using?
Oh sorry. Seems I don't read it through ly. I'm using Ubuntu 18.04, and
using apache+nginx installer from vestacp.com
I'm horiffied because of many OOM caused by apache with prefork with
mod_php other than that, when doing daily backup, the server will hang. The
strangest thing is, the ram never free up even after restarting the
service(I never encountered this with vanilla config from Ubuntu repo on
other server) .
At least with php-fpm and mpm_event making ram/memory is more at ease, and
backup better than before.
See the attached screenshot

Regards,
Benyamin Limanto
sent from my Sony XPERIA XZ Premium
On Wed, 12 Aug 2020, 18:03 dpeca, notifications@github.com wrote:
@benyaminl https://github.com/benyaminl
again, what linux distribution you are using?—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/serghey-rodin/vesta/issues/1038#issuecomment-672804947,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AAVP2NE7JTHTG2HK6EGQT7TSAJZH7ANCNFSM4C5BTV5A
.
@benyaminl
Take a look at https://forum.vestacp.com/viewtopic.php?p=76287#p76287
In my fork I made default stack to be "Apache in mpm_event + PHP-FPM", but fork is Debian-only (i will not put link to my fork because I don't want to looks like as advertisment)
Yes, ruid cause problem, I remove it 2 days ago. Oh we can safely remove suexec, interesting, let me try. Hmm.. how about rpaf? Do we need it ?
Regrads,
Benyamin Limanto
Sent from Outlook 2019 using ASUS A43SV
From: dpeca notifications@github.com
Sent: Rabu, 12 Agustus 2020 23:11
To: serghey-rodin/vesta vesta@noreply.github.com
Cc: Benyamin Limanto BLBENYAMIN9@GMAIL.COM; Mention mention@noreply.github.com
Subject: Re: [serghey-rodin/vesta] Add Apache2 PHP-FPM Support (#1038)
@benyaminl https://github.com/benyaminl
Take a look at https://forum.vestacp.com/viewtopic.php?p=76287#p76287
In my fork I made default Apache in mpm_event + PHP-FPM, but fork is Debian-only (i will not put link to my fork because I don't want to looks like as advertisment)
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub https://github.com/serghey-rodin/vesta/issues/1038#issuecomment-672969229 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AAVP2NC2HPYS4LSAD2F2MW3SAK5KJANCNFSM4C5BTV5A . https://github.com/notifications/beacon/AAVP2NCLUP3TKGG3O7NFNXDSAK5KJA5CNFSM4C5BTV5KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOFAOLEDI.gif
In my fork I made default stack to be "Apache in mpm_event + PHP-FPM", but fork is Debian-only (i will not put link to my fork because I don't want to looks like as advertisment)
Let me do it for you. @dpeca is speaking about www.myvestacp.com, there is aswell another fork with an active development and community when you search for additional feautures and a more OS support: www.hestiacp.com
It should not be advertisement, but it is a clear fact, that Vesta has still unpatched exploits in the current version and basicly is dead - all discussed here: https://github.com/serghey-rodin/vesta/issues/2006
@benyaminl
Yes, ruid cause problem, I remove it 2 days ago. Oh we can safely remove suexec, interesting, let me try. Hmm.. how about rpaf? Do we need it
Huh, I don't know.
Long time ago we switched RPAF to mod_remoteip, but I know it is done for sure on Debian, for other Linux distributions I'm not sure, because I'm using only Debian.
Yes I know about it. Thanks for mention it again. Just hoping Serghey can
Be back and start being active some more haha.
Regards,
Benyamin Limanto
sent from my ASUS Fonepad 8
Pada tanggal Kam, 13 Agt 2020 12.00, Raphael Schneeberger <
[email protected]> menulis:
Most helpful comment
temporary working solution using vesta templates on Debian installation:
Notes
- test first, dont try directly on production, this can break your server
- Works perfect with the exception that you must manually delete the pools after delete the websites, the pools are located in /etc/php5/fpm/pool.d/
- after you deleted the pool restart php5-fpm to free ram.
- if you modify your .sh template files you need to chmod +x them.
Apache
PHP
Vesta Templates
## php5-fpm.tpl
_Note i added the %backend_lsnr_cust% var, i will replace that with the .sh file_
/usr/local/vesta/data/templates/web/apache2/
## php5-fpm.stpl
_Note i added the %backend_lsnr_cust% var, i will replace that with the .sh file_
/usr/local/vesta/data/templates/web/apache2/
## php5-fpm.sh
/usr/local/vesta/data/templates/web/apache2/
## php5-dynamic.tpl
This goes on the php5-fpm folder _/usr/local/vesta/data/templates/web/php5-fpm/_
dont forget to chmod +x your php5-fpm.sh file.
i will post the complete modification in the forum, including using multi-php.