Page 1 of 17

TUTORIAL: PHP selector for PHP 5.6, 7.0, 7.1, 7.2, 7.3, 7.4 for Debian & Ubuntu (and optionally directly nginx-PHP-FPM)

Posted: Fri Jun 15, 2018 11:28 am
by dpeca
This tutorial will enable PHP 5.6, 7.0, 7.1, 7.2, 7.3 and 7.4 to specific/desired domains.
Tutorial is for Debian and Ubuntu (but probably can give you a good direction for CentOS).

PHP will run through PHP-FPM, which is much more faster solution than other existent PHP-switcher that uses only old phpfcgid solution (because with PHP-FPM you can use opcache).
Communication to PHP-FPM will goes through Unix-sockets, which is also the fastest communication between daemons.

Second tutorial goes a step forward - it will allow you to make direct communication from nginx to PHP-FPM, avoiding Apache for desired domains (Apache is installed by default in default Vesta installation).
So, yes, you can easily make nginx <-> PHP-FPM stack even if you have Apache installed.
And yet better news - you can use it only on desired domains - so all other domains will stay untouched.


First pre-required step for Debian 10:

Code: Select all

apt-get update
apt install apt-transport-https ca-certificates
wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
sh -c 'echo "deb https://packages.sury.org/php/ buster main" > /etc/apt/sources.list.d/php.list'
First pre-required step for Debian 9:

Code: Select all

apt-get update
apt install apt-transport-https ca-certificates
wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
sh -c 'echo "deb https://packages.sury.org/php/ stretch main" > /etc/apt/sources.list.d/php.list'
First pre-required step for Debian 8:

Code: Select all

apt-get update
apt install apt-transport-https ca-certificates
wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
sh -c 'echo "deb https://packages.sury.org/php/ jessie main" > /etc/apt/sources.list.d/php.list'
First pre-required step for Ubuntu:

Code: Select all

apt-get update
apt install apt-transport-https ca-certificates
wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
Then in your browser go to https://launchpad.net/~ondrej/+archive/ubuntu/php/
Under Adding this PPA to your system click Technical details about this PPA, select your Ubuntu version, and two lines that you get from field box below add to /etc/apt/sources.list.d/php.list


Second pre-required step for both Debian and Ubuntu:

Code: Select all

apt-get update
a2enmod proxy_fcgi setenvif


For PHP 5.6

Code: Select all

