dunglas / frankenphp

🧟 The modern PHP app server
https://frankenphp.dev
MIT License
6.71k stars 222 forks source link

Laravel Forge and Franken #446

Closed tpharaoh closed 7 months ago

tpharaoh commented 9 months ago

Would love some feedback before making a PR. I am a Laravel forge user, so I wanted a way to automate. So, I made a worker server, which is just PHP, then opened ports 80,443 in the firewall, and did the following steps. I saved as a recipe so I can make additional servers.. will need some more work for domains, and stuff.

#!/bin/bash

# Download FrankenPHP binary
wget https://github.com/dunglas/frankenphp/releases/download/v1.0.2/frankenphp-linux-x86_64

# Create a directory for FrankenPHP configuration
cp frankenphp-linux-x86_64 frankenphp
chown forge:forge frankenphp

# Create the systemd service file
touch /etc/systemd/system/frankServer.service

# Paste the service file contents
cat << EOF > /etc/systemd/system/frankServer.service
[Unit]
Description=frankServer Caddy service
After=network.target

[Service]
User=forge
WorkingDirectory=/home/forge/
ExecStart=/home/forge/frankenphp run --config /home/forge/Caddyfile
Restart=always

[Install]
WantedBy=multi-user.target
EOF

# Create the Caddyfile for FrankenPHP
touch /home/forge/Caddyfile

# Paste the Caddyfile content
cat << EOF > /home/forge/Caddyfile
{
    frankenphp
    order mercure after encode
    order php_server before file_server
}

# The domain name of your server
example.com {
    # Set the webroot to the public/ dir
    root * public/

    # Enable compression (optional)
    encode zstd gzip
    mercure {
       # Publisher JWT key
       publisher_jwt !ChangeThisMercureHubJWTSecretKey!
       # Subscriber JWT key
       subscriber_jwt !ChangeThisMercureHubJWTSecretKey!
    }

    # Execute PHP files in the current directory and serve assets
    php_server {
       # Required for the public/storage/ dir
       resolve_root_symlink
    }
}
EOF
chown forge:forge Caddyfile
# Grant the `net_bind_service` capability to the FrankenPHP binary
setcap 'cap_net_bind_service=+ep' /home/forge/frankenphp

# Enable the systemd service
systemctl enable frankServer

# Start the systemd service
systemctl start frankServer
francislavoie commented 8 months ago

You might want to review & consider the info in https://caddyserver.com/docs/running#linux-service

dunglas commented 7 months ago

This is now documented in https://laravel.com/docs/10.x/octane#frankenphp.