Разные версии PHP в VestaCP и Debian 8

В текущих версиях панели VestaCP нет выбора версий PHP как в CPanel, ISPmanager 5 и т.п., поэтому попробуем сделать это сами.

Устанавливать будем на Debian 8 + VestaCP

Из репозитория автоматом установится PHP 5.6, поэтому наша задача установить дополнительно:

Все действия производятся под root’ом.

Для начала установим необходимые пакеты:

apt-get build-dep -y php5
apt-get install libonig-dev libmcrypt-dev libreadline-dev

Также нам нужен пакет libt1-dev, который отсутствует в репах debian 8, возьмем его из репов debian 7 wheezy, для этого добавим в /etc/apt/sources.list следующую строку

deb http://ftp.debian.org/debian wheezy main contrib non-free

Затем выполняем:

apt-get update
apt-get install libt1-dev

Затем убираем добавленную строку из /etc/apt/sources.list и затем выполняем:

apt-get update

Создаем каталог для исходников:

mkdir /php/
mkdir /php/src

Сделаем симлинк для freetype

mkdir /usr/include/freetype2/freetype
ln -s /usr/include/freetype2/freetype.h /usr/include/freetype2/freetype/freetype.h

сделаем симлинк gmp.h в /usr/include/

ln -s /usr/include/x86_64-linux-gnu/gmp.h /usr/include/gmp.h

на этом подготовка к установке разных версий PHP завершена

Установка PHP 5.3

cd /php/src/
wget -O php-5.3.29.tar.bz2 http://php.net/get/php-5.3.29.tar.bz2/from/this/mirror
tar -xjf php-5.3.29.tar.bz2
cd php-5.3.29
mkdir /php/php53

Выполняется одной командой:

./configure --prefix=/php/php53 \
--with-config-file-path=/php/php53/etc \
--with-config-file-scan-dir=/php/php53/etc/conf \
--with-regex=php \
--disable-rpath \
--disable-static \
--with-pic \
--with-layout=GNU \
--enable-calendar \
--enable-sysvsem \
--enable-sysvshm \
--enable-sysvmsg \
--enable-bcmath \
--with-bz2 \
--enable-ctype \
--with-cdb \
--with-iconv \
--enable-exif \
--enable-ftp \
--with-gettext \
--enable-mbstring \
--with-onig=/usr \
--with-pcre-regex=/usr \
--enable-shmop \
--enable-sockets \
--enable-wddx \
--with-libxml-dir=/usr \
--with-zlib \
--with-kerberos=/usr \
--with-openssl=/usr \
--enable-soap \
--enable-zip \
--with-mhash=yes \
--with-mysql-sock=/var/run/mysqld/mysqld.sock \
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--enable-pdo \
--with-pdo-mysql=mysqlnd \
--enable-exif \
--with-jpeg-dir=/usr \
--with-png-dir=/usr \
--with-freetype-dir=/usr \
--with-t1lib \
--with-zlib-dir=/usr \
--with-mcrypt=/usr \
--with-mhash \
--with-xsl=/usr \
--enable-zip \
--enable-cgi \
--with-curl \
--with-gd \
--enable-pcntl \
--enable-mbregex \
--enable-gd-native-ttf \
--with-libdir=lib64 \
--enable-dba=shared \
--with-readline=/usr \
--enable-simplexml \
--with-libdir=/lib/x86_64-linux-gnu \
--with-pspell
make
make install

Скопируем шаблон существующий шаблон phpfcgid

cp /usr/local/vesta/data/templates/web/apache2/phpfcgid.sh /usr/local/vesta/data/templates/web/apache2/php53.sh
cp /usr/local/vesta/data/templates/web/apache2/phpfcgid.stpl /usr/local/vesta/data/templates/web/apache2/php53.stpl
cp /usr/local/vesta/data/templates/web/apache2/phpfcgid.tpl /usr/local/vesta/data/templates/web/apache2/php53.tpl

Открываем файл /usr/local/vesta/data/templates/web/apache2/php53.sh и находим там строку

exec  /usr/bin/php-cgi

заменяем на

exec  /php/php53/bin/php-cgi

 

Установка PHP 5.4

cd /php/src/
wget -O php-5.4.45.tar.bz2 http://php.net/get/php-5.4.45.tar.bz2/from/this/mirror
tar -xjf php-5.4.45.tar.bz2
cd php-5.4.45
mkdir /php/php54

Выполняется одной командой:

