-
-
Notifications
You must be signed in to change notification settings - Fork 251
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improve Dockerfile and add some docs (#15)
- Loading branch information
Showing
15 changed files
with
1,139 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Dockerfile | ||
Dockerfile.dev |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,3 +57,15 @@ Run the test app: | |
|
||
cd ../../testdata/ | ||
../internal/testserver/testserver | ||
|
||
## Misc Dev Resources | ||
|
||
* [PHP embedding in uWSGI](https://github.com/unbit/uwsgi/blob/master/plugins/php/php_plugin.c) | ||
* [PHP embedding in NGINX Unit](https://github.com/nginx/unit/blob/master/src/nxt_php_sapi.c) | ||
* [PHP embedding in Go (go-php)](https://github.com/deuill/go-php) | ||
* [PHP embedding in Go (GoEmPHP)](https://github.com/mikespook/goemphp) | ||
* [PHP embedding in C++](https://gist.github.com/paresy/3cbd4c6a469511ac7479aa0e7c42fea7) | ||
* [Extending and Embedding PHP by Sara Golemon](https://books.google.fr/books?id=zMbGvK17_tYC&pg=PA254&lpg=PA254#v=onepage&q&f=false) | ||
* [What the heck is TSRMLS_CC, anyway?](http://blog.golemon.com/2006/06/what-heck-is-tsrmlscc-anyway.html) | ||
* [PHP embedding on Mac](https://gist.github.com/jonnywang/61427ffc0e8dde74fff40f479d147db4) | ||
* [SDL bindings](https://pkg.go.dev/github.com/veandco/[email protected]/sdl#Main) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
FROM golang | ||
|
||
ARG LIBICONV_VERSION=1.17 | ||
ENV PHPIZE_DEPS \ | ||
autoconf \ | ||
dpkg-dev \ | ||
file \ | ||
g++ \ | ||
gcc \ | ||
libc-dev \ | ||
make \ | ||
pkg-config \ | ||
re2c | ||
|
||
RUN apt-get update && \ | ||
apt-get -y --no-install-recommends install \ | ||
$PHPIZE_DEPS \ | ||
libargon2-dev \ | ||
libcurl4-openssl-dev \ | ||
libonig-dev \ | ||
libreadline-dev \ | ||
libsodium-dev \ | ||
libsqlite3-dev \ | ||
libssl-dev \ | ||
libxml2-dev \ | ||
zlib1g-dev \ | ||
bison \ | ||
# Dev tools \ | ||
git \ | ||
gdb \ | ||
valgrind \ | ||
neovim \ | ||
zsh && \ | ||
echo 'set auto-load safe-path /' > /root/.gdbinit && \ | ||
echo '* soft core unlimited' >> /etc/security/limits.conf \ | ||
&& \ | ||
apt-get clean | ||
|
||
RUN git clone --depth=1 --single-branch --branch=frankenphp-8.2 https://github.com/dunglas/php-src.git && \ | ||
cd php-src && \ | ||
git checkout frankenphp-8.2 && \ | ||
export CFLAGS="-DNO_SIGPROF" && \ | ||
# --enable-embed is only necessary to generate libphp.so, we don't use this SAPI directly | ||
./buildconf && \ | ||
./configure \ | ||
--enable-embed=static \ | ||
--enable-zts \ | ||
--disable-zend-signals \ | ||
--enable-debug && \ | ||
make -j6 && \ | ||
make install && \ | ||
ldconfig && \ | ||
php --version | ||
|
||
RUN echo "zend_extension=opcache.so\nopcache.enable=1" > /usr/local/lib/php.ini | ||
|
||
WORKDIR /go/src/app | ||
|
||
COPY . . | ||
|
||
RUN go get -d -v ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,93 +1,17 @@ | ||
# Caddy PHP | ||
# FrankenPHP: Modern App Server for PHP | ||
|
||
|
||
## Install | ||
|
||
### Docker | ||
|
||
The easiest way to get started is to use our Docker image: | ||
## Getting Started | ||
|
||
``` | ||
docker build -t frankenphp . | ||
``` | ||
|
||
### Compile From Sources | ||
|
||
#### Install PHP | ||
|
||
To use FrankenPHP, you currently need to compile a fork of PHP. | ||
Patches have been contributed upstream, and some have already | ||
been merged. It will be possible to use the vanilla version of PHP | ||
starting with version 8.3. | ||
|
||
First, get our PHP fork and prepare it: | ||
|
||
docker run -v $PWD:/app/public \ | ||
-p 80:80 -p 443:443 \ | ||
dunglas/frankenphp | ||
``` | ||
git clone https://github.com/dunglas/php-src.git | ||
cd php-src | ||
git checkout frankenphp-8.2 | ||
./buildconf | ||
``` | ||
|
||
Then, configure PHP for your platform: | ||
|
||
**Linux**: | ||
|
||
``` | ||
./configure \ | ||
--enable-embed \ | ||
--enable-zts \ | ||
--disable-zend-signals | ||
``` | ||
|
||
**Mac**: | ||
|
||
Use the [Homebrew](https://brew.sh/) package manager to install | ||
`libiconv` and `bison`: | ||
|
||
``` | ||
brew install libiconv bison | ||
echo 'export PATH="/opt/homebrew/opt/bison/bin:$PATH"' >> ~/.zshrc | ||
``` | ||
|
||
Then run the configure script: | ||
|
||
``` | ||
./configure \ | ||
--enable-embed=static \ | ||
--enable-zts \ | ||
--disable-zend-signals \ | ||
--disable-opcache-jit \ | ||
--with-iconv=/opt/homebrew/opt/libiconv/ | ||
``` | ||
|
||
These flags are required, but you can add other flags (extra extensions...) | ||
if needed. | ||
|
||
Finally, compile PHP: | ||
|
||
``` | ||
make -j6 | ||
make install | ||
``` | ||
|
||
#### Compile the Go App | ||
|
||
You can now use the Go lib and compile our Caddy build: | ||
|
||
``` | ||
cd caddy/frankenphp | ||
go build | ||
``` | ||
Your app is served at https://localhost! | ||
|
||
## Misc Dev Resources | ||
## Docs | ||
|
||
* [PHP embedding in uWSGI](https://github.com/unbit/uwsgi/blob/master/plugins/php/php_plugin.c) | ||
* [PHP embedding in NGINX Unit](https://github.com/nginx/unit/blob/master/src/nxt_php_sapi.c) | ||
* [PHP embedding in Go (go-php)](https://github.com/deuill/go-php) | ||
* [PHP embedding in Go (GoEmPHP)](https://github.com/mikespook/goemphp) | ||
* [PHP embedding in C++](https://gist.github.com/paresy/3cbd4c6a469511ac7479aa0e7c42fea7) | ||
* [Extending and Embedding PHP by Sara Golemon](https://books.google.fr/books?id=zMbGvK17_tYC&pg=PA254&lpg=PA254#v=onepage&q&f=false) | ||
* [What the heck is TSRMLS_CC, anyway?](http://blog.golemon.com/2006/06/what-heck-is-tsrmlscc-anyway.html) | ||
* [PHP embedding on Mac](https://gist.github.com/jonnywang/61427ffc0e8dde74fff40f479d147db4) | ||
* [SDL bindings](https://pkg.go.dev/github.com/veandco/[email protected]/sdl#Main) | ||
* [worker mode](docs/worker.md) | ||
* [Early Hints support (103 HTTP status code)](docs/early-hints.md) | ||
* [compile from sources](docs/compile.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
# Debug | ||
{$DEBUG} | ||
|
||
frankenphp { | ||
#worker /path/to/your/worker.php | ||
{$FRANKENPHP_CONFIG} | ||
} | ||
} | ||
|
||
{$SERVER_NAME:localhost} | ||
|
||
log | ||
route { | ||
root * public/ | ||
# Add trailing slash for directory requests | ||
@canonicalPath { | ||
file {path}/index.php | ||
not path */ | ||
} | ||
redir @canonicalPath {path}/ 308 | ||
|
||
# If the requested file does not exist, try index files | ||
@indexFiles file { | ||
try_files {path} {path}/index.php index.php | ||
split_path .php | ||
} | ||
rewrite @indexFiles {http.matchers.file.relative} | ||
|
||
# FrankenPHP! | ||
@phpFiles path *.php | ||
php @phpFiles | ||
encode zstd gzip | ||
file_server | ||
|
||
respond 404 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.