[Solved] Multiple PHP install

This forum is dedicated to advanced help and support :

Ask here your questions about advanced usage of Mageia. For example you may post here all your questions about network and automated installs, complex server configurations, kernel tuning, creating your own Mageia mirrors, and all tasks likely to be touchy even for skilled users.

[Solved] Multiple PHP install

Postby tis » Sep 18th, '21, 17:20

Hi,

Is there a solution to run 2 different versions of php under apache ( e.g. on a vhost runs different version, or I have to run 2 apache same time)?
Or is there a solution to easily switch php version with apache restart?

I'm developing a drupal module and drupal 8 runs with php7 and now drupal 9 with php8. But sometimes I at least should switch between php versions. I found that someone made something similar to debian/ubuntu.

Ty
Last edited by tis on Sep 21st, '21, 12:56, edited 1 time in total.
tis
 
Posts: 148
Joined: Sep 30th, '19, 20:19

Re: Multiple PHP install

Postby tis » Sep 19th, '21, 16:17

I've tried to compile an older php version 7.4.23 and insert that to mga httpd.conf (70_mod_php.conf removed for this test)
Code: Select all
LoadModule php7_module modules/libphp7.so
AddHandler php7-script .php

AddType application/x-httpd-php .php
AddType application/x-httpd-php .php7
AddType application/x-httpd-php .phtml
AddType application/x-httpd-php-source .phps

DirectoryIndex index.php index.phtml


It should be worked, but the server sais that:
Code: Select all
403 Forbidden: Execute Access Forbidden

The server is currently not serving php scripts.


