frankenphp icon indicating copy to clipboard operation
frankenphp copied to clipboard

frankenphp wordpress can't work on wsl

Open sugizo opened this issue 10 months ago • 10 comments

env wsl 2 windows 11 with os tested : debian and ubuntu

execute

sudo apt update
sudo apt install -y curl unzip mariadb-server 
curl https://frankenphp.dev/install.sh | sh
sudo mv frankenphp /usr/local/bin/
sudo service mariadb restart &
sudo mysql -u root --password="password" -e "CREATE USER 'wp_user' IDENTIFIED BY 'password';"
sudo mysql -u root --password="password" -e "GRANT ALL PRIVILEGES ON wp.* TO 'wp_user';"
sudo mysql -u root --password="password" -e "FLUSH PRIVILEGES;"
sudo mysql -u root --password="password" -e "DROP DATABASE IF EXISTS wp;"
sudo mysql -u root --password="password" -e "CREATE DATABASE IF NOT EXISTS wp;"
sudo mysql -u root --password="password" -e "FLUSH PRIVILEGES;"
curl -LOC - https://wordpress.org/latest.zip
unzip latest.zip 
cd wordpress 
sudo frankenphp php-server 

result can't access on browser either http://localhost and https://localhost

thanks and best regards

sugizo avatar Feb 27 '25 06:02 sugizo

When working in WSL, https does not work on localhost since the Windows host system does not accept Caddy's self signed certificate. You can copy the certificate or just use a plain http port:

frankenphp php-server --listen :8144

and then go to http://localhost:8144

When using WSL, I'd generally also recommend setting up a development environment with docker/docker-compose (makes stuff more reproducible once your app gets more complex)

AlliBalliBaba avatar Feb 27 '25 18:02 AlliBalliBaba

execute on wsl 2

$ sudo frankenphp php-server  --listen :8144
2025/02/27 20:49:58.104 WARN    admin   admin endpoint disabled
2025/02/27 20:49:58.105 INFO    tls.cache.maintenance   started background certificate maintenance      {"cache": "0xc0008a0280"}
2025/02/27 20:49:58.165 INFO    frankenphp      FrankenPHP started 🐘   {"php_version": "8.4.4", "num_threads": 16, "max_threads": 16}
2025/02/27 20:49:58.185 WARN    http    HTTP/2 skipped because it requires TLS  {"network": "tcp", "addr": ":8144"}
2025/02/27 20:49:58.185 WARN    http    HTTP/3 skipped because it requires TLS  {"network": "tcp", "addr": ":8144"}
2025/02/27 20:49:58.185 INFO    http.log        server running  {"name": "php", "protocols": ["h1", "h2", "h3"]}
2025/02/27 20:49:58.185 INFO    Caddy serving PHP app on :8144
2025/02/27 20:49:58.202 INFO    tls     storage cleaning happened too recently; skipping for now        {"storage": "FileStorage:/root/.local/share/caddy", "instance": "a0b1b8ea-d74c-4ced-af06-a21678e4c94f", "try_again": "2025/02/28 20:49:58.202", "try_again_in": 86399.999999249}
2025/02/27 20:49:58.202 INFO    tls     finished cleaning storage units

result on browser http://localhost:8144

This page isn’t working
localhost sent an invalid response.
ERR_INVALID_REDIRECT

any solution for this ?

thanks and best regards

sugizo avatar Feb 27 '25 20:02 sugizo

What do you see in the network tab of your browser? Where does it redirect to?

AlliBalliBaba avatar Feb 27 '25 23:02 AlliBalliBaba

Image

sugizo avatar Feb 28 '25 00:02 sugizo

A 404 response means that the server works 🎉. When using php-server, you have to run the command in your public directory (where the index.php is)

AlliBalliBaba avatar Feb 28 '25 13:02 AlliBalliBaba

test with docker in wsl (debian os) is not work

sudo apt update
sudo apt install -y curl docker.io
cd
mkdir -p ~/frankenphp
sudo docker run -v ~/frankenphp:/app/public     -p 80:80 -p 443:443 -p 443:443/udp     dunglas/frankenphp
sudo docker images
sudo docker ps -a

result in browser

This localhost page can’t be found
No webpage was found for the web address: https://localhost/
HTTP ERROR 404

result in shell

