Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP/GAE Buildpacks cannot serve static files #234

Open
vbarbarosh opened this issue Sep 4, 2022 · 1 comment
Open

PHP/GAE Buildpacks cannot serve static files #234

vbarbarosh opened this issue Sep 4, 2022 · 1 comment
Labels
kind/question Further information is requested

Comments

@vbarbarosh
Copy link

It turns out that all requests are passed to the front controller. What about static files? I found no way to instruct nginx to serve them.
Seems https://github.com/GoogleCloudPlatform/buildpacks/blob/main/pkg/nginx/nginx.go is responsible for making nginx.conf file.

This is how I built my app for GAE:

$ cat run.Dockerfile
FROM gcr.io/gae-runtimes/buildpacks/php74/run
USER root

        # Install phpredis
        RUN apt-get update
        RUN apt-get install -y autoconf make g++
        RUN echo | pecl install redis
        RUN echo 'extension=redis.so' >> /etc/php.ini
        RUN php -r 'echo "PHPREDIS: ", phpversion("redis"), "\n";'

USER www-data

$ docker build -t my-run-image -f run.Dockerfile .

$ pack build hello-app --builder=gcr.io/gae-runtimes/buildpacks/php74/builder:latest --run-image=my-run-image --env=X_GOOGLE_TARGET_PLATFORM=gae 
@vbarbarosh
Copy link
Author

Current solution:

<?php

$file = __DIR__ . $_SERVER['PATH_INFO'];
if (is_file($file)) {
    switch (preg_replace('/.*?([^.]+)$/', '$1', basename($file))) {
    case 'jpg': $mime = 'image/jpeg'; break;
    case 'jpeg': $mime = 'image/jpeg'; break;
    case 'png': $mime = 'image/png'; break;
    case 'svg': $mime = 'image/svg+xml'; break;
    case 'gif': $mime = 'image/gif'; break;
    case 'html': $mime = 'text/html'; break;
    case 'md': $mime = 'text/plain'; break;
    case 'css': $mime = 'text/css'; break;
    case 'xml': $mime = 'text/xml'; break;
    case 'js': $mime = 'text/javascript'; break;
    case 'json': $mime = 'application/json'; break;
    default: $mime = 'application/octet-stream'; break;
    }
    header("Content-Type: $mime");
    header('Content-Length: ' . filesize($file));
    flush();
    readfile($file);
    exit;
}

require_once __DIR__ . '/index-laravel.php';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants