multiPHP version w Vhost - directive PHPINIDir not working

Problems with the Linux version of XAMPP, questions, comments, and anything related.

multiPHP version w Vhost - directive PHPINIDir not working

Postby smalldragoon » 29. May 2019 23:53

Hi,
I configured my apache to have php 56.and 7.2 running together.
I created a VHost where I want to have 7.2 running -> fine
Now, I would like to use a specific php.ini . I use the option
but it is not working
what am I missing ?
here is the Vhost config

Code: Select all
DocumentRoot /var/www/html2
<Directory "/var/www/html2">
allow from all
Options None
Require all granted
</Directory>
        <FilesMatch \.php$>
        # Apache 2.4.10+ can proxy to unix socket
        SetHandler "proxy:unix:/var/run/php/php7.2-fpm.sock|fcgi://localhost/"
       </FilesMatch>

ErrorLog ${APACHE_LOG_DIR}/error80.log
CustomLog ${APACHE_LOG_DIR}/access80.log combined
PHPINIDir /var/www/html2
php_value session.save_path /tmp
Thanks !
smalldragoon
 
Posts: 14
Joined: 29. May 2019 23:47
XAMPP version: 1.0
Operating System: ubuntu

Re: multiPHP version w Vhost - directive PHPINIDir not worki

Postby Nobbie » 30. May 2019 10:59

You cannot use PHPINIDir in a VirtualHost Context, the following link tells you why: https://serverfault.com/questions/46170 ... rtualhosts
Nobbie
 
Posts: 11106
Joined: 09. March 2008 13:04

Re: multiPHP version w Vhost - directive PHPINIDir not worki

Postby smalldragoon » 30. May 2019 13:55

Hi Nobbie,
thanks for your Answer
in fact, I already tried that option as I just wanted to change 1 value of the php.ini
But whatever the value I'm putting, there is no changes ( checking with phpinfo )

here is my full vhost config


Code: Select all
DocumentRoot /var/www/html2
<Directory "/var/www/html2">
allow from all
Options None
Require all granted
</Directory>
 <FilesMatch \.php$>
        # Apache 2.4.10+ can proxy to unix socket
        SetHandler "proxy:unix:/var/run/php/php7.2-fpm.sock|fcgi://localhost/"
    </FilesMatch>
   
   
    ErrorLog ${APACHE_LOG_DIR}/error80.log
   CustomLog ${APACHE_LOG_DIR}/access80.log combined

php_value session.save_path "/tmp"



I tried as well othervalues in case of , like

php_value post_max_size "60M"
php_value upload_max_filesize "60M"

but no changes... ( I restart apache after each change of course )
any suggestion ?
Thanks
smalldragoon
 
Posts: 14
Joined: 29. May 2019 23:47
XAMPP version: 1.0
Operating System: ubuntu

Re: multiPHP version w Vhost - directive PHPINIDir not worki

Postby Nobbie » 30. May 2019 22:46

I dont have any experience about running PHP-FPM and i dont have any experience about running PHP-FPM as unix proxy vs. a moduled PHP. That looks very strange for me, do you really know what you are doing there?

I would simply configure both PHP versions as PHP CGI (i already did that before) and it runs smoothly without any hassle. What is the goal of your extremely "sophisticated" configuration? Keep it simple instead.
Nobbie
 
Posts: 11106
Joined: 09. March 2008 13:04

Re: multiPHP version w Vhost - directive PHPINIDir not worki

Postby smalldragoon » 31. May 2019 09:33

In fact, I just need to have 2 differents versions of PHP ( 5.6 and 7.2 ) running on the same server.
I use this method as I foudn a detailed procedure/tutorial but happy to switch to anything else as long as it works :D
I have no experience running PHP-FPM , I just followed steps ...
my need is very basic
everything starting from /var/www/html must use 5.6
everything starting from /var/www/html2 must use 7.2
:D
smalldragoon
 
Posts: 14
Joined: 29. May 2019 23:47
XAMPP version: 1.0
Operating System: ubuntu

Re: multiPHP version w Vhost - directive PHPINIDir not worki

Postby Nobbie » 31. May 2019 11:15

Which Linux are you running and where (and how!) did you install both PHP5 and PHP7?

Here i found a forum where someone shows how to switch between PHP5 and PHP7 on the fly, but not to run them at the same time: https://askubuntu.com/questions/761713/ ... -04/762161

You could also run VirtualBox and install two machines (both Linux or Windows, does not matter) and install Apache with PHP5 into one machine, Apache with PHP7 into the other machine. From my point of view this is the easiest way and you have the big advantage that the virtual machines are running in their own environment and do not collide in any way.
Nobbie
 