./configure --prefix=/php/php54 \
--with-config-file-path=/php/php54/etc \
--with-config-file-scan-dir=/php/php54/etc/conf \
--with-regex=php \
--disable-rpath \
--disable-static \
--with-pic \
--with-layout=GNU \
--enable-calendar \
--enable-sysvsem \
--enable-sysvshm \
--enable-sysvmsg \
--enable-bcmath \
--with-bz2 \
--enable-ctype \
--with-cdb \
--with-iconv \
--enable-exif \
--enable-ftp \
--with-gettext \
--enable-mbstring \
--with-onig=/usr \
--with-pcre-regex=/usr \
--enable-shmop \
--enable-sockets \
--enable-wddx \
--with-libxml-dir=/usr \
--with-zlib \
--with-kerberos=/usr \
--with-openssl=/usr \
--enable-soap \
--enable-zip \
--with-mhash=yes \
--with-mysql-sock=/var/run/mysqld/mysqld.sock \
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--enable-pdo \
--with-pdo-mysql=mysqlnd \
--enable-exif \
--with-jpeg-dir=/usr \
--with-png-dir=/usr \
--with-freetype-dir=/usr \
--with-t1lib \
--with-zlib-dir=/usr \
--with-mcrypt=/usr \
--with-mhash \
--with-xsl=/usr \
--enable-zip \
--enable-cgi \
--with-curl \
--with-gd \
--enable-pcntl \
--enable-mbregex \
--enable-gd-native-ttf \
--with-libdir=lib64 \
--enable-dba=shared \
--enable-intl \
--with-readline=/usr \
--enable-simplexml \
--with-libdir=/lib/x86_64-linux-gnu \
--with-pspell
make
make install

Скопируем шаблон существующий шаблон phpfcgid

cp /usr/local/vesta/data/templates/web/apache2/phpfcgid.sh /usr/local/vesta/data/templates/web/apache2/php54.sh
cp /usr/local/vesta/data/templates/web/apache2/phpfcgid.stpl /usr/local/vesta/data/templates/web/apache2/php54.stpl
cp /usr/local/vesta/data/templates/web/apache2/phpfcgid.tpl /usr/local/vesta/data/templates/web/apache2/php54.tpl

Открываем файл /usr/local/vesta/data/templates/web/apache2/php54.sh и находим там строку

exec  /usr/bin/php-cgi

заменяем на

exec  /php/php54/bin/php-cgi

 

Установка PHP 5.5

cd /php/src/
wget -O php-5.5.37.tar.bz2 http://php.net/get/php-5.5.37.tar.bz2/from/this/mirror
tar -xjf php-5.5.37.tar.bz2
cd php-5.5.37
mkdir /php/php55

Выполняется одной командой:

./configure --prefix=/php/php55 \
--with-config-file-path=/php/php55/etc \
--with-config-file-scan-dir=/php/php55/etc/conf \
--with-regex=php \
--disable-rpath \
--disable-static \
--with-pic \
--with-layout=GNU \
--enable-calendar \
--enable-sysvsem \
--enable-sysvshm \
--enable-sysvmsg \
--enable-bcmath \
--with-bz2 \
--enable-ctype \
--with-cdb \
--with-iconv \
--enable-exif \
--enable-ftp \
--with-gettext \
--enable-mbstring \
--with-onig=/usr \
--with-pcre-regex=/usr \
--enable-shmop \
--enable-sockets \
--enable-wddx \
--with-libxml-dir=/usr \
--with-zlib \
--with-kerberos=/usr \
--with-openssl=/usr \
--enable-soap \
--enable-zip \
--with-mhash=yes \
--with-mysql-sock=/var/run/mysqld/mysqld.sock \
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--enable-pdo \
--with-pdo-mysql=mysqlnd \
--enable-exif \
--with-jpeg-dir=/usr \
--with-png-dir=/usr \
--with-freetype-dir=/usr \
--with-t1lib \
--with-zlib-dir=/usr \
--with-mcrypt=/usr \
--with-mhash \
--with-xsl=/usr \
--enable-zip \
--enable-cgi \
--with-curl \
--with-gd \
--enable-pcntl \
--enable-mbregex \
--enable-gd-native-ttf \
--with-libdir=lib64 \
--enable-dba=shared \
--enable-intl \
--with-readline=/usr \
--enable-simplexml \
--with-libdir=/lib/x86_64-linux-gnu \
--with-pspell
make
make install

Скопируем шаблон существующий шаблон phpfcgid

cp /usr/local/vesta/data/templates/web/apache2/phpcgi.sh /usr/local/vesta/data/templates/web/apache2/php55.sh
cp /usr/local/vesta/data/templates/web/apache2/phpcgi.stpl /usr/local/vesta/data/templates/web/apache2/php55.stpl
cp /usr/local/vesta/data/templates/web/apache2/phpcgi.tpl /usr/local/vesta/data/templates/web/apache2/php55.tpl

Открываем файл /usr/local/vesta/data/templates/web/apache2/php55.sh и находим там строку

exec  /usr/bin/php-cgi

заменяем на

exec  /php/php55/bin/php-cgi

 

