Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,29 @@ jobs:
steps:
- uses: actions/checkout@v5

- name: Validate the egg
- name: Validate the eggs
run: |
jq -e '.meta.version == "PTDL_v2"' egg-nginx-webhost.json >/dev/null
# tr: the panel saves the install script with Windows line endings
version=$(jq -r '.scripts.installation.script' egg-nginx-webhost.json \
| tr -d '\r' \
| sed -n 's/^EGG_VERSION="\([^"]*\)"$/\1/p' | head -n 1)
if [ -z "${version}" ]; then
echo "::error::EGG_VERSION not found in the egg's install script"
for egg in egg-nginx-webhost.json egg-nginx-webhost-git.json; do
jq -e '.meta.version == "PTDL_v2"' "${egg}" >/dev/null
# tr: the panel saves the install script with Windows line endings
version=$(jq -r '.scripts.installation.script' "${egg}" \
| tr -d '\r' \
| sed -n 's/^EGG_VERSION="\([^"]*\)"$/\1/p' | head -n 1)
if [ -z "${version}" ]; then
echo "::error::EGG_VERSION not found in ${egg}'s install script"
exit 1
fi
echo "${egg}: version ${version}"
done

# The two eggs only differ in name, description, update URL and the WordPress/Git
# variables; everything else has to stay the same in both
shared='{scripts, docker_images, startup, config, features, file_denylist,
variables: [.variables[] | select(.env_variable | test("^(WORDPRESS|GIT_ADDRESS|BRANCH|USERNAME|ACCESS_TOKEN|AUTO_UPDATE)$") | not)]}'
if ! diff <(jq -S "${shared}" egg-nginx-webhost.json) <(jq -S "${shared}" egg-nginx-webhost-git.json); then
echo "::error::egg-nginx-webhost.json and egg-nginx-webhost-git.json differ in a part they should share (shown above)"
exit 1
fi
echo "Egg version ${version}"

- uses: docker/setup-buildx-action@v3

Expand Down
71 changes: 47 additions & 24 deletions .github/workflows/release-egg.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
name: Release egg

# Publishes egg-nginx-webhost.json as a GitHub release named after the EGG_VERSION in its
# install script (e.g. v1.0.0). Bump EGG_VERSION to make a new release.
# The egg is attached twice: egg-nginx-webhost-<version>.json to download, and
# egg-nginx-webhost.json, which servers' update checks fetch from the latest release.
# Publishes the eggs as a GitHub release named after the EGG_VERSION in their install script
# (e.g. v1.0.0). Bump EGG_VERSION to make a new release. Attached:
# egg-nginx-webhost-<version>.json Nginx Webhost, to download
# egg-nginx-webhost-git-<version>.json Nginx Webhost (Git), to download
# egg-nginx-webhost.json Nginx Webhost again, servers' update checks fetch it
# from the latest release by this name
on:
push:
branches: [main]
paths:
- "egg-nginx-webhost.json"
- "egg-nginx-webhost-git.json"
workflow_dispatch:
inputs:
republish:
description: "Replace the egg in this version's existing release without bumping EGG_VERSION"
description: "Replace the eggs in this version's existing release without bumping EGG_VERSION"
type: boolean
default: false

Expand Down Expand Up @@ -49,48 +52,68 @@ jobs:
TAG: v${{ steps.egg.outputs.version }}
REPUBLISH: ${{ inputs.republish }}
run: |
name="egg-nginx-webhost-${TAG#v}.json"
versioned="${RUNNER_TEMP}/${name}"
cp egg-nginx-webhost.json "${versioned}"
assets="${RUNNER_TEMP}/assets"
mkdir -p "${assets}"
cp egg-nginx-webhost.json "${assets}/egg-nginx-webhost-${TAG#v}.json"
cp egg-nginx-webhost-git.json "${assets}/egg-nginx-webhost-git-${TAG#v}.json"
cp egg-nginx-webhost.json "${assets}/egg-nginx-webhost.json"

