skip to Main Content

I just try to switch from php7.4 to php8.2 changing .httaccess like this:

DirectoryIndex index.php
AddHandler application/x-httpd-php82 .php
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>

I am not succeeding. This is output of

sudo update-alternatives --config php

enter image description here

.htaccess is stored in same folder info.php is stored. Why is php8.2 not version being used for? I want to switch between different php versions depending on code being used for different subdomains. This is output of info.php:

enter image description here

Here is an extraction of Vhost:

<Directory /var/www/testshop.leitner-sales.at>
Options -Indexes +FollowSymLinks +MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>

2

Answers


  1. Chosen as BEST ANSWER

    T.Miles, your solution suggested throws out 500 Server Error. In /var/log/apache2/error.log will be deposited following error message

    Invalid command 'Action', perhaps misspelled or defined by a module not included in the server configuration
    

    I fixed it fireing following commands:

    sudo a2enmod actions
    sudo service apache2 restart
    

    but it din't change output of info.php Just PHP version 7.4.33 is using, not php version 8.2! Ur solution doesn't throw out error, but it seems to be ineffective. I implemented ur suggestion in VHost /etc/apache2/sites-available/shop.conf I noticed, php8.2 is not loaded, at all:

    enter image description here


  2. First off, welcome to Stack Overflow and good on you for updating, a little late to the party tho ;P You’ll love php ^8.

    Now, typically, php can be run in multiple ways like CLI and GUI (there are actually many more, but off-topic), which is the server context. In a stock installation of apache with php the users request is forwarded to PHP’s .so file. This file is actually the artifact of compiling PHP directly from its source code written in C.

    This is all to say if you have not restarted apache that new compiled handler may not be found.

    Let’s dig in deeper. You’re adding a handler in apache to the .htaccess file, which is cleaver I’ve never seen that, but this handlers definition (aka the executable it points to) is defined in the server config. Typically httpd.conf. Many things can not be added to the .htaccess but must be loaded at startup, not call-time. When you type php in the command line you are actually using a different executable php than apache should. Thus your php-cli vs php-cgi.

    # In httpd.conf or a configuration file included by it
    <IfModule mod_php7.c>
        AddHandler application/x-httpd-php74 .php
        Action application/x-httpd-php74 /cgi-bin/php74-cgi
    </IfModule>
    
    <IfModule mod_php8.c>
        AddHandler application/x-httpd-php80 .php
        Action application/x-httpd-php80 /cgi-bin/php80-cgi
    </IfModule>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search