Установка PHP 7.0

cd /php/src/
wget http://php.net/get/php-7.0.25.tar.bz2/from/this/mirror -O php-7.0.25.tar.bz2
tar -xvjf php-7.0.25.tar.bz2
cd php-7.0.25

Выполняется одной командой:

./configure --prefix=/php/php70 \
--with-config-file-path=/php/php70/etc \
--with-config-file-scan-dir=/php/php70/etc/conf \
--disable-rpath \
--disable-static \
--with-pic \
--with-layout=GNU \
--enable-calendar \
--enable-sysvsem \
--enable-sysvshm \
--enable-sysvmsg \
--enable-bcmath \
--with-bz2 \
--enable-ctype \
--with-cdb \
--with-iconv \
--enable-exif \
--enable-ftp \
--with-gettext \
--enable-mbstring \
--with-onig=/usr \
--with-pcre-regex=/usr \
--enable-shmop \
--enable-sockets \
--enable-wddx \
--with-libxml-dir=/usr \
--with-zlib \
--with-kerberos=/usr \
--with-openssl=/usr \
--enable-soap \
--enable-zip \
--with-mhash=yes \
--with-mysql-sock=/var/run/mysqld/mysqld.sock \
--with-mysqli=mysqlnd \
--enable-pdo \
--with-pdo-mysql=mysqlnd \
--enable-exif \
--with-jpeg-dir=/usr \
--with-png-dir=/usr \
--with-freetype-dir=/usr \
--with-zlib-dir=/usr \
--with-mcrypt=/usr \
--with-mhash \
--with-xsl=/usr \
--enable-zip \
--enable-cgi \
--with-curl \
--with-gd \
--enable-pcntl \
--enable-mbregex \
--enable-gd-native-ttf \
--with-libdir=lib64 \
--enable-dba=shared \
--enable-intl \
--with-readline=/usr \
--enable-simplexml \
--with-libdir=/lib/x86_64-linux-gnu \
--with-pspell
make
make install

Скопируем шаблон существующий шаблон phpfcgid

cp /usr/local/vesta/data/templates/web/apache2/phpfcgid.sh /usr/local/vesta/data/templates/web/apache2/php70.sh
cp /usr/local/vesta/data/templates/web/apache2/phpfcgid.stpl /usr/local/vesta/data/templates/web/apache2/php70.stpl
cp /usr/local/vesta/data/templates/web/apache2/phpfcgid.tpl /usr/local/vesta/data/templates/web/apache2/php70.tpl

Открываем файл /usr/local/vesta/data/templates/web/apache2/php70.sh и находим там строку

exec  /usr/bin/php-cgi

заменяем на

exec  /php/php70/bin/php-cgi

Для подключения Zend OPcache создадим файл /php/php70/etc/conf/opcache.ini с содержимым:

# Zend OPcache
zend_extension=opcache.so

 

Установка PHP 7.1

cd /php/src/
wget http://php.net/get/php-7.1.18.tar.bz2/from/this/mirror -O php-7.1.18.tar.bz2
tar -xvjf php-7.1.18.tar.bz2
cd php-7.1.18

Выполняется одной командой:

./configure --prefix=/php/php71 \
--with-config-file-path=/php/php71/etc \
--with-config-file-scan-dir=/php/php71/etc/conf \
--disable-rpath \
--disable-static \
--with-pic \
--with-layout=GNU \
--enable-calendar \
--enable-sysvsem \
--enable-sysvshm \
--enable-sysvmsg \
--enable-bcmath \
--with-bz2 \
--enable-ctype \
--with-cdb \
--with-iconv \
--enable-exif \
--enable-ftp \
--with-gettext \
--enable-mbstring \
--with-onig=/usr \
--with-pcre-regex=/usr \
--enable-shmop \
--enable-sockets \
--enable-wddx \
--with-libxml-dir=/usr \
--with-zlib \
--with-kerberos=/usr \
--with-openssl=/usr \
--enable-soap \
--enable-zip \
--with-mhash=yes \
--with-mysql-sock=/var/run/mysqld/mysqld.sock \
--with-mysqli=mysqlnd \
--enable-pdo \
--with-pdo-mysql=mysqlnd \
--enable-exif \
--with-jpeg-dir=/usr \
--with-png-dir=/usr \
--with-freetype-dir=/usr \
--with-zlib-dir=/usr \
--with-mcrypt=/usr \
--with-mhash \
--with-xsl=/usr \
--enable-zip \
--enable-cgi \
--with-curl \
--with-gd \
--enable-pcntl \
--enable-mbregex \
--enable-gd-native-ttf \
--with-libdir=lib64 \
--enable-dba=shared \
--enable-intl \
--with-readline=/usr \
--enable-simplexml \
--with-libdir=/lib/x86_64-linux-gnu \
--with-pspell \
--with-gmp
make
make install