if [ "$(gh release view "${TAG}" --json isDraft --jq .isDraft 2>/dev/null)" = "false" ]; then
gh release download "${TAG}" --pattern egg-nginx-webhost.json --output "${RUNNER_TEMP}/released.json"
if cmp -s egg-nginx-webhost.json "${RUNNER_TEMP}/released.json"; then
# Releases made before the versioned file existed get it added
if gh release view "${TAG}" --json assets --jq '.assets[].name' | grep -qxF "${name}"; then
echo "Release ${TAG} already exists with this egg, nothing to do."
released=$(gh release view "${TAG}" --json assets --jq '.assets[].name')
changed=""
missing=""
for file in "${assets}"/*.json; do
name=$(basename "${file}")
if ! printf '%s\n' "${released}" | grep -qxF "${name}"; then
missing="${missing} ${file}"
continue
fi
rm -f "${RUNNER_TEMP}/released.json"
gh release download "${TAG}" --pattern "${name}" --output "${RUNNER_TEMP}/released.json"
cmp -s "${file}" "${RUNNER_TEMP}/released.json" || changed="${changed} ${name}"
done

if [ -z "${changed}" ]; then
# Releases made before a file existed get it added
if [ -n "${missing}" ]; then
gh release upload "${TAG}" ${missing}
echo "Added${missing//${assets}\//} to release ${TAG}."
else
gh release upload "${TAG}" "${versioned}"
echo "Added ${name} to release ${TAG}."
echo "Release ${TAG} already exists with these eggs, nothing to do."
fi
exit 0
fi
if [ "${REPUBLISH}" = "true" ]; then
# Run by hand with "republish": swap the egg in the existing release. The tag
# Run by hand with "republish": swap the eggs in the existing release. The tag
# stays where it is, release tags are protected and can't be moved
gh release upload "${TAG}" egg-nginx-webhost.json "${versioned}" --clobber
echo "Replaced the egg in release ${TAG}."
gh release upload "${TAG}" "${assets}"/*.json --clobber
echo "Replaced the eggs in release ${TAG}."
exit 0
fi
echo "::error::egg-nginx-webhost.json changed but EGG_VERSION is still ${TAG#v}. Bump EGG_VERSION, or run this workflow by hand with \"republish\" ticked to replace the egg in ${TAG}."
echo "::error::${changed# } changed but EGG_VERSION is still ${TAG#v}. Bump EGG_VERSION, or run this workflow by hand with \"republish\" ticked to replace the eggs in ${TAG}."
exit 1
fi
cat > notes.md <<'EOF'
## Install

1. Download `EGG_FILE` below.
1. Download the egg you want below:
- `EGG_FILE`: **Nginx Webhost**, you upload the site yourself or install WordPress
- `GIT_EGG_FILE`: **Nginx Webhost (Git)**, the site is cloned from a Git repo
2. In the panel: **Admin → Nests → Import Egg**, upload it.
3. Create a server with the egg, pick a PHP version (Docker Image), and visit `http://ip:port`.

## Update from an older version

**Admin → Nests → (nest) → Nginx Webhost → Update Egg** with this file (not Import Egg, that makes a second copy), then **Reinstall** your servers.
**Admin → Nests → (nest) → the egg → Update Egg** with its file (not Import Egg, that makes a second copy), then **Reinstall** your servers.
Reinstalling replaces `nginx/`, `php-fpm/` and `start.sh` on each server (`webroot/` is kept), so back up any edits to them first.

`egg-nginx-webhost.json` is the same file, kept for the servers' update check.
`egg-nginx-webhost.json` is the same file as `EGG_FILE`, kept for the servers' update check.
EOF
sed -i "s/EGG_FILE/${name}/" notes.md
gh release create "${TAG}" "${versioned}" egg-nginx-webhost.json \
sed -i "s/GIT_EGG_FILE/egg-nginx-webhost-git-${TAG#v}.json/; s/EGG_FILE/egg-nginx-webhost-${TAG#v}.json/g" notes.md
gh release create "${TAG}" \
"${assets}/egg-nginx-webhost-${TAG#v}.json" \
"${assets}/egg-nginx-webhost-git-${TAG#v}.json" \
"${assets}/egg-nginx-webhost.json" \
--title "${TAG}" \
--notes-file notes.md \
--target "${GITHUB_SHA}"
102 changes: 58 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,21 @@
[![Build images](https://github.com/Rustix-Development/pterodactyl-nginx-egg/actions/workflows/build-images.yml/badge.svg)](https://github.com/Rustix-Development/pterodactyl-nginx-egg/actions/workflows/build-images.yml)
[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)

A [Pterodactyl](https://pterodactyl.io) egg for hosting PHP and static websites with
**nginx 1.30** and **PHP 8.3 / 8.4 / 8.5** on PHP-FPM.

- **Upload or deploy from Git**: upload files into `webroot/`, or clone a Git repo
(public or private) and optionally pull it on every start
- **WordPress**: turn on *Wordpress* when creating the server and it's downloaded for you
- **Composer**: list packages in *Composer modules* and they're installed into `webroot/`
- **Site variables**: SMTP / mail, site name and URL, Discord and Google OAuth and a database
connection string are passed to PHP, so your code reads them with `getenv()` instead of
hardcoding them
[Pterodactyl](https://pterodactyl.io) eggs for hosting PHP and static websites with
**nginx 1.30** and **PHP 8.3 / 8.4 / 8.5** on PHP-FPM. There are two, pick one per server:

| Egg | File | For |
|-----|------|-----|
| **Nginx Webhost** | `egg-nginx-webhost-<version>.json` | You upload the site yourself (SFTP or the file manager), or install WordPress |
| **Nginx Webhost (Git)** | `egg-nginx-webhost-git-<version>.json` | The site is cloned from a Git repo (public or private), optionally pulled on every start |

Both use the same image, config files and startup script.

- **WordPress** (Nginx Webhost): turn on *Setup · WordPress* when creating the server and it's downloaded for you
- **Composer**: list packages in *Setup · Composer Modules* and they're installed into `webroot/`
- **Site variables**: site name and URL, Google Analytics, SMTP / mail, Cloudflare Turnstile,
Discord and Google OAuth and a database connection string are passed to PHP, so your code
reads them with `getenv()` instead of hardcoding them
- **Update check**: the console says when the egg or the Docker image has an update
- **Maintained images**: Debian based with PHP from packages.sury.org, `amd64` and `arm64`, rebuilt weekly for nginx and PHP
security fixes
Expand All @@ -27,33 +32,39 @@ A [Pterodactyl](https://pterodactyl.io) egg for hosting PHP and static websites

## Install

1. Download `egg-nginx-webhost-<version>.json` from the
[latest release](https://github.com/Rustix-Development/pterodactyl-nginx-egg/releases/latest).
2. In the panel: **Admin → Nests → Import Egg**, upload it into the nest you want.
1. Download `egg-nginx-webhost-<version>.json`, `egg-nginx-webhost-git-<version>.json` or
both from the [latest release](https://github.com/Rustix-Development/pterodactyl-nginx-egg/releases/latest).
2. In the panel: **Admin → Nests → Import Egg**, upload each one into the nest you want.
3. Create a server with the egg and pick a PHP version under **Docker Image**.
4. Once it has installed, start it and visit `http://<node-ip>:<port>`. You should see the
"Web server is running" page; replace it by uploading your site into `webroot/`.
"Web server is running" page (or your site, with the Git egg); with Nginx Webhost, replace
it by uploading your site into `webroot/`.

The server listens on its primary allocation. To serve a domain over HTTPS, put a reverse
proxy (nginx, Caddy, Cloudflare, ...) in front of that port.

## Variables

All variables can be changed later under the server's **Startup** tab. The site variables
only reach your PHP code; the egg itself doesn't use them, so leave the ones you don't need
blank.
All variables can be changed later under the server's **Startup** tab. Each name starts
with its section (*Site*, *Git*, *Setup*, *Mail*, *Login*, *Security*, *Analytics*,
*Database*, *Egg*) so they stay grouped in the panel. The site variables only reach your PHP code;
the egg itself doesn't use them, so leave the ones you don't need blank.

### Site and setup

| Variable | Default | What it does |
|----------|---------|--------------|
| Site · Root Folder (`ROOT_FOLDER`) | | Folder in `webroot/` to serve at your domain's root, see [below](#serving-a-folder-at-the-root). Blank serves `webroot/` as is |
| Site · 404 Page (`ERROR_404_PAGE`) | | Page to show for missing pages, see [below](#custom-404-page). Blank keeps sending them to `index.php` |
| Setup · WordPress (`WORDPRESS`) | `0` | Nginx Webhost only. Install WordPress into an empty `webroot/`. Finish setup at `/wp-admin` |
| Setup · Composer Modules (`COMPOSER_MODULES`) | | Space separated packages, e.g. `phpmailer/phpmailer vlucas/phpdotenv`. Pin a version with `vendor/package:^6.0` |

### Website
### Egg

| Variable | Default | What it does |
|----------|---------|--------------|
| Wordpress (`WORDPRESS`) | `0` | Install WordPress into an empty `webroot/`. Finish setup at `/wp-admin` |
| Composer modules (`COMPOSER_MODULES`) | | Space separated packages, e.g. `phpmailer/phpmailer vlucas/phpdotenv`. Pin a version with `vendor/package:^6.0` |
| Root Folder (`ROOT_FOLDER`) | | Folder in `webroot/` to serve at your domain's root, see [below](#serving-a-folder-at-the-root). Blank serves `webroot/` as is |
| 404 Page (`ERROR_404_PAGE`) | | Page to show for missing pages, see [below](#custom-404-page). Blank keeps sending them to `index.php` |
| User Uploaded Files (`USER_UPLOAD`) | `0` | Skip the Git setup, you upload the files yourself |
| Update Check (`UPDATE_CHECK`) | `1` | Say in the console when the egg or the Docker image has an update |
| Startup Command (`STARTUP_CMD`) | `./start.sh` | Leave as is unless you know you need to change it |
| Egg · Update Check (`UPDATE_CHECK`) | `1` | Say in the console when the egg or the Docker image has an update |
| Egg · Startup Command (`STARTUP_CMD`) | `./start.sh` | Leave as is unless you know you need to change it |

Each Composer package is added once and then kept at that version. On every start
`composer install` keeps `vendor/` in line with `composer.lock`.
Expand Down Expand Up @@ -103,31 +114,33 @@ path is from your site's root: `webroot/`, or the **Root Folder** if you set one
- If the page doesn't exist, visitors get nginx's plain 404 and the console says so.
- Needs a **Reinstall** first on servers installed before the egg had this option.

### Git
### Git (Nginx Webhost (Git) only)

| Variable | Default | What it does |
|----------|---------|--------------|
| Git Repo Address (`GIT_ADDRESS`) | | Repo to clone your site from, e.g. `https://github.com/you/your-site` |
| Git Branch (`BRANCH`) | | Branch to clone; blank uses the repo's default branch |
| Auto Update (`AUTO_UPDATE`) | `0` | `git pull` on every start |
| Git Username (`USERNAME`) | | For private repos |
| Git Access Token (`ACCESS_TOKEN`) | | For private repos; use a personal access token, not your password |
| Git · Repo Address (`GIT_ADDRESS`) | | Repo to clone your site from, e.g. `https://github.com/you/your-site` |
| Git · Branch (`BRANCH`) | | Branch to clone; blank uses the repo's default branch |
| Git · Username (`USERNAME`) | | For private repos |
| Git · Access Token (`ACCESS_TOKEN`) | | For private repos; use a personal access token, not your password |
| Git · Auto Update (`AUTO_UPDATE`) | `0` | `git pull` on every start |

The repo is only cloned into an empty `webroot/`. If `webroot/` is already a clone of the
same repo, a reinstall pulls it; any other files are left alone.

### Site variables (read with `getenv()`)

| Variable | Default | Typical use |
|----------|---------|-------------|
| `SMTP_HOST`, `SMTP_PORT` | `smtp.resend.com`, `465` | Mail server. For Gmail / Google Workspace use `smtp.gmail.com` and `587` |
| `SMTP_USERNAME`, `SMTP_PASSWORD` | `resend`, | Mail login. For Resend, the password is your API key; for Gmail, an App Password |
| `MAIL_FROM_EMAIL`, `MAIL_FROM_NAME` | | Sender address and name |
| `MAIL_TO_EMAIL` | | Where contact form mail goes |
| `SITE_NAME`, `SITE_URL` | `Website`, | Your site's name and public URL (no trailing slash) |
| `DISCORD_CLIENT_ID`, `DISCORD_CLIENT_SECRET` | | Discord OAuth2 login |
| `GOOGLE_CLIENT_ID`, `GOOGLE_CLIENT_SECRET` | | Google OAuth2 login |
| `DB_CONNECTION_STRING` | | Database URL, e.g. `mysql://user:pass@host:3306/db` |
| Section | Variables | Default | Typical use |
|---------|-----------|---------|-------------|
| Site | `SITE_NAME`, `SITE_URL` | `Website`, | Your site's name and public URL (no trailing slash) |
| Mail | `SMTP_HOST`, `SMTP_PORT` | `smtp.resend.com`, `465` | Mail server. For Gmail / Google Workspace use `smtp.gmail.com` and `587` |
| Mail | `SMTP_USERNAME`, `SMTP_PASSWORD` | `resend`, | Mail login. For Resend, the password is your API key; for Gmail, an App Password |
| Mail | `MAIL_FROM_EMAIL`, `MAIL_FROM_NAME` | | Sender address and name |
| Mail | `MAIL_TO_EMAIL` | | Where contact form mail goes |
| Login | `DISCORD_CLIENT_ID`, `DISCORD_CLIENT_SECRET` | | Discord OAuth2 login |
| Login | `GOOGLE_CLIENT_ID`, `GOOGLE_CLIENT_SECRET` | | Google OAuth2 login |
| Security | `TURNSTILE_SITE_KEY`, `TURNSTILE_SECRET_KEY` | | Cloudflare Turnstile bot check on forms |
| Analytics | `GA_MEASUREMENT_ID` | | Google Analytics 4 Measurement ID, e.g. `G-XXXXXXXXXX` |
| Database | `DB_CONNECTION_STRING` | | Database URL, e.g. `mysql://user:pass@host:3306/db` |

```php
<?php
Expand Down Expand Up @@ -169,9 +182,10 @@ only into an empty `webroot/`. Your other website files are kept.

Every time a server starts it checks for updates in the background and says in the console if:

- **the egg has an update**: download `egg-nginx-webhost-<version>.json` from the
- **the egg has an update**: download `egg-nginx-webhost-<version>.json` (or
`egg-nginx-webhost-git-<version>.json` for the Git egg) from the
[latest release](https://github.com/Rustix-Development/pterodactyl-nginx-egg/releases/latest), then
**Admin → Nests → (nest) → Nginx Webhost → Update Egg** with it (not *Import Egg*, that
**Admin → Nests → (nest) → the egg → Update Egg** with it (not *Import Egg*, that
makes a second copy), and **Reinstall** the server.
- **the Docker image has an update**: restart the server, the panel downloads the latest
image on every start. If it keeps showing, run
Expand All @@ -185,7 +199,7 @@ Every time a server starts it checks for updates in the background and says in t
egg's images: **Admin → Servers → server → Startup → Docker Image**, pick one of the
egg's images.

Turn it off per server with the *Update Check* variable.
Turn it off per server with the *Egg · Update Check* variable.

## Troubleshooting

Expand Down
Loading
Loading