Multiple PHP Versions

I am running Caddy with PHP, which defaults to version 7.0.7 as almost all my sites use it. However, for a particular site I need to run version 5.6. How can I run a different version of PHP with Caddy, specifically from a different folder?

I have PHP 7.0.7 installed in C:\Caddy\php and 5.6 in C:\Caddy\php-5.6.23, and my basic Caddy setup is this:

localhost:80 {
	log logs/access.log
	errors logs/error.log
	gzip
	startup php-cgi -b 127.0.0.1:9000 &
	fastcgi / 127.0.0.1:9000 php {
		index index.php
	}
}

Can I somehow altar the path to where FastCGI starts up php-cgi for the particular server? I tried this:

56.dev:80 {
	log logs/access.log
	errors logs/error.log
	gzip
	startup php-cgi -b 127.0.0.1:9000 &
	fastcgi /php-5.6.23 127.0.0.1:9000 php {
		index index.php
	}
}

But I take it that is an incorrect use of the FastCGI path. I should note that I am running Caddy v0.8.3.

You will need to have two php-cgi.exe instances running configured to point to the two php versions and listening on different ports.

Then create two fastcgi entries in your Caddyfile pointing to either ports.

1 Like

But I can run these two instances as spawned by Caddy, as I do currently? Each of the sites in my Caddyfile use a configuration like above, and each spawns an instance of CGI /FastCGI. The ports I get, but how would I set which port leads to which instance?

Also, should I not be spawning a PHP-instance for each site? I guess that it might be superfluous.

No, a single FastCGI (php-cgi) instance can handle multiple php sites.

I think each php version should have its own php-cgi. Is that the case for you ?

Ahh, then I can remove several startups of php-cgi from the Caddyfile. Each PHP version is released with its own php-cgi.exe, but I’m unsure of how to make each site in the Caddyfile use a specific one rather than the “general one” which is started from environment paths.

The PHP 7.0.7 php-cgi is registered in the environment paths, and thus startup php-cgi always spawns this available for all sites regardless of host name or port.

You can use absolute paths to the php-cgi executables. And you’ll need to locate the .conf file to change the port to listen on.

1 Like

I think I figured it out, I was confusing the startup-directive with the fastcgi-directive. It should be:

localhost:80 {
	log logs/access.log
	errors logs/error.log
	gzip
	startup php-cgi -b 127.0.0.1:9000 &
	fastcgi / 127.0.0.1:9000 php {
		index index.php
	}
}

56.dev:81 {
	log logs/access.log
	errors logs/error.log
	gzip
	startup C:/Caddy/php-5.6.23/php-cgi.exe -b 127.0.0.1:9001 &
	fastcgi / 127.0.0.1:9001 php {
		index index.php
	}
}

This spawns a php-cgi instance on port 80 for PHP 7.0.7 (from path) and on port 81 for PHP 5.6.23.

3 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.