Posts: 11106
Joined: 09. March 2008 13:04

Re: multiPHP version w Vhost - directive PHPINIDir not worki

Postby smalldragoon » 31. May 2019 13:13

I'm using ubuntu.
Unfortunately, I must run the 2 version on the same host. I can not use virtualmachine or other trics like that :(
smalldragoon
 
Posts: 14
Joined: 29. May 2019 23:47
XAMPP version: 1.0
Operating System: ubuntu

Re: multiPHP version w Vhost - directive PHPINIDir not worki

Postby Nobbie » 31. May 2019 15:18

How did you install PHP5 and PHP7 and where did you install them?
Nobbie
 
Posts: 11106
Joined: 09. March 2008 13:04

Re: multiPHP version w Vhost - directive PHPINIDir not worki

Postby smalldragoon » 31. May 2019 19:29

I used standard APT tool
and they are both installed into 2 different directories

/etc/php/5.6
/etc/php/7.2
smalldragoon
 
Posts: 14
Joined: 29. May 2019 23:47
XAMPP version: 1.0
Operating System: ubuntu

Re: multiPHP version w Vhost - directive PHPINIDir not worki

Postby Nobbie » 31. May 2019 19:47

Ok. Then create two VirtualHosts, one for each PHP version. Apply PHP5 CGI for one, PHP7 CGI for the other VirtualHost. There is plenty of documentation how to establish PHP CGI Mode.
Nobbie
 
Posts: 11106
Joined: 09. March 2008 13:04

Re: multiPHP version w Vhost - directive PHPINIDir not worki

Postby smalldragoon » 01. June 2019 19:05

ok, thanks will search for tutorials and let you know

Thanks a lot _
smalldragoon
 
Posts: 14
Joined: 29. May 2019 23:47
XAMPP version: 1.0
Operating System: ubuntu

Re: multiPHP version w Vhost - directive PHPINIDir not worki

Postby Nobbie » 02. June 2019 10:35

Here is a working example for PHP7 CGI in a VirtualHost:

Code: Select all
<VirtualHost *:80>
   ServerAdmin xxxxxxxx
   DocumentRoot "/opt/lampp/htdocs"
   ServerName php7.localhost
   ErrorLog "logs/php7_error_log"
   CustomLog "logs/php7_access_log" common

   ScriptAlias /local-bin /usr/bin
   AddHandler application/x-httpd-php php
   Action application/x-httpd-php /local-bin/php-cgi
<Directory "/usr/bin">
    Require all granted
</Directory>
<Directory "/opt/lampp/htdocs">
    Options Indexes FollowSymLinks ExecCGI Includes
    AllowOverride All
    Require all granted
</Directory>
</VirtualHost>


You can take this as basic configuration, add another VirtualHost for PHP5 (apply another ServerName, for example php5.localhost) and change the pathnames to your needs (i used the pathes of my installation). You may use the same DocumentRoot for both VirtualHosts, but you also can use different DocumentRoots. Add an entry for php7.localhost and php5.localhost into your hosts file (/etc/hosts) and assign 127.0.0.1 to both. Instead of /usr/bin/php-cgi you probably have to use /etc/php/5.6/php-cgi or maybe /usr/bin/php5.6-cgi or so (i dont know, i am running Linux Mint and there is no PHP 5.6 in the repository). Dont overlook that "Require all granted" for the path of the php-cgi executable, otherwise you will end up in an 403 error. You also need "Require all granted" for the DocumentRoot (for both).

After all, when everything is working, you have to enter http://php5.localhost/myfile.php for PHP 5.6 and http://php7.localhost/myfile.php for PHP 7.2. Thats very handy!
Nobbie
 
Posts: 11106
Joined: 09. March 2008 13:04

Re: multiPHP version w Vhost - directive PHPINIDir not worki

Postby smalldragoon » 05. June 2019 23:31

with all the changes I made, my config was screwed. so I restarted a full install till the point I was adding 2 different PHP versions.
So my virtual host are just based on port , so based on your exemple, I created a new Vhost listening on port 80 ( I changed the other one to 81 )
my "default" version of php is the opposite, but it is just a switch at the end ( main is 5.6 , new Vhost is 7.2 )
Here the vhost config, where apache do not care at all about the changes ( I still have a 5.6 executing a php_info )
Maybe I should enable something ?
Code: Select all
   DocumentRoot "/var/www/html2"
   ScriptAlias /local-bin /usr/bin
   AddHandler application/x-httpd-php php .php
   Action application/x-httpd-php /usr/bin/php-cgi7.2

<Directory "/usr/bin">
    Require all granted
</Directory>


ErrorLog ${APACHE_LOG_DIR}/error80.log
CustomLog ${APACHE_LOG_DIR}/access80.log combined
smalldragoon
 
Posts: 14
Joined: 29. May 2019 23:47
XAMPP version: 1.0
Operating System: ubuntu

Re: multiPHP version w Vhost - directive PHPINIDir not worki

Postby Nobbie » 06. June 2019 09:02

If you need help, you should apply all informations including full configuration, what you enter into the browser etc.

Actually its not a good idea to use a different port (probably going wrong), why did you do so?

The Action is wrong (but thats not the reason of your problem, but it would go wrong if the VirtualHost would be used), instead of /usr/bin you should apply /local-bin
Nobbie
 
Posts: 11106
Joined: 09. March 2008 13:04

Re: multiPHP version w Vhost - directive PHPINIDir not worki

Postby smalldragoon » 06. June 2019 13:44

Hi, so here are all the info

apache.conf
Code: Select all
#
ErrorLog ${APACHE_LOG_DIR}/error.log

LogLevel warn

# Include module configuration:
IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf

# Include list of ports to listen on
Include ports.conf


# Sets the default security model of the Apache2 HTTPD server. It does
# not allow access to the root filesystem outside of /usr/share and /var/www.
# The former is used by web applications packaged in Debian,
# the latter may be used for local directories served by the web server. If
# your system is serving content from a sub-directory in /srv you must allow
# access here, or in any related virtual host.
<Directory />
        Options FollowSymLinks
        AllowOverride All
        Require all denied
</Directory>

<Directory /usr/share>
        AllowOverride All
        Require all granted
</Directory>

<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
AllowOverride All
</Directory>

#<Directory /srv/>
#       Options Indexes FollowSymLinks
#       AllowOverride All
#       Require all granted
#</Directory>




# AccessFileName: The name of the file to look for in each directory
# for additional configuration directives.  See also the AllowOverride
# directive.
#
AccessFileName .htaccess

#
# The following lines prevent .htaccess and .htpasswd files from being
# viewed by Web clients.
#
<FilesMatch "^\.ht">
        Require all denied
</FilesMatch>


#
# The following directives define some format nicknames for use with
# a CustomLog directive.
#
# These deviate from the Common Log Format definitions in that they use %O
# (the actual bytes sent including headers) instead of %b (the size of the
# requested file), because the latter makes it impossible to detect partial
# requests.
#
# Note that the use of %{X-Forwarded-For}i instead of %h is not recommended.
# Use mod_remoteip instead.
#
LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent


# Include generic snippets of statements
IncludeOptional conf-enabled/*.conf

# Include the virtual host configurations:
IncludeOptional sites-enabled/*.conf

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet


Virtualhost 1
Code: Select all
<VirtualHost *:81>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #ServerName www.example.com

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
</VirtualHost>


virtual host 2
Code: Select all
<VirtualHost *:80>
   DocumentRoot "/var/www/html2"
   ScriptAlias /local-bin /usr/bin
   AddHandler application/x-httpd-php php .php
   Action application/x-httpd-php /usr/bin/php-cgi7.2

<Directory "/usr/bin">
    Require all granted
</Directory>


    ErrorLog ${APACHE_LOG_DIR}/error80.log
        CustomLog ${APACHE_LOG_DIR}/access80.log combined

php_value session.save_path "/tmp"
php_value session.post_max_size "60M"
php_value session.upload_max_filesize "60M"
</VirtualHost>

http request in the browser

18.23.X.Y:80/mywebsite/info.php

Where I have into the info.php a info_php() ( which display 5.6 )

for php :

Code: Select all
# which php
/usr/bin/php

then

Code: Select all
n# ls -la php
lrwxrwxrwx 1 root root 21 May 17 13:11 php -> /etc/alternatives/php

then

Code: Select all
/etc/alternatives# ls -la php
lrwxrwxrwx 1 root root 15 Jun  5 21:33 php -> /usr/bin/php5.6


/usr/bin# ls php*
php  php-cgi  php-cgi5.6  php-cgi7.2  php5.6  php7.2
smalldragoon
 
Posts: 14
Joined: 29. May 2019 23:47
XAMPP version: 1.0
Operating System: ubuntu

Next

Return to XAMPP for Linux

Who is online

Users browsing this forum: No registered users and 5 guests