nix-env -iA nixpkgs.php
Make a new folder called php
in your home directory, and make a fpm.conf file. PHP FPM (FastCGI Process Manager) is what basically runs the PHP code. Replace USERNAME
with your username.
[global]
pid = /home/USERNAME/php/fpm.pid
error_log = /home/USERNAME/php/fpm-error.log
[global]
daemonize = yes
[www]
listen = /home/USERNAME/php/fpm.sock
user = USERNAME
group = USERNAME
pm = dynamic
pm.max_children = 5
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.status_path = /phpstatus
ping.path = /phpping
ping.response = pong
Add the php_fastcgi directive to your Caddyfile. This tells caddy to send all requests for PHP files to FastCGI. Replace USERNAME
with your username.
http://USERNAME.hackclub.app {
...
php_fastcgi unix//home/USERNAME/php/fpm.sock
...
}
Using systemd, we can use nano ~/.config/systemd/user/php-fpm.service
to edit it. Insert this somewhere in the text editor an save it.
[Unit]
Description=PHP FastCGI Service
After=network.target
[Service]
Type=simple
ExecStart=/home/david/.nix-profile/bin/php-fpm -y /home/david/php/fpm.conf -g /home/david/php/fpm.pid -n -F
[Install]
WantedBy=default.target
Just run the following and you should be all set, even across reboots!
php-fpm -y /home/USERNAME/php/fpm.conf -g /home/USERNAME/php/fpm.pid -n