Скопируем шаблон существующий шаблон phpfcgid

cp /usr/local/vesta/data/templates/web/apache2/phpfcgid.sh /usr/local/vesta/data/templates/web/apache2/php71.sh
cp /usr/local/vesta/data/templates/web/apache2/phpfcgid.stpl /usr/local/vesta/data/templates/web/apache2/php71.stpl
cp /usr/local/vesta/data/templates/web/apache2/phpfcgid.tpl /usr/local/vesta/data/templates/web/apache2/php71.tpl

Открываем файл /usr/local/vesta/data/templates/web/apache2/php71.sh и находим там строку

exec  /usr/bin/php-cgi

заменяем на

exec  /php/php71/bin/php-cgi

Для подключения Zend OPcache создадим файл /php/php71/etc/conf/opcache.ini с содержимым:

# Zend OPcache
zend_extension=opcache.so

 

Установка PHP 7.2

cd /php/src/
wget http://php.net/get/php-7.2.18.tar.bz2/from/this/mirror -O php-7.2.18.tar.bz2
tar -xvjf php-7.2.18.tar.bz2
cd php-7.2.18

Выполняется одной командой:

./configure --prefix=/php/php72 \
--with-config-file-path=/php/php72/etc \
--with-config-file-scan-dir=/php/php72/etc/conf \
--disable-rpath \
--disable-static \
--with-pic \
--with-layout=GNU \
--enable-calendar \
--enable-sysvsem \
--enable-sysvshm \
--enable-sysvmsg \
--enable-bcmath \
--with-bz2 \
--enable-ctype \
--with-cdb \
--with-iconv \
--enable-exif \
--enable-ftp \
--with-gettext \
--enable-mbstring \
--with-onig=/usr \
--with-pcre-regex=/usr \
--enable-shmop \
--enable-sockets \
--enable-wddx \
--with-libxml-dir=/usr \
--with-zlib \
--with-kerberos=/usr \
--with-openssl=/usr \
--enable-soap \
--enable-zip \
--with-mhash=yes \
--with-mysql-sock=/var/run/mysqld/mysqld.sock \
--with-mysqli=mysqlnd \
--enable-pdo \
--with-pdo-mysql=mysqlnd \
--enable-exif \
--with-jpeg-dir=/usr \
--with-png-dir=/usr \
--with-freetype-dir=/usr \
--with-zlib-dir=/usr \
--with-mhash \
--with-xsl=/usr \
--enable-zip \
--enable-cgi \
--with-curl \
--with-gd \
--enable-pcntl \
--enable-mbregex \
--with-libdir=lib64 \
--enable-dba=shared \
--enable-intl \
--with-readline=/usr \
--enable-simplexml \
--with-libdir=/lib/x86_64-linux-gnu \
--with-pspell \
--with-gmp \
--enable-opcache \
--without-pear
make
make install

Скопируем шаблон существующий шаблон phpfcgid

cp /usr/local/vesta/data/templates/web/apache2/phpfcgid.sh /usr/local/vesta/data/templates/web/apache2/php72.sh
cp /usr/local/vesta/data/templates/web/apache2/phpfcgid.stpl /usr/local/vesta/data/templates/web/apache2/php72.stpl
cp /usr/local/vesta/data/templates/web/apache2/phpfcgid.tpl /usr/local/vesta/data/templates/web/apache2/php72.tpl

Открываем файл /usr/local/vesta/data/templates/web/apache2/php72.sh и находим там строку

exec  /usr/bin/php-cgi

заменяем на

exec  /php/php72/bin/php-cgi

Для подключения Zend OPcache создадим файл /php/php72/etc/conf/opcache.ini с содержимым:

# Zend OPcache
zend_extension=opcache.so

 

С установкой PHP закончено.

Для пользовательских настроек пхп в папке каждого сайта нужно создать файл:

/home/{пользователь}/web/{домен}/cgi-bin/php.ini

После этого в настройках web домена появятся добавленные версии PHP. См. картинку:

select php vestacp debian8

Аналогично можно сделать и phpcgi

По умолчанию phpfcgid порождает 20 дочерних процессов для каждого домена, и если сайтов много - память сжирается очень быстро, поэтому вариант с phpcgi вполне жизнеспособен.

Если режим phpcgi вываливается с ошибкой The requested URL /cgi-bin/php/index.php was not found on this server - вероятно не включен модуль апача cgi. Включается командой:

a2enmod cgi
sevice apache2 restart

 

Готовые шаблоны phpcgi и phpfcgid можно скачать здесь

 

Для обобщения и доработки использовались материалы:

http://anikin.pw/all/multiversionnost-php-na-servere-s-vestacp/
http://anikin.pw/all/sborka-php-7-na-debian-8-jessie/