php.ini version and apache php version is a different - php

I installed php 8.1 and some of my sites are not working. I select version php 7.4
use the command update-alternatives --config php
and apache2 shows that the version is selected. But the Apache server itself runs php 8.1 this proves the php.ini file and not working sites. How do I back to php 7.4?
I've also tried making changes like:
AddHandler application/x-httpd-php73 .php
in a .htaccess
and
<VirtualHost *:80>
ServerAdmin webmaster#example.com
ServerName example.com
ServerAlias www.example.com
<IfModule mod_fastcgi.c>
AddHandler php74-fcgi .php
</IfModule>
So doesn't work at all, I no have idea the next steps...
enter image description here

turned out to be easier than it was, after disabling the additional config, you can freely switch between versions php
a2disconf php8.1-fpm.conf

Related

How to use Multiple xampp Like xampp php version 5, xampp php version 7, version 8. I also install it but problem new laravel project npm not install

when i run xampp php version 7 all are good but when i run xampp php version 8 but my current project not work this is my laravel 9 xampp php version 8 current project
and another problem when i run new project and install npm install && npm run dev but it's not work
npm install
and when I run npm run dev this result npm run dev
and when I run php artisan migrate and serve after then login url
Why switch between PHP versions when you can use multiple PHP versions at the same time with a single xampp installation?
With a single xampp installation, you have 2 options:
Run an older PHP version for only the directory of your old project: This will serve the purpose most of the time. You may have one or two old projects that you intend to run with an older PHP version. Just configure xampp to run an older PHP version for only those project directories.
Run an older PHP version on a separate port of xampp: Sometimes you may be upgrading an old project to the latest PHP version and at the same time you need to run the same project back and forth between the new PHP version and the old PHP version. To do this you can set an older PHP version on a different port (say 8056) so when you go to http://localhost/any_project/, xampp runs PHP 7 and when you go to http://localhost:8056/any_project/ xampp runs PHP 5.6.
Run an older PHP version on a virtualhost: You can create a virtualhost like localhost56 to run PHP 5.6 while you can use PHP 7 on localhost.
Lets set it up
Step 1: Download PHP
So you have PHP 7 running under xampp, you want to add an older PHP version to it (say PHP 5.6). Download the nts (Non Thread Safe) version of the PHP zip archive from php.net (see archive for older versions) and extract the files under c:\xampp\php56. The thread safe version does not include php-cgi.exe.
Step 2: Configure php.ini
Open the file c:\xampp\php56\php.ini in notepad. If the file does not exist, copy php.ini-development to php.ini and open it in notepad. Then uncomment the following line:
extension_dir = "ext"
Also if the following line exists in Apache config httpd-xampp.conf
SetEnv PHPRC "\\path\\to\\xampp\\php"
comment it out with with a leading # (hash character).
Step 3: Configure apache
Open xampp control panel, click the config button for apache, and click Apache (httpd-xampp.conf). A text file will open. Put the following settings at the bottom of the file:
ScriptAlias /php56 "C:/xampp/php56"
Action application/x-httpd-php56-cgi /php56/php-cgi.exe
<Directory "C:/xampp/php56">
AllowOverride None
Options None
Require all denied
<Files "php-cgi.exe">
Require all granted
</Files>
</Directory>
Note: You can add more versions of PHP to your xampp installation following step 1 to 3 if you want.
Step 4 (option 1): [Add Directories to run a specific PHP version]
Now you can set directories that will run in PHP 5.6. Just add the following at the bottom of the config file (httpd-xampp.conf from Step 3) to set directories.
<Directory "C:\xampp\htdocs\my_old_project1">
<FilesMatch "\.php$">
SetHandler application/x-httpd-php56-cgi
</FilesMatch>
</Directory>
<Directory "C:\xampp\htdocs\my_old_project2">
<FilesMatch "\.php$">
SetHandler application/x-httpd-php56-cgi
</FilesMatch>
</Directory>
Step 4 (option 2): [Run an older PHP version on a separate port]
Now to to set PHP v5.6 on port 8056, add the following code to the bottom of the config file (httpd-xampp.conf from Step 3).
Listen 8056
<VirtualHost *:8056>
<FilesMatch "\.php$">
SetHandler application/x-httpd-php56-cgi
</FilesMatch>
</VirtualHost>
Step 4 (option 3): [Run an older PHP version on a virtualhost]
To create a virtualhost (localhost56) on a directory (htdocs56) to use PHP v5.6 on http://localhost56, create directory htdocs56 at your desired location and
add localhost56 to your hosts file (see how),
then add the following code to the bottom of the config file (httpd-xampp.conf from Step 3).
<VirtualHost localhost56:80>
DocumentRoot "C:\xampp\htdocs56"
ServerName localhost56
<Directory "C:\xampp\htdocs56">
Require all granted
</Directory>
<FilesMatch "\.php$">
SetHandler application/x-httpd-php56-cgi
</FilesMatch>
</VirtualHost>
Finish: Save and Restart Apache
Save and close the config file. Restart apache from the xampp control panel. If you went for option 2, you can see the additional port(8056) listed in your xampp control panel.
For more information, take a look at this thread: Is there way to use two PHP versions in XAMPP?

How can I change the PHP version used by phpmyadmin?