CONTAINER ID   IMAGE                COMMAND                  CREATED       STATUS                       PORTS                                                                                                                       NAMES
0163d9057990   dunglas/frankenphp   "docker-php-entrypoi…"   2 hours ago   Exited (255) 2 minutes ago   0.0.0.0:80->80/tcp, :::80->80/tcp, 0.0.0.0:443->443/tcp, :::443->443/tcp, 0.0.0.0:443->443/udp, :::443->443/udp, 2019/tcp   sweet_khorana
debian@LAPTOP-AEUH1H9T:~$ sudo docker rm -f sweet_khorana
sweet_khorana
debian@LAPTOP-AEUH1H9T:~$ sudo docker run -v ~/frankenphp:/app/public     -p 80:80 -p 443:443 -p 443:443/udp     dunglas/frankenphp
{"level":"info","ts":1743526096.8166132,"msg":"using config from file","file":"/etc/caddy/Caddyfile"}
{"level":"info","ts":1743526096.8206897,"msg":"adapted config to JSON","adapter":"caddyfile"}
{"level":"warn","ts":1743526096.8207688,"msg":"Caddyfile input is not formatted; run 'caddy fmt --overwrite' to fix inconsistencies","adapter":"caddyfile","file":"/etc/caddy/Caddyfile","line":10}
{"level":"info","ts":1743526096.8253474,"logger":"admin","msg":"admin endpoint started","address":"localhost:2019","enforce_origin":false,"origins":["//localhost:2019","//[::1]:2019","//127.0.0.1:2019"]}
{"level":"info","ts":1743526096.827044,"logger":"http.auto_https","msg":"server is listening only on the HTTPS port but has no TLS connection policies; adding one to enable TLS","server_name":"srv0","https_port":443}
{"level":"info","ts":1743526096.8271186,"logger":"http.auto_https","msg":"enabling automatic HTTP->HTTPS redirects","server_name":"srv0"}
{"level":"info","ts":1743526096.8285203,"logger":"tls.cache.maintenance","msg":"started background certificate maintenance","cache":"0xc000634880"}
{"level":"warn","ts":1743526096.8520987,"logger":"pki.ca.local","msg":"installing root certificate (you might be prompted for password)","path":"storage:pki/authorities/local/root.crt"}
{"level":"info","ts":1743526096.857694,"msg":"warning: \"certutil\" is not available, install \"certutil\" with \"apt install libnss3-tools\" or \"yum install nss-tools\" and try again"}
{"level":"info","ts":1743526096.8577502,"msg":"define JAVA_HOME environment variable to use the Java trust"}
{"level":"info","ts":1743526096.8581011,"logger":"tls","msg":"cleaning storage unit","storage":"FileStorage:/data/caddy"}
{"level":"info","ts":1743526096.8623486,"logger":"tls","msg":"finished cleaning storage units"}
{"level":"info","ts":1743526098.0858386,"msg":"certificate installed properly in linux trusts"}
{"level":"info","ts":1743526098.0875177,"logger":"http","msg":"enabling HTTP/3 listener","addr":":443"}
{"level":"info","ts":1743526098.0880716,"msg":"failed to sufficiently increase receive buffer size (was: 208 kiB, wanted: 7168 kiB, got: 416 kiB). See https://github.com/quic-go/quic-go/wiki/UDP-Buffer-Sizes for details."}
{"level":"info","ts":1743526098.091653,"logger":"http.log","msg":"server running","name":"srv0","protocols":["h1","h2","h3"]}
{"level":"warn","ts":1743526098.0918357,"logger":"http","msg":"HTTP/2 skipped because it requires TLS","network":"tcp","addr":":80"}
{"level":"warn","ts":1743526098.0918486,"logger":"http","msg":"HTTP/3 skipped because it requires TLS","network":"tcp","addr":":80"}
{"level":"info","ts":1743526098.0918524,"logger":"http.log","msg":"server running","name":"remaining_auto_https_redirects","protocols":["h1","h2","h3"]}
{"level":"info","ts":1743526098.091858,"logger":"http","msg":"enabling automatic TLS certificate management","domains":["localhost"]}
{"level":"info","ts":1743526098.0962486,"logger":"tls.obtain","msg":"acquiring lock","identifier":"localhost"}
{"level":"info","ts":1743526098.1009455,"logger":"tls.obtain","msg":"lock acquired","identifier":"localhost"}
{"level":"info","ts":1743526098.1012044,"logger":"tls.obtain","msg":"obtaining certificate","identifier":"localhost"}
{"level":"info","ts":1743526098.1160393,"logger":"tls.obtain","msg":"certificate obtained successfully","identifier":"localhost","issuer":"local"}
{"level":"info","ts":1743526098.116229,"logger":"tls.obtain","msg":"releasing lock","identifier":"localhost"}
{"level":"info","ts":1743526098.2222505,"logger":"frankenphp","msg":"FrankenPHP started 🐘","php_version":"8.4.5","num_threads":16,"max_threads":16}
{"level":"info","ts":1743526098.2249508,"msg":"autosaved config (load with --resume flag)","file":"/config/caddy/autosave.json"}
{"level":"info","ts":1743526098.2250123,"msg":"serving initial configuration"}

