How to run caddy+php-cgi on windows?

I use this video as instruction Tutorial: Caddy Web Server, PHP 5.6 and Phalcon PHP 2.0.8 - YouTube
On 17:00 author try to run caddy+php-cgi and no result. Then he do something and all work.
How to run caddy+php-cgi on windows?
No video, instructions, etc.

My bat files
1.bat

@ECHO off
ECHO Start caddy
start caddy
pause

2.bat
@ECHO off
ECHO Start FastCGI
set path=c:/php;c:/caddy;%PATH%
c:\php\php-cgi.exe -b 127.0.0.1:9123 -c c:\php\php.ini
pause

i just need to run caddy+php-cgi…

I’d recommend looking at this forum thread for information on how to get Caddy+PHP working on Windows.

Read thread. Try. Strange, but dont work.
I try this using my own path examples/Caddyfile at master · caddyserver/examples · GitHub
mysite.example.com

on startup d:\php7\php-cgi.exe -b 6545 &
fastcgi / 127.0.0.1:6545 php
root D:\Web\Website

And dont work.

Try this (change to my path)

Prompt Go Caddy --

TITLE Caddy Command Prompt
ECHO Shuting down CADDY and subprocesses if running.
taskkill /IM caddy.exe /f /t
ECHO Starting CADDY .
REM PHP FastCGI on windows by default stops after 500 requests due to memory and reliability, but does not restart.
REM Setting PHP_FCGI_MAX_REQUESTS to 0 prevents this behaviour, but you must set a task to restart entire process set periodically
set PHP_FCGI_MAX_REQUESTS=0
:start

C:\caddy\caddy.exe -version
C:\caddy\caddy.exe -quic -log c:\caddy\logs\MAINCADDYRUNLOG.log

REM loop to restart - http://stackoverflow.com/a/34458348/6244
REM Whenever caddy is killed (by the other script, should restart automatically.)
ECHO ReStarting Caddy after shutdown
Echo Restarting Caddy after Shutdown >> c:\logs\filerestarts.txt
date /t >> c:\logs\filerestarts.txt
time /t >> c:\logs\filerestarts.txt
date /t
time /t
goto start

Dont work.
logs
2018/11/02 09:13:11 [INFO] Certificate for mysite. example. com is already being obtained elsewhere and stored; waiting
2018/11/02 09:13:50 [INFO] Certificate for mysite. example. com is already being obtained elsewhere and stored; waiting
So logs ok?
__
I am php web developer and easy configure a web server on Linux. Every day I use Open Server, XAMMP, Denver e.t.c. And caddy… Any official instructions? Manual? Documentation?

Caddy seems to think that another Caddy instance using the same file system is in the middle of certificate acquisition, and is waiting for it to finish.

Unless you’re trying to run Caddy in a fleet configuration, my guess is that you killed the Caddy process in the middle of a HTTP validation attempt.

Using PHP is as simple as using the directive fastcgi / localhost:9000 php (default PHP-FPM listener for most Linux distros, modify as appropriate for other setups). Documentation for Caddy is available at https://caddyserver.com/docs/fastcgi. The Windows-specific example Caddyfile is available at examples/winphp at master · caddyserver/examples · GitHub, and includes having Caddy start the PHP-FPM listener as part of its startup. Documentation for PHP on Windows can be found at PHP: Installation on Windows systems - Manual.

The issue above, in your logs, does not appear to be PHP-specific.

Bad, bad Caddy.

Easy question - what to do? I dont need certificate and such problems. Nobody need.

I believe that Caddy puts down lock files during the challenge-response process that you’ll need to delete.

Before doing that, though, it’s worth changing all the site labels in your Caddyfile to HTTP-only, starting Caddy, and verifying that your sites work fine for when we fix the issue caused by the interrupted certificate requisitioning.