I have phpmyadmin installed on my ubuntu server, that runs several versions of PHP depending on the website used.
The default version is 7.4, but phpmyadmin use 7.2 for unknown reason.
Simple question : where do I change that ?
Cannot find it in any forum or documentation...
I tried to put in phpmyadmin/apache.conf what I use in my virtual hosts sites :
<FilesMatch \.php$>
SetHandler "proxy:unix:/var/run/php/php7.4-fpm.sock|fcgi://localhost/"
</FilesMatch>
but it doesn't work and I still have 7.2
Thanks a lot !
Solution found !
As my Phpmyadmin installation doesn't use the virtual host file system, the file to modify is /etc/phpmyadmin/apache.conf
I put a code, but outside the Directory tags, and you have to put it inside to make it work :
<Directory /usr/share/phpmyadmin>
<FilesMatch \.php$>
SetHandler "proxy:unix:/var/run/php/php7.4-fpm.sock|fcgi://localhost/"
</FilesMatch>
</Directory>
And then, restart Apache change the PHP version of phpmyadmin page.
Thanks !
Add the below code inside /etc/phpmyadmin/apache.conf
<Directory /usr/share/phpmyadmin>
<FilesMatch \.php$>
SetHandler "proxy:unix:/var/run/php/php8.1-fpm.sock|fcgi://localhost/"
</FilesMatch>
</Directory>
After that restart Apache
sudo systemctl restart apache2
Here's how I do it:
Go to phpMyAdmin config
cd /etc/apache2/sites-available
Open config file
sudo nano phpmyadmin.conf
Put the following line inside the tags to serve 7.4:
include /etc/apache2/conf-available/php7.4-fpm.conf
Restart apache:
sudo systemctl restart apache2
Note that my setup is mostly from this tutorial.

Apache+PHP - different php versions per VHost

On my local dev maschine (Ubuntu), I have apache2 and different php version to develop different projects, managed over Vhosts.
Is there a way to configure each vhost to use a specific (already installed) PHP version? So for example:
example1.local should use PHP 7.4
example2.local should use PHP 8.0
example3.local should use PHP 8.0
example4.local should use PHP 5.6
Currently, I am always running for example sudo a2enmod php{X} & sudo a2dismod php{Y} & sudo service apache2 restart to switch versions, which is really anoying.
I see you are using Apache. So you can use a .htaccess file and add there
AddHandler application/x-httpd-php74 .php
In this way your vhost uses php version 7.4
or with normal apache configuration
<VirtualHost *:80>
ServerAdmin webmaster#example.com
ServerName example.com
ServerAlias www.example.com
<IfModule mod_fastcgi.c>
AddHandler php74-fcgi .php
</IfModule>
</VirtualHost>

apache2.4 build not finding php5.3

I am setting up a test server before upgrading an elderly version of mediawiki on a production server. I am trying to duplicate what will be on the production server - apache2.4 and php5.3.
When I try to access any php file, the server displays it as text rather than running it.
This is all running on Ubuntu 12.04 LTS. The apache package available is version 2.2, so I can't simply apt-get.
I have built apache 2.4 from source, and it correctly serves an index.html from my designated DocumentRoot.
In httpd.conf, I have added:
DocumentRoot = /var/www
AddType application/x-httpd-php .php
<filesMatch>"\.php$:"
SetHandler application/x-httpd-php .php
</filesMatch>
I have installed php5.3, and it is working - I can run phpinfo.php from a command line.
In /etc/php5/apache2/php.ini I have (error displays are for testing only):
engine = On
display_errors = On
display_startup_errors = On
doc_root = /var/www
I am not able to find a reference to a mod_php of any sort either in the httpd.conf or in the directory in which httpd is installed (/usr/local/apache2).
Some of the references on the web mention "modules-available" and "modules-enabled" but these appear to be a convenience added by Debian, and are not part of the apache source build.
What am I missing? I'm sure it's something simple.
After searching and using packages from several repositories for both apache and php, and trying to build either or both from source, I determined that there did not seem to be a libphp5.so that was compatible with apache 2.4. In any case, I didn't find it.
I reconfigured everything to use php as cgi rather than as a module, and got things working that way, which was enough for my intended purpose.
You need to load php module in httpd.conf:
On my Linux Slackware I have this in /etc/httpd/mod_php.conf
LoadModule php5_module lib/httpd/modules/libphp5.so
# Tell Apache to feed all *.php files through PHP. If you'd like to
# parse PHP embedded in files with different extensions, comment out
# these lines and see the example below.
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
And in /etc/httpd/httpd.conf:
# php
Include /etc/httpd/mod_php.conf

Apache with passenger and php modules, not executing php

I have a rails setup which is served by Apache Passenger, there are 2 apps on the server which are served by passenger and all was working fine. I then wanted to install wordpress on the same server and so I installed the required packages "php5 php5-mysql libapache2-mod-php" and setup a separate vhost for wordpress, when I try to run the wordpress index.php file, apache doesn't execute but rather offers me to download.
I have googled this to no resolution, this problem is pretty common but none of the solutions have worked for me. Solutions that I have tried:
Adding "AddType application/x-httpd-php .php" in apache2.conf
making the wordpress directory executable, also changed the owner of the directory to www-data
In the vhost of wordpress, disabled Passenger by setting PassengerEnabled Off in the Directory directive.
Verified that php module is loaded by apache2ctl -M
Checked error log and nothing there, enabled error log for that vhost but nothing there.
any pointers, help appreciated thanks. BTW, the same setup works on local development box, its just this instance being painful can't recreate things from scratch.
Do you have a handler for the *.php extension?
My handler looks like this (with type included for clarity):
AddHandler php5-script .php
AddType text/html .php
Or from the documentation:
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
How did you enable the php module, did you use a2enmod or did you add it by hand?
Try removing the extra "AddType application/x-httpd-php .php" in apache2.conf and then run
sudo a2dismod php5; sudo a2enmod php5; sudo service apache2 restart
If you have already done that, please provide the contents of php5.conf, vhost file and everything else you believe is relative.

Categories