best regards

sugizo avatar Apr 01 '25 16:04 sugizo

What is the content of ~/frankenphp ? Is there an index.php ?

AlliBalliBaba avatar Apr 01 '25 18:04 AlliBalliBaba

A 404 means the server responded that it could not find what you were requesting. Make sure you aren't running another service on your machine listening to the same port(s), or that you have files to serve.

withinboredom avatar Apr 01 '25 18:04 withinboredom

wsl only work with docker

sudo apt update
sudo apt install -y curl docker.io
cd
mkdir -p ~/frankenphp
echo "<?php phpinfo(); ?>" > ~/frankenphp/phpinfo.php
sudo docker run -v ~/frankenphp:/app/public     -p 80:80 -p 443:443 -p 443:443/udp     dunglas/frankenphp
sudo docker images
sudo docker ps -a

on browser access http://localhost/phpinfo.php

while with terminal execute is not work (still problem like on first posted)

sudo apt update
sudo apt install -y curl unzip mariadb-server 
curl https://frankenphp.dev/install.sh | sh
sudo mv frankenphp /usr/local/bin/
sudo service mariadb restart &
sudo mysql -u root --password="password" -e "CREATE USER 'wp_user' IDENTIFIED BY 'password';"
sudo mysql -u root --password="password" -e "GRANT ALL PRIVILEGES ON wp.* TO 'wp_user';"
sudo mysql -u root --password="password" -e "FLUSH PRIVILEGES;"
sudo mysql -u root --password="password" -e "DROP DATABASE IF EXISTS wp;"
sudo mysql -u root --password="password" -e "CREATE DATABASE IF NOT EXISTS wp;"
sudo mysql -u root --password="password" -e "FLUSH PRIVILEGES;"
curl -LOC - https://wordpress.org/latest.zip
unzip latest.zip 
cd wordpress 
sudo frankenphp php-server --listen :8144

result on terminal

~/wordpress$ sudo frankenphp php-server --listen :8144
2025/04/01 18:58:07.342 WARN    admin   admin endpoint disabled
2025/04/01 18:58:07.344 INFO    tls.cache.maintenance   started background certificate maintenance      {"cache": "0xc0005da880"}
2025/04/01 18:58:07.472 INFO    frankenphp      FrankenPHP started 🐘   {"php_version": "8.4.5", "num_threads": 16, "max_threads": 16}
2025/04/01 18:58:07.497 INFO    tls     cleaning storage unit   {"storage": "FileStorage:/root/.local/share/caddy"}
2025/04/01 18:58:07.502 INFO    tls     finished cleaning storage units
2025/04/01 18:58:07.524 WARN    http    HTTP/2 skipped because it requires TLS  {"network": "tcp", "addr": ":8144"}
2025/04/01 18:58:07.524 WARN    http    HTTP/3 skipped because it requires TLS  {"network": "tcp", "addr": ":8144"}
2025/04/01 18:58:07.524 INFO    http.log        server running  {"name": "php", "protocols": ["h1", "h2", "h3"]}
2025/04/01 18:58:07.524 INFO    Caddy serving PHP app on :8144

result on browser http://localhost:8144

This page isn’t working
localhost sent an invalid response.
ERR_INVALID_REDIRECT

Image

result on browser http://localhost:8144/wordpress/

This page isn’t working
localhost sent an invalid response.
ERR_INVALID_REDIRECT

Image

any idea to work on wsl without docker ?

thanks and best regards

sugizo avatar Apr 01 '25 19:04 sugizo

tried to simplified the first posted, is work, but again the first posted (frankenphp, wordpress) reported is still not worked

sudo apt update
sudo apt install -y curl 
curl https://frankenphp.dev/install.sh | sh
sudo mv frankenphp /usr/local/bin/
cd
echo "<?php phpinfo(); ?>" > ~/phpinfo.php
frankenphp php-server --listen :8144

it's work when access the browser http://localhost:8144/phpinfo.php

best regards

sugizo avatar Apr 02 '25 13:04 sugizo