2018/11/02 10:46:00 [INFO][test.example.com] acme: Obtaining bundled SAN certificate
    2018/11/02 10:46:01 [INFO][test.example.com] AuthURL: https://acme-v02.api.letsencrypt.org/acme/authz/0UabhqLy_kHLOqwCWe3mnZ2YoaTLvp1kNA9dQBhZilE
    2018/11/02 10:46:01 [INFO][test.example.com] acme: Could not find solver for: dns-01
    2018/11/02 10:46:01 [INFO][test.example.com] acme: Trying to solve HTTP-01
    2018/11/02 10:46:07 [INFO][test.example.com] acme: Obtaining bundled SAN certificate
    2018/11/02 10:46:08 [INFO][test.example.com] AuthURL: https://acme-v02.api.letsencrypt.org/acme/authz/8oSJsIxCl6z6FHOFYlyhdXaHnlIyQF6bLmdg0Bo0c2g
    2018/11/02 10:46:08 [INFO][test.example.com] acme: Could not find solver for: dns-01
    2018/11/02 10:46:08 [INFO][test.example.com] acme: Trying to solve HTTP-01
    2018/11/02 10:46:14 [INFO][test.example.com] acme: Obtaining bundled SAN certificate
    2018/11/02 10:46:15 [INFO][test.example.com] AuthURL: https://acme-v02.api.letsencrypt.org/acme/authz/3PmU2nN02x5T10B5nwM9VkmeO_uaVwF_l0q2F_2xb0o
    2018/11/02 10:46:15 [INFO][test.example.com] acme: Could not find solver for: tls-alpn-01
    2018/11/02 10:46:15 [INFO][test.example.com] acme: Could not find solver for: dns-01
    2018/11/02 10:46:15 [INFO][test.example.com] acme: Trying to solve HTTP-01
    2018/11/02 10:46:22 [INFO][test.example.com] acme: Obtaining bundled SAN certificate
    2018/11/02 10:46:23 [INFO][test.example.com] AuthURL: https://acme-v02.api.letsencrypt.org/acme/authz/KoWyddzha99aFJHvXy7bqmUwMW8idn6Bc2MeQRIOJ6I
    2018/11/02 10:46:23 [INFO][test.example.com] acme: Could not find solver for: tls-alpn-01
    2018/11/02 10:46:23 [INFO][test.example.com] acme: Trying to solve HTTP-01
2018/11/02 10:48:29 [INFO][test.example.com] acme: Obtaining bundled SAN certificate
2018/11/02 10:48:29 [INFO][test.example.com] acme: Obtaining bundled SAN certificate

What next?

It looks like you’re trying to acquire certificates for the literal FQDN test.example.com.

Unless you actually own that domain, and can rectify the fact that it has no DNS A records by pointing it at your own server, Caddy will never be able to acquire a HTTPS certificate from LetsEncrypt for it.

I suggest disabling HTTPS entirely for that site, because as long as Caddy can’t do what you’ve configured it to do, it will give you the error and exit instead of launching.

http://test.example.com 
on startup C:\caddy\php\php-cgi.exe -b 6545  &
fastcgi / 127.0.0.1:6545 php 
root  C:\caddy\site

Run.
Logs:
2018/11/02 11:08:32 http://test.example.com
2018/11/02 11:08:32 [INFO] Nonblocking Command “C:\caddy\php\php-cgi.exe -b 6545” with ID 85c3c4d1-4285-451b-bf0e-cc49772b2172

Try in browser
http://test.example.com Browser “error” No ip for such site…etc.
Try 127.0.0.1
404 Site 127.0.0.1 is not served on this interface
localhost?
2018/11/02 11:09:22 [INFO] 127.0.0.1 - No such site at :80 (Remote: 127.0.0.1, Referer: )

Browsing to http://test.example.com will naturally fail unless you control the responding DNS server and respond to queries for that domain with the IP address of your own server.

127.0.0.1 and localhost will both fail because your browser signals to the HTTP server what site you’re asking for, but neither match the hostname you specified in the Caddyfile, which is test.example.com.

I don’t know how to do this on a Windows shell off the top of my head, but you could get around it by making a request to your server and manually specifying the hostname. curl -H "Host:test.example.com" http://localhost/ would do this on Linux.

With some magic it worked now. Thank.

I have a very simple setup which I usually take along and use everywhere.

I have a caddy.exe lying in the same file as the bats and subfolders for the PHP versions.

caddy.bat
caddy -conf="caddyconf.txt"

(I just prefer my caddyfile having a txt ending so I dont need to select an editor all the time)

php73.bat
PHP73\php-cgi.exe -b 127.0.0.1:9000

(obviously my caddyfile has fastcgi / 127.0.0.1:9000 php)

you also can turn this into a one bat only setup when you let caddy start PHP with on startup in your caddyfile, although the current setup allows you to swap PHP versions just by closing one php bat and starting another which is a real godsend when trying for multiple PHP versions.

1 Like

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