And I renamed a test.php to test.php7 and it serves php....
Code: Select all
Array
(
    [HTTP_USER_AGENT] => Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0
    [HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
    [HTTP_ACCEPT_LANGUAGE] => hu-HU,hu;q=0.8,en-US;q=0.5,en;q=0.3
    [HTTP_ACCEPT_ENCODING] => gzip, deflate
    [HTTP_DNT] => 1
    [HTTP_CONNECTION] => keep-alive
    [HTTP_COOKIE] => cookieconsent_status=allow
    [HTTP_UPGRADE_INSECURE_REQUESTS] => 1
    [PATH] => /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
    [SERVER_SIGNATURE] =>
    [SERVER_SOFTWARE] => Apache/2.4.48 (Mageia) PHP/7.4.23 mod_perl/2.0.10 Perl/v5.32.1
    [SERVER_ADDR] => 127.0.0.1
    [SERVER_PORT] => 80
    [REMOTE_ADDR] => 127.0.0.1
    [REQUEST_SCHEME] => http
    [CONTEXT_PREFIX] =>
    [REMOTE_PORT] => 49800
    [GATEWAY_INTERFACE] => CGI/1.1
    [SERVER_PROTOCOL] => HTTP/1.1
    [REQUEST_METHOD] => GET
    [QUERY_STRING] =>
    [REQUEST_URI] => /test.php7
    [SCRIPT_NAME] => /test.php7
    [PHP_SELF] => /test.php7


but if I compile apache httpd and runs with this option it will serve php7 and my website code works well, unfortunately drupal 8 not working on this server yet. so there is some differences in configuration, and I may need to set something at mga httpd.conf to serve php with php7.
tis
 
Posts: 148
Joined: Sep 30th, '19, 20:19

Re: Multiple PHP install

Postby tis » Sep 19th, '21, 21:51

I've recompiled php7 with the same configure parameters as mga php8 was compiled and tried. The problem is the same with mga httpd, it can only open php7 files.
(I've overwritten lib64/php files and cli too).
Code: Select all
rpm -e php-xmlwriter-8.0.9-1.1.mga8 php-pdo-8.0.9-1.1.mga8 php-ctype-8.0.9-1.1.mga8 php-pdo_mysql-8.0.9-1.1.mga8 php-bz2-8.0.9-1.1.mga8 php-posix-8.0.9-1.1.mga8 php-apcu-5.1.19-1.mga8 php-xmlreader-8.0.9-1.1.mga8 php-gd-8.0.9-1.1.mga8 php-channel-phpunit-1.3-17.mga8 php-openssl-8.0.9-1.1.mga8 php-mysqli-8.0.9-1.1.mga8 php-sockets-8.0.9-1.1.mga8 php-cli-8.0.9-1.1.mga8 php-tokenizer-8.0.9-1.1.mga8 php-zlib-8.0.9-1.1.mga8 php-mbstring-8.0.9-1.1.mga8 php-mcrypt-1.0.4-1.mga8 php-dom-8.0.9-1.1.mga8 apache-mod_php-8.0.9-1.1.mga8 php-ftp-8.0.9-1.1.mga8 php-raphf-2.0.1-1.mga8 php-fpdf-1.8.2-1.mga8 php-iconv-8.0.9-1.1.mga8 php-sysvsem-8.0.9-1.1.mga8 php-curl-8.0.9-1.1.mga8 php-gettext-8.0.9-1.1.mga8 php-sysvshm-8.0.9-1.1.mga8 php-session-8.0.9-1.1.mga8 php-filter-8.0.9-1.1.mga8 php-zip-8.0.9-1.1.mga8 php-mysqlnd-8.0.9-1.1.mga8 php-cgi-8.0.9-1.1.mga8 --nodeps

cd src/php7
make install                 
Installing PHP SAPI module:       apache2handler
/usr/lib64/httpd/build/instdso.sh SH_LIBTOOL='/usr/lib64/apr-1/build/libtool' libphp7.la /usr/lib64/httpd/modules
/usr/lib64/apr-1/build/libtool --mode=install install libphp7.la /usr/lib64/httpd/modules/
libtool: install: install .libs/libphp7.so /usr/lib64/httpd/modules/libphp7.so
libtool: install: install .libs/libphp7.lai /usr/lib64/httpd/modules/libphp7.la
libtool: warning: remember to run 'libtool --finish php-7.4.23/libs'
chmod 755 /usr/lib64/httpd/modules/libphp7.so
[activating module `php7' in /etc/httpd/conf/httpd.conf]
Installing shared extensions:     /usr/lib64/extensions/no-debug-zts-20190902/
Installing PHP CLI binary:        /usr/bin/
Installing PHP CLI man page:      /usr/share/man/man1/
Installing PHP FPM binary:        /usr/sbin/
Installing PHP FPM defconfig:     /etc/
Installing PHP FPM man page:      /usr/share/man/man8/
Installing PHP FPM status page:   /usr/share/fpm/
Installing phpdbg binary:         /usr/bin/
Installing phpdbg man page:       /usr/share/man/man1/
Installing PHP CGI binary:        /usr/bin/
Installing PHP CGI man page:      /usr/share/man/man1/
Installing build environment:     /usr/lib64/build/
Installing header files:          /usr/include/php/
Installing helper programs:       /usr/bin/
  program: phpize
  program: php-config
Installing man pages:             /usr/share/man/man1/
  page: phpize.1
  page: php-config.1

./build/shtool install -c ext/phar/phar.phar /usr/bin/phar.phar
ln -s -f phar.phar /usr/bin/phar

I also tried to remove php packages and install php7 with make install with the same result, php files not served just php7 and html.

And a good news, that the downloaded httpd works with this libphp7 well, furthermore the drupal8 vhost is works well... (drupal9 too)
So I just have to recompile with different directory settings, then it could work only with different httpd start.
tis
 
Posts: 148
Joined: Sep 30th, '19, 20:19

Re: Multiple PHP install

Postby tis » Sep 20th, '21, 13:31

I found the difference. The /etc/httpd/conf/conf.d/security.conf checks only mod_php but libphp7 links to mod_php7 symbol....
Code: Select all
    <IfModule !mod_php.c>
+    <IfModule !mod_php7.c>
    <IfDefine !phpFPM>
   <FilesMatch "\.(php|php3|php4|php5|phps|phtml)$">
       ErrorDocument 403 "<h1>403 Forbidden: Execute Access Forbidden</h1>\
       <p>The server is currently not serving php scripts.</p><p>This \
       could mean the server administrator is doing maintenance or has \
       orphan php files laying around, please contact the server \
       administrator or come back later. Thank you.</p>"
       Require all denied
   </FilesMatch>
    </IfDefine>
+    </IfModule>
    </IfModule>
tis
 
Posts: 148
Joined: Sep 30th, '19, 20:19

Re: Multiple PHP install

Postby tis » Sep 20th, '21, 14:59

Finally, I could change between php7<->php8 in apache with some configfile modifications and a httpd restart. So I don't need second apache, and maybe I'm good at php 7.4.23 yet... :-)
Screenshot_20210920_151820.png
Drupal 9 status - php 7.4.23
Screenshot_20210920_151820.png (111.41 KiB) Viewed 9387 times


If you would like to change back to php 7:
1, download php 7.x you would like
2, compile with the same options as php -i sais
3, remove php8 (above rpm -e)
4. remove 70-mod-php.conf
5. edit security.conf and httpd.conf
6. install php 7
7. edit php.ini extensions location
8. start httpd

After this small good job :-) you can enjoy previuos php in mageia 8.

Do you know better solution? please share with us...
Ty
tis
 
Posts: 148
Joined: Sep 30th, '19, 20:19

Re: Multiple PHP install

Postby doktor5000 » Sep 20th, '21, 17:09

Compile the other php version into a custom prefix e.g. /opt/php7 as explained in e.g. viewtopic.php?f=41&t=14038
That way there's no need to uninstall packages to switch back and forth.
Cauldron is not for the faint of heart!
Caution: Hot, bubbling magic inside. May explode or cook your kittens!
----
Disclaimer: Beware of allergic reactions in answer to unconstructive complaint-type posts
User avatar
doktor5000
 
Posts: 17629
Joined: Jun 4th, '11, 10:10
Location: Leipzig, Germany

Re: Multiple PHP install

Postby tis » Sep 20th, '21, 18:08

Ty,

If I found that topic earlier, I hadn' got the "security.conf issue", so I wouldn't remove php8. :-) and I also have 2 different version after I reinstalled php8 with urpmi.

On the other hand I have no solution yet to easily switch from php7 to php8 and back. Yeah I have to change mod_php.conf, and php.ini and restart apache will work.

And also if you build with seting config file path only modphp settings must change.
The configure:
Code: Select all
'./configure'  '--prefix=/opt/php7' '--enable-fpm' '--with-fpm-user=apache' '--with-fpm-group=apache' '--with-fpm-systemd' '--enable-cli' '--with-apxs2=/usr/bin/apxs' '--enable-maintainer-zts' '--with-pic' '--build=x86_64-mageia-linux-gnu' '--exec-prefix=/opt/php7/usr' '--bindir=/opt/php7/usr/bin' '--sbindir=/opt/php7/usr/sbin' '--sysconfdir=/opt/php7/etc' '--datadir=/opt/php7/usr/share' '--includedir=/opt/php7/usr/include' '--libdir=/opt/php7/usr/lib64' '--libexecdir=/opt/php7/usr/libexec' '--localstatedir=/opt/php7/var/lib' '--mandir=/opt/php7/usr/share/man' '--enable-shared=yes' '--enable-static=no' '--disable-debug' '--enable-bcmath=shared' '--enable-calendar=shared' '--enable-ctype=shared' '--enable-dba=shared' '--enable-dom=shared,/usr' '--enable-exif=shared' '--enable-fileinfo=shared' '--enable-filter=shared' '--enable-ftp=shared' '--enable-gd=shared' '--enable-intl=shared' '--enable-mbregex' '--enable-mbstring=shared,/usr' '--enable-mysqlnd=shared,/usr/bin/mysql_config' '--enable-opcache=shared' '--enable-pcntl=shared' '--enable-pdo=shared,/usr' '--enable-phar=shared' '--enable-phpdbg' '--enable-phpdbg-webhelper' '--enable-posix=shared' '--enable-session=shared,/usr' '--enable-shmop=shared,/usr' '--enable-simplexml' '--enable-soap=shared,/usr' '--enable-sockets=shared,/usr' '--enable-sysvmsg=shared,/usr' '--enable-sysvsem=shared,/usr' '--enable-sysvshm=shared,/usr' '--enable-tokenizer=shared,/usr' '--enable-xmlreader=shared,/usr' '--enable-xmlwriter=shared,/usr' '--with-zip=shared' '--with-bz2=shared,/usr' '--with-cdb' '--with-config-file-path=/opt/php7/etc' '--with-config-file-scan-dir=/etc/php.d' '--with-curl=shared,/usr' '--with-db4' '--with-enchant=shared,/usr' '--with-freetype=/usr' '--with-gdbm' '--with-external-gd=shared,/usr' '--with-gettext=shared,/usr' '--with-gmp=shared,/usr' '--with-iconv=shared' '--with-imap=shared,/usr' '--with-imap-ssl=/usr' '--with-jpeg=/usr' '--with-ldap-sasl' '--with-ldap=shared,/usr' '--with-libdir=lib64' '--with-mhash=shared,/usr' '--with-mysqli=shared,mysqlnd' '--with-mysql-sock=/var/lib/mysql/mysql.sock' '--with-openssl-dir=/usr' '--with-openssl=shared,/usr' '--without-pear' '--with-external-pcre=/usr' '--with-pcre-jit' '--with-pdo-dblib=shared,/usr' '--with-pdo-firebird=shared,/usr/lib64/firebird' '--with-pdo-mysql=shared,mysqlnd' '--with-pdo-odbc=shared,unixODBC,/usr' '--with-pdo-pgsql=shared,/usr' '--with-pdo-sqlite=shared,/usr' '--with-pgsql=shared,/usr' '--with-readline=shared,/usr' '--with-snmp=shared,/usr' '--with-sodium=shared,/usr' '--with-sqlite3=shared,/usr' '--with-system-ciphers' '--with-tidy=shared,/usr' '--with-unixODBC=shared,/usr' '--with-webp=/usr' '--with-xpm=/usr/X11R6' '--with-xsl=shared,/usr' '--with-zlib=shared,/usr' '--with-zlib-dir=/usr' 'build_alias=x86_64-mageia-linux-gnu' 'PKG_CONFIG_PATH=:/usr/lib64/pkgconfig:/usr/share/pkgconfig' 'ENCHANT_CFLAGS=-I/usr/include/enchant-2 -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -pthread ' 'ENCHANT_LIBS=-lenchant-2 '

with this, the php.ini used from /opt/php/etc for php7 and /etc/php.ini for php8, and only 70_mod_php.conf have to be changed and restart httpd.
Now the only difference in php.ini
Code: Select all
extension_dir = "/opt/php7/usr/lib64/extensions/no-debug-zts-20190902/"


and i just have to copy or ln the desired mod_php.conf file....

Unfortunately modphp8 and modphp7 cannot be loaded in the same time (went failure), and I cannot find how to load php7 to vhost1 and php8 to vhost2, only 1 can run in same time, whenever I run another apache....
tis
 
Posts: 148
Joined: Sep 30th, '19, 20:19

Re: Multiple PHP install

Postby tis » Sep 21st, '21, 11:53

Also you can set '--with-config-file-scan-dir=/opt/php7/etc/php.d' to get the opportunity to different e.g. mysqli config.

Finally, as two mod_php cannot be loaded, you can install mod_fcgid too. With this module I can reach that drupal8 runs on php7 menawhile all the others on php8. You do not need to change and restart all the time, http-get the different domains (virtual hosts)...

my drupal8 vhost example:
Code: Select all
<VirtualHost *:80>
    DocumentRoot "/www/apache/drupal-8.8.3"
    ServerName drupal

            FcgidInitialEnv PHPRC "/opt/php7/"

    # Other directives here
    <Directory /www/apache/drupal-8.8.3>
            Options Indexes FollowSymLinks MultiViews ExecCGI
            AllowOverride All
            Require all granted

            AddHandler fcgid-script .php
            FcgidWrapper "/opt/php7/bin/php-cgi" .php
            AddType application/x-httpd-php .php

            Order allow,deny
            Allow from all
    </Directory>

    ErrorLog "logs/vhost_drupal_log"
    LogLevel warn
   
</VirtualHost>


Screenshot_20210921_114113.png
Drupal on PHP8 server - running with php7-cgi
Screenshot_20210921_114113.png (100.19 KiB) Viewed 9334 times


So this is better than good enough solution to me now...
tis
 
Posts: 148
Joined: Sep 30th, '19, 20:19

Re: [Solved] Multiple PHP install

Postby tis » Mar 1st, '23, 10:58

Since this solution I'm using multiple PHPs well.

Currently Drupal 10 requires PHP 8.1, I've found and have installed from Core Backports v. 8.1.15...

Then I realized, my test env. Drupal 9.2.6 works better with PHP 8.0, so I had to do the same as above:

1, download PHP 8.0.28.
2, compile with Mageia like settings:
Code: Select all
'./configure'  '--prefix=/opt/php8' '--enable-fpm' '--with-fpm-user=apache' '--with-fpm-group=apache' '--with-fpm-systemd' '--enable-cli' '--with-apxs2=/usr/bin/apxs' '--enable-zts' '--with-pic' '--build=x86_64-mageia-linux-gnu' '--exec-prefix=/opt/php8/usr' '--bindir=/opt/php8/usr/bin' '--sbindir=/opt/php8/usr/sbin' '--sysconfdir=/opt/php8/etc' '--datadir=/opt/php8/usr/share' '--includedir=/opt/php8/usr/include' '--libdir=/opt/php8/usr/lib64' '--libexecdir=/opt/php8/usr/libexec' '--localstatedir=/opt/php8/var/lib' '--mandir=/opt/php8/usr/share/man' '--enable-shared=yes' '--enable-static=no' '--disable-debug' '--enable-bcmath=shared' '--enable-calendar=shared' '--enable-ctype=shared' '--enable-dba=shared' '--enable-dom=shared,/usr' '--enable-exif=shared' '--enable-fileinfo=shared' '--enable-filter=shared' '--enable-ftp=shared' '--enable-gd=shared' '--enable-intl=shared' '--enable-mbregex' '--enable-mbstring=shared,/usr' '--enable-mysqlnd=shared,/usr/bin/mysql_config' '--enable-opcache=shared' '--enable-pcntl=shared' '--enable-pdo=shared,/usr' '--enable-phar=shared' '--enable-phpdbg' '--enable-phpdbg-webhelper' '--enable-posix=shared' '--enable-session=shared,/usr' '--enable-shmop=shared,/usr' '--enable-simplexml' '--enable-soap=shared,/usr' '--enable-sockets=shared,/usr' '--enable-sysvmsg=shared,/usr' '--enable-sysvsem=shared,/usr' '--enable-sysvshm=shared,/usr' '--enable-tokenizer=shared,/usr' '--enable-xmlreader=shared,/usr' '--enable-xmlwriter=shared,/usr' '--with-zip=shared' '--with-bz2=shared,/usr' '--with-cdb' '--with-config-file-path=/opt/php8/etc' '--with-config-file-scan-dir=/etc/php.d' '--with-curl=shared,/usr' '--with-db4' '--with-enchant=shared,/usr' '--with-freetype=/usr' '--with-gdbm' '--with-external-gd=shared,/usr' '--with-gettext=shared,/usr' '--with-gmp=shared,/usr' '--with-iconv=shared' '--with-imap=shared,/usr' '--with-imap-ssl=/usr' '--with-jpeg=/usr' '--with-ldap-sasl' '--with-ldap=shared,/usr' '--with-libdir=lib64' '--with-mhash=shared,/usr' '--with-mysqli=shared,mysqlnd' '--with-mysql-sock=/var/lib/mysql/mysql.sock' '--with-openssl-dir=/usr' '--with-openssl=shared,/usr' '--without-pear' '--with-external-pcre=/usr' '--with-pcre-jit' '--with-pdo-dblib=shared,/usr' '--with-pdo-firebird=shared,/usr/lib64/firebird' '--with-pdo-mysql=shared,mysqlnd' '--with-pdo-odbc=shared,unixODBC,/usr' '--with-pdo-pgsql=shared,/usr' '--with-pdo-sqlite=shared,/usr' '--with-pgsql=shared,/usr' '--with-readline=shared,/usr' '--with-snmp=shared,/usr' '--with-sodium=shared,/usr' '--with-sqlite3=shared,/usr' '--with-system-ciphers' '--with-tidy=shared,/usr' '--with-unixODBC=shared,/usr' '--with-webp=/usr' '--with-xpm=/usr/X11R6' '--with-xsl=shared,/usr' '--with-zlib=shared,/usr' '--with-zlib-dir=/usr' 'build_alias=x86_64-mageia-linux-gnu' 'PKG_CONFIG_PATH=:/usr/lib64/pkgconfig:/usr/share/pkgconfig' 'ENCHANT_CFLAGS=-I/usr/include/enchant-2 -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -pthread ' 'ENCHANT_LIBS=-lenchant-2 '

3, make and then install to /opt/php8
4, I have pecl packages installed like apcu,... I had to download and compile them to this configuration too
5, edit extension dir in /opt/php8/etc/php.ini
6, edit drupal-9.2.6 vhost file as above to use php8fcgi

So Now I have 3 phps, So I can test a lot of web codes on it...
tis
 
Posts: 148
Joined: Sep 30th, '19, 20:19


Return to Advanced support

Who is online

Users browsing this forum: No registered users and 1 guest

cron