Skip to content

Commit 49c77bf

Browse files
committed
Added Cloudflared support
1 parent 739e8fc commit 49c77bf

File tree

7 files changed

+190
-52
lines changed

7 files changed

+190
-52
lines changed

Dockerfile

+29-13
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,27 @@ FROM debian:bookworm-slim
22

33
LABEL author="Ym0t" maintainer="[email protected]"
44

5-
ARG PHP_VERSION="8.3"
5+
ARG PHP_VERSION
66

7-
ENV DEBIAN_FRONTEND noninteractive
7+
ENV DEBIAN_FRONTEND=noninteractive
88

9-
RUN apt-get update \
10-
&& apt-get upgrade -y \
11-
&& apt-get install -y git apt-transport-https lsb-release ca-certificates wget nginx \
9+
RUN apt-get update && apt-get install -y \
10+
git \
11+
apt-transport-https \
12+
lsb-release \
13+
ca-certificates \
14+
wget \
15+
nginx \
16+
&& ARCH=$(uname -m) \
17+
&& if [ "$ARCH" = "x86_64" ]; then \
18+
wget -O /tmp/cloudflared.deb https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb; \
19+
elif [ "$ARCH" = "aarch64" ]; then \
20+
wget -O /tmp/cloudflared.deb https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-arm64.deb; \
21+
else \
22+
echo "Unsupported architecture: $ARCH" && exit 1; \
23+
fi \
24+
&& dpkg -i /tmp/cloudflared.deb \
25+
&& rm /tmp/cloudflared.deb \
1226
&& wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg \
1327
&& echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/php.list \
1428
&& apt-get update \
@@ -18,7 +32,7 @@ RUN apt-get update \
1832
php${PHP_VERSION}-cli \
1933
php${PHP_VERSION}-common \
2034
php${PHP_VERSION}-mysqlnd \
21-
php${PHP_VERSION}-PDO \
35+
php${PHP_VERSION}-pdo \
2236
php${PHP_VERSION}-sybase \
2337
php${PHP_VERSION}-psr \
2438
php${PHP_VERSION}-xml \
@@ -47,13 +61,13 @@ RUN apt-get update \
4761
php${PHP_VERSION}-odbc \
4862
php${PHP_VERSION}-pcov \
4963
php${PHP_VERSION}-pgsql \
50-
php${PHP_VERSION}-Phar \
64+
php${PHP_VERSION}-phar \
5165
php${PHP_VERSION}-posix \
5266
php${PHP_VERSION}-ps \
5367
php${PHP_VERSION}-pspell \
5468
php${PHP_VERSION}-readline \
5569
php${PHP_VERSION}-shmop \
56-
php${PHP_VERSION}-SimpleXML \
70+
php${PHP_VERSION}-simplexml \
5771
php${PHP_VERSION}-soap \
5872
php${PHP_VERSION}-sockets \
5973
php${PHP_VERSION}-sqlite3 \
@@ -70,18 +84,20 @@ RUN apt-get update \
7084
php${PHP_VERSION}-inotify \
7185
php${PHP_VERSION}-maxminddb \
7286
php${PHP_VERSION}-protobuf \
73-
php${PHP_VERSION}-OPcache \
74-
&& apt-get purge -y --auto-remove \
87+
php${PHP_VERSION}-opcache \
7588
&& rm -rf /var/lib/apt/lists/*
7689

77-
RUN useradd -m -d /home/container/ -s /bin/bash container
78-
ENV USER=container HOME=/home/container
90+
# Create user and set environment variables
91+
RUN useradd -m -d /home/container/ -s /bin/bash container \
92+
&& echo "USER=container" >> /etc/environment \
93+
&& echo "HOME=/home/container" >> /etc/environment
7994

8095
WORKDIR /home/container
8196

8297
STOPSIGNAL SIGINT
8398

99+
# Copy entrypoint script
84100
COPY ./entrypoint.sh /entrypoint.sh
85101
RUN chmod +x /entrypoint.sh
86102

87-
CMD /entrypoint.sh
103+
CMD ["/entrypoint.sh"]

README.md

+53-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# Pterodactyl Nginx egg
22

33
Nginx web server egg with PHP, optional Wordpress installation and git support.
4-
4+
<br><br>
55
## Features
66

77
#### Supports AMD64 & ARM64
8+
#### Cloudflared Tunnel support
89
#### Git support for your webserver
910
#### You can select the desired PHP version:
1011
- ✅ 8.4
@@ -14,7 +15,7 @@ Nginx web server egg with PHP, optional Wordpress installation and git support.
1415
- ☑️ 8.0 [EOL]
1516

1617
[PHP supported versions](https://www.php.net/supported-versions.php)
17-
18+
<br><br>
1819
## How to install
1920

2021
- **Step 1:** Download the egg (json file `egg-nginx.json`)
@@ -23,12 +24,58 @@ Nginx web server egg with PHP, optional Wordpress installation and git support.
2324
- **Step 4:** Create a new server and select the "Nginx" egg
2425
- **Step 5:** Select the corresponding Docker image with the desired PHP version
2526
- **Step 6:** Fill in the text fields. Whether Wordpress is desired or not. It is important to **enter the selected PHP version in the PHP version field**.
27+
<br><br>
28+
## 🚀 Cloudflared Tunnel Tutorial
29+
30+
With **Cloudflared**, you can create a secure tunnel to your server, making it accessible over the internet **without** complicated port forwarding!
31+
[Cloudflared | Create a remotely-managed tunnel](https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/get-started/create-remote-tunnel/)
32+
33+
### 📌 Requirements
34+
- A [Cloudflare](https://dash.cloudflare.com/) account
35+
- A domain (optional but recommended)
36+
37+
---
38+
39+
- 🔹 **Step 1: Log in to Zero Trust ↗ and go to Networks > Tunnel**
40+
- 🔹 **Step 2: Select Create a tunnel.**
41+
- 🔹 **Step 3: Choose Cloudflared for the connector type and select Next.**
42+
- 🔹 **Step 4: Enter a name for your tunnel.**
43+
- 🔹 **Step 5: Select Save tunnel.**
44+
- 🔹 **Step 6: Save the token. (The token is very long)**
45+
46+
![grafik](https://github.com/user-attachments/assets/0c0430a5-5cb6-45e4-8b26-1805cddde3cc)
47+
48+
49+
---
50+
51+
- 🔹 **Step 7: Activate Cloudflared**
52+
53+
![grafik](https://github.com/user-attachments/assets/726c5dad-7cb6-4537-a215-6aaec59d827a)
54+
55+
56+
---
57+
58+
- 🔹 **Step 8: Add your token.**
59+
60+
![grafik](https://github.com/user-attachments/assets/46b09f6a-30b0-48aa-9980-53697b1fbcf6)
2661

62+
63+
---
64+
65+
- 🔹 **Step 9: Restart your webserver.**
66+
67+
![grafik](https://github.com/user-attachments/assets/84fb9b6c-10cd-4bd3-86ae-e725e7145e8d)
68+
69+
---
70+
71+
✅ You have successfully set up Cloudflared and connected it to your server!
72+
<br><br>
2773
## FAQ
2874

75+
2976
#### In which folder do I upload my files for my site?
3077
The "www" folder is used as a public folder. There you can add your PHP, HTML, CSS, JS and so on files that are required for the public or for the operation of the site.
31-
78+
<br><br>
3279
## How do I use Git support?
3380

3481
#### Instructions for Git support
@@ -83,7 +130,7 @@ Furthermore, if not already done, adjust to your domain:
83130
```bash
84131
server_name www.example.com;
85132
```
86-
133+
<br><br>
87134
## Change PHP version
88135

89136
Changing the PHP version is currently still somewhat cumbersome. A revised version will be available in the future.
@@ -101,7 +148,7 @@ Changing the PHP version is currently still somewhat cumbersome. A revised versi
101148
---
102149

103150
- **Step 3:** Restart your container.
104-
151+
<br><br>
105152
## PHP extensions
106153

107154
PHP extensions of PHP version 8.3:
@@ -111,7 +158,7 @@ Core, date, libxml, openssl, pcre, zlib, filter, hash, json, random, Reflection,
111158
```
112159

113160
Small differences in the extensions between the PHP versions.
114-
161+
<br><br>
115162
## License
116163

117164
[MIT License](https://choosealicense.com/licenses/mit/)

cloudflared.sh

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
3+
# [Tunnel] Check if cloudflared_token.txt exists and has content
4+
if [ -s "/home/container/cloudflared_token.txt" ]; then
5+
# If the file has content, start cloudflared using the content as the token
6+
echo "[Tunnel] Starting cloudflared tunnel with token"
7+
cloudflared tunnel --no-autoupdate run --token "$(cat /home/container/cloudflared_token.txt)" > /dev/null 2>&1 &
8+
9+
# Wait for the tunnel to start
10+
echo "[Tunnel] Waiting for cloudflared tunnel to start..."
11+
12+
# Set max number of attempts
13+
MAX_ATTEMPTS=10
14+
ATTEMPT=0
15+
16+
# Check if cloudflared is running, repeat every 1 second until it is or max attempts reached
17+
while ! pgrep -x "cloudflared" > /dev/null && [ $ATTEMPT -lt $MAX_ATTEMPTS ]; do
18+
ATTEMPT=$((ATTEMPT + 1))
19+
sleep 1
20+
done
21+
22+
# If cloudflared is running
23+
if pgrep -x "cloudflared" > /dev/null; then
24+
# Green success message
25+
echo -e "[Tunnel]\033[0;32m Cloudflared tunnel is running successfully.\033[0m"
26+
else
27+
echo -e "[Tunnel]\033[0;31m Failed to start cloudflared tunnel after $MAX_ATTEMPTS attempts. Exiting...\033[0m"
28+
exit 1
29+
fi
30+
31+
else
32+
echo "[Tunnel]\033[0;31m cloudflared_token.txt is empty or does not exist. Skipping cloudflared startup.\033[0m"
33+
fi

0 commit comments

Comments
 (0)