apt-get install php5.6-apcu php5.6-mbstring php5.6-bcmath php5.6-cli php5.6-curl php5.6-fpm php5.6-gd php5.6-intl php5.6-mcrypt php5.6-mysql php5.6-soap php5.6-xml php5.6-zip php5.6-memcache php5.6-memcached php5.6-zip
update-rc.d php5.6-fpm defaults
a2enconf php5.6-fpm
systemctl restart apache2
cp -r /etc/php/5.6/ /root/vst_install_backups/php5.6/
rm -f /etc/php/5.6/fpm/pool.d/*
wget http://dl.mycity.tech/vesta/php-fpm-tpl/PHP-FPM-56.stpl -O /usr/local/vesta/data/templates/web/apache2/PHP-FPM-56.stpl
wget http://dl.mycity.tech/vesta/php-fpm-tpl/PHP-FPM-56.tpl -O /usr/local/vesta/data/templates/web/apache2/PHP-FPM-56.tpl
wget http://dl.mycity.tech/vesta/php-fpm-tpl/PHP-FPM-56.sh -O /usr/local/vesta/data/templates/web/apache2/PHP-FPM-56.sh
chmod a+x /usr/local/vesta/data/templates/web/apache2/PHP-FPM-56.sh


For PHP 7.0

Code: Select all

apt-get install php7.0-apcu php7.0-mbstring php7.0-bcmath php7.0-cli php7.0-curl php7.0-fpm php7.0-gd php7.0-intl php7.0-mcrypt php7.0-mysql php7.0-soap php7.0-xml php7.0-zip php7.0-memcache php7.0-memcached php7.0-zip
update-rc.d php7.0-fpm defaults
a2enconf php7.0-fpm
systemctl restart apache2
cp -r /etc/php/7.0/ /root/vst_install_backups/php7.0/
rm -f /etc/php/7.0/fpm/pool.d/*
wget http://dl.mycity.tech/vesta/php-fpm-tpl/PHP-FPM-70.stpl -O /usr/local/vesta/data/templates/web/apache2/PHP-FPM-70.stpl
wget http://dl.mycity.tech/vesta/php-fpm-tpl/PHP-FPM-70.tpl -O /usr/local/vesta/data/templates/web/apache2/PHP-FPM-70.tpl
wget http://dl.mycity.tech/vesta/php-fpm-tpl/PHP-FPM-70.sh -O /usr/local/vesta/data/templates/web/apache2/PHP-FPM-70.sh
chmod a+x /usr/local/vesta/data/templates/web/apache2/PHP-FPM-70.sh


For PHP 7.1

Code: Select all

apt-get install php7.1-apcu php7.1-mbstring php7.1-bcmath php7.1-cli php7.1-curl php7.1-fpm php7.1-gd php7.1-intl php7.1-mcrypt php7.1-mysql php7.1-soap php7.1-xml php7.1-zip php7.1-memcache php7.1-memcached php7.1-zip
update-rc.d php7.1-fpm defaults
a2enconf php7.1-fpm
systemctl restart apache2
cp -r /etc/php/7.1/ /root/vst_install_backups/php7.1/
rm -f /etc/php/7.1/fpm/pool.d/*
wget http://dl.mycity.tech/vesta/php-fpm-tpl/PHP-FPM-71.stpl -O /usr/local/vesta/data/templates/web/apache2/PHP-FPM-71.stpl
wget http://dl.mycity.tech/vesta/php-fpm-tpl/PHP-FPM-71.tpl -O /usr/local/vesta/data/templates/web/apache2/PHP-FPM-71.tpl
wget http://dl.mycity.tech/vesta/php-fpm-tpl/PHP-FPM-71.sh -O /usr/local/vesta/data/templates/web/apache2/PHP-FPM-71.sh
chmod a+x /usr/local/vesta/data/templates/web/apache2/PHP-FPM-71.sh


For PHP 7.2

Code: Select all

apt-get install php7.2-apcu php7.2-mbstring php7.2-bcmath php7.2-cli php7.2-curl php7.2-fpm php7.2-gd php7.2-intl php7.2-mysql php7.2-soap php7.2-xml php7.2-zip php7.2-memcache php7.2-memcached php7.2-zip
update-rc.d php7.2-fpm defaults
a2enconf php7.2-fpm
systemctl restart apache2
cp -r /etc/php/7.2/ /root/vst_install_backups/php7.2/
rm -f /etc/php/7.2/fpm/pool.d/*
wget http://dl.mycity.tech/vesta/php-fpm-tpl/PHP-FPM-72.stpl -O /usr/local/vesta/data/templates/web/apache2/PHP-FPM-72.stpl
wget http://dl.mycity.tech/vesta/php-fpm-tpl/PHP-FPM-72.tpl -O /usr/local/vesta/data/templates/web/apache2/PHP-FPM-72.tpl
wget http://dl.mycity.tech/vesta/php-fpm-tpl/PHP-FPM-72.sh -O /usr/local/vesta/data/templates/web/apache2/PHP-FPM-72.sh
chmod a+x /usr/local/vesta/data/templates/web/apache2/PHP-FPM-72.sh


For PHP 7.3

Code: Select all

apt-get install php7.3-apcu php7.3-mbstring php7.3-bcmath php7.3-cli php7.3-curl php7.3-fpm php7.3-gd php7.3-intl php7.3-mysql php7.3-soap php7.3-xml php7.3-zip php7.3-memcache php7.3-memcached php7.3-zip
update-rc.d php7.3-fpm defaults
a2enconf php7.3-fpm
systemctl restart apache2
cp -r /etc/php/7.3/ /root/vst_install_backups/php7.3/
rm -f /etc/php/7.3/fpm/pool.d/*
wget http://dl.mycity.tech/vesta/php-fpm-tpl/PHP-FPM-73.stpl -O /usr/local/vesta/data/templates/web/apache2/PHP-FPM-73.stpl
wget http://dl.mycity.tech/vesta/php-fpm-tpl/PHP-FPM-73.tpl -O /usr/local/vesta/data/templates/web/apache2/PHP-FPM-73.tpl
wget http://dl.mycity.tech/vesta/php-fpm-tpl/PHP-FPM-73.sh -O /usr/local/vesta/data/templates/web/apache2/PHP-FPM-73.sh
chmod a+x /usr/local/vesta/data/templates/web/apache2/PHP-FPM-73.sh


For PHP 7.4

Code: Select all

apt-get install php7.4-apcu php7.4-mbstring php7.4-bcmath php7.4-cli php7.4-curl php7.4-fpm php7.4-gd php7.4-intl php7.4-mysql php7.4-soap php7.4-xml php7.4-zip php7.4-memcache php7.4-memcached php7.4-zip
update-rc.d php7.4-fpm defaults
a2enconf php7.4-fpm
systemctl restart apache2
cp -r /etc/php/7.4/ /root/vst_install_backups/php7.4/
rm -f /etc/php/7.4/fpm/pool.d/*
wget http://dl.mycity.tech/vesta/php-fpm-tpl/PHP-FPM-74.stpl -O /usr/local/vesta/data/templates/web/apache2/PHP-FPM-74.stpl
wget http://dl.mycity.tech/vesta/php-fpm-tpl/PHP-FPM-74.tpl -O /usr/local/vesta/data/templates/web/apache2/PHP-FPM-74.tpl
wget http://dl.mycity.tech/vesta/php-fpm-tpl/PHP-FPM-74.sh -O /usr/local/vesta/data/templates/web/apache2/PHP-FPM-74.sh
chmod a+x /usr/local/vesta/data/templates/web/apache2/PHP-FPM-74.sh


Now simply go to Vesta, edit WEB for desired domain and choose:
Image

Step forward: Enable direct communication between nginx and php-fpm (if you want to avoid Apache for specific domain)

Posted: Fri Jun 15, 2018 11:31 am
by dpeca
Step forward: Enable direct communication between nginx and php-fpm (if you want to avoid Apache for specific domain)

As I said in first post, second tutorial goes a step forward - it will allow you to make direct communication from nginx to PHP-FPM, avoiding Apache for desired domains (Apache is installed by default in default Vesta installation).
So, yes, you can easily make nginx <-> PHP-FPM stack even if you have Apache installed.
And yet better news - you can use it only on desired domains - so all other domains will stay untouched.


For custom PHP CMS:

Code: Select all

wget https://raw.githubusercontent.com/serghey-rodin/vesta/master/install/debian/9/templates/web/nginx/php-fpm/default.tpl -O /usr/local/vesta/data/templates/web/nginx/PHP-FPM-72.tpl
wget https://raw.githubusercontent.com/serghey-rodin/vesta/master/install/debian/9/templates/web/nginx/php-fpm/default.stpl -O /usr/local/vesta/data/templates/web/nginx/PHP-FPM-72.stpl
wget http://dl.mycity.tech/vesta/php-fpm-tpl/PHP-FPM-72.sh -O /usr/local/vesta/data/templates/web/nginx/PHP-FPM-72.sh
chmod a+x /usr/local/vesta/data/templates/web/nginx/PHP-FPM-72.sh
sed -i "s#%web_port%#%proxy_port%#g" /usr/local/vesta/data/templates/web/nginx/PHP-FPM-72.tpl
sed -i "s#%web_ssl_port%#%proxy_ssl_port%#g" /usr/local/vesta/data/templates/web/nginx/PHP-FPM-72.stpl
sed -i "s#%backend_lsnr%#unix:/run/php/php7.2-fpm-%domain%.sock#g" /usr/local/vesta/data/templates/web/nginx/PHP-FPM-72.tpl
sed -i "s#%backend_lsnr%#unix:/run/php/php7.2-fpm-%domain%.sock#g" /usr/local/vesta/data/templates/web/nginx/PHP-FPM-72.stpl
sed -i "s#/var/log/nginx/#/var/log/%web_system%/#g" /usr/local/vesta/data/templates/web/nginx/PHP-FPM-72.tpl
sed -i "s#/var/log/nginx/#/var/log/%web_system%/#g" /usr/local/vesta/data/templates/web/nginx/PHP-FPM-72.stpl

For WordPress:

Code: Select all

wget https://raw.githubusercontent.com/serghey-rodin/vesta/master/install/debian/9/templates/web/nginx/php-fpm/wordpress2.tpl -O /usr/local/vesta/data/templates/web/nginx/PHP-FPM-72-Wordpress.tpl
wget https://raw.githubusercontent.com/serghey-rodin/vesta/master/install/debian/9/templates/web/nginx/php-fpm/wordpress2.stpl -O /usr/local/vesta/data/templates/web/nginx/PHP-FPM-72-Wordpress.stpl
wget http://dl.mycity.tech/vesta/php-fpm-tpl/PHP-FPM-72.sh -O /usr/local/vesta/data/templates/web/nginx/PHP-FPM-72-Wordpress.sh
chmod a+x /usr/local/vesta/data/templates/web/nginx/PHP-FPM-72-Wordpress.sh
sed -i "s#%web_port%#%proxy_port%#g" /usr/local/vesta/data/templates/web/nginx/PHP-FPM-72-Wordpress.tpl
sed -i "s#%web_ssl_port%#%proxy_ssl_port%#g" /usr/local/vesta/data/templates/web/nginx/PHP-FPM-72-Wordpress.stpl
sed -i "s#%backend_lsnr%#unix:/run/php/php7.2-fpm-%domain%.sock#g" /usr/local/vesta/data/templates/web/nginx/PHP-FPM-72-Wordpress.tpl
sed -i "s#%backend_lsnr%#unix:/run/php/php7.2-fpm-%domain%.sock#g" /usr/local/vesta/data/templates/web/nginx/PHP-FPM-72-Wordpress.stpl
sed -i "s#/var/log/nginx/#/var/log/%web_system%/#g" /usr/local/vesta/data/templates/web/nginx/PHP-FPM-72-Wordpress.tpl
sed -i "s#/var/log/nginx/#/var/log/%web_system%/#g" /usr/local/vesta/data/templates/web/nginx/PHP-FPM-72-Wordpress.stpl
This way you can adapt any other existent Vesta PHP-FPM template for other CMS.
(list of CMS templates is here - https://github.com/serghey-rodin/vesta/ ... nx/php-fpm )

This is example for PHP 7.2.
You can install templates for other PHP version the same way, just substitute 7.2 and 72 with desired version.

Now simply go to Vesta, edit WEB for desired domain and choose:
Image

Re: TUTORIAL: PHP selector for PHP 5.6, 7.0, 7.1 and 7.2 on Debian9 (and optionally make direct nginx <-> PHP-FPM stack)

Posted: Tue Jun 26, 2018 2:49 pm
by blueberry
Good share. Thanks.

For the benefit of others using this method, just take note that to edit some of the php.ini features, eg. upload_max_filesize, you got to edit the template files. Editing the php.ini files will not effect the change.

sudo nano /usr/local/vesta/data/templates/web/apache2/PHP-FPM-71.sh

Re: TUTORIAL: PHP selector for PHP 5.6, 7.0, 7.1 and 7.2 on Debian9 (and optionally make direct nginx <-> PHP-FPM stack)

Posted: Tue Jun 26, 2018 4:32 pm
by sacredwebsite
I am really liking this, and it is more up to date than any other solution I have found in the forums or repo.

I am having a problem with the Apache templates.
It may be that I did not install on Debian 9, but rather 8, and then I performed the update to 9 on this particular test server.

However, the nginx direct fpm templates do work for me.

When selecting the apache fpm web templates in my test environment, php files are not executed, simply the content of the file is shown in the browser.
I am looking over the template code to determine what could be causing this.

If you have any advice on what to check that would be much appreciated.
I believe this should be a standard feature in Vesta as many web apps can benefit from a multiphp selector, so I appreciate you posting this thread.

Re: TUTORIAL: PHP selector for PHP 5.6, 7.0, 7.1 and 7.2 on Debian9 (and optionally make direct nginx <-> PHP-FPM stack)

Posted: Wed Jun 27, 2018 5:58 am
by blueberry
One thing i noticed, when changing some php settings, for eg, increasing execution_time, the changes does not effect at all even after reboot.

Changes will only effect if u goto Web -> Edit Domain -> Web Template -> Select another package, save, and go back to PHP-FPM-XX.

Re: TUTORIAL: PHP selector for PHP 5.6, 7.0, 7.1 and 7.2 on Debian9 (and optionally make direct nginx <-> PHP-FPM stack)

Posted: Thu Jun 28, 2018 7:09 pm
by dpeca
blueberry wrote:
Tue Jun 26, 2018 2:49 pm
Good share. Thanks.

For the benefit of others using this method, just take note that to edit some of the php.ini features, eg. upload_max_filesize, you got to edit the template files. Editing the php.ini files will not effect the change.

sudo nano /usr/local/vesta/data/templates/web/apache2/PHP-FPM-71.sh
The same is with default PHP, you just need to edit /usr/local/vesta/data/templates/web/apache2/default.tpl :)

BTW, template from this tutorial will never overwrite fpm pool file, so you also need to edit pool file (/etc/php/7.X/fpm/pool.d/YOUR-DOMAIN.conf) and then restart choosen php-fpm:

Code: Select all

service php7.X-fpm restart

Re: TUTORIAL: PHP selector for PHP 5.6, 7.0, 7.1 and 7.2 on Debian9 (and optionally make direct nginx <-> PHP-FPM stack)

Posted: Thu Jun 28, 2018 7:17 pm
by dpeca
sacredwebsite wrote:
Tue Jun 26, 2018 4:32 pm
When selecting the apache fpm web templates in my test environment, php files are not executed, simply the content of the file is shown in the browser.
I am looking over the template code to determine what could be causing this.

If you have any advice on what to check that would be much appreciated.
I believe this should be a standard feature in Vesta as many web apps can benefit from a multiphp selector, so I appreciate you posting this thread.
Did you run:

Code: Select all

a2enconf php7.X-fpm
systemctl restart apache2
?

Re: TUTORIAL: PHP selector for PHP 5.6, 7.0, 7.1 and 7.2 on Debian9 (and optionally make direct nginx <-> PHP-FPM stack)

Posted: Sat Jun 30, 2018 2:59 am
by sacredwebsite
dpeca wrote:
Thu Jun 28, 2018 7:17 pm
Did you run:

Code: Select all

a2enconf php7.X-fpm
systemctl restart apache2
?
Yes, they are already enabled and I have restarted apache, do you think upgrading from 8 to 9 makes a difference in how your script installs on an upgraded system versus one where Vesta was installed on Debian 9 rather than upgraded?

Re: TUTORIAL: PHP selector for PHP 5.6, 7.0, 7.1 and 7.2 on Debian9 (and optionally make direct nginx <-> PHP-FPM stack)

Posted: Sat Jun 30, 2018 5:51 pm
by dpeca
sacredwebsite wrote:
Sat Jun 30, 2018 2:59 am
Yes, they are already enabled and I have restarted apache, do you think upgrading from 8 to 9 makes a difference in how your script installs on an upgraded system versus one where Vesta was installed on Debian 9 rather than upgraded?
what is a content of /etc/apt/sources.list.d/php.list ?
if you find 'strech' in it, replace it to 'jessie' and run again: apt-get update && apt-get upgrade

Re: TUTORIAL: PHP selector for PHP 5.6, 7.0, 7.1 and 7.2 on Debian9 (and optionally make direct nginx <-> PHP-FPM stack)

Posted: Sat Jul 07, 2018 3:05 pm
by sacredwebsite
dpeca wrote:
Sat Jun 30, 2018 5:51 pm
sacredwebsite wrote:
Sat Jun 30, 2018 2:59 am
Yes, they are already enabled and I have restarted apache, do you think upgrading from 8 to 9 makes a difference in how your script installs on an upgraded system versus one where Vesta was installed on Debian 9 rather than upgraded?
what is a content of /etc/apt/sources.list.d/php.list ?
if you find 'strech' in it, replace it to 'jessie' and run again: apt-get update && apt-get upgrade
Dpeca, thank you for your support.
I launched a test server with Debian 9 as the base OS and installed Vesta on it and installed the scripts, I am getting the same issue still.
Any suggestions on where to look to help troubleshoot?

Also Are you installing your script on a bare Debian 9 Vesta install?
I am on 9.4 on this test server, I am just trying to determine what is the factor, also this is Debian 9 running in a LXC container atop a Debian 9 baremetal virtualizer.

Thank you for your time, I feel this is a very important feature that should be an official template in Vesta.