Skip to content

Embed assets to phar file #1568

@KarelWintersky

Description

@KarelWintersky

My project have dirs and files

- assets
  - scripts.js
  - styles.css
- engine
  - (some engine files)
- vendor
  - (composer installed files)
- index.php

inside my index.php (or any template) i have a strings:

<script src="/assets/scripts.js"></script>
<link href="/assets/styles.css" rel="stylesheet">

My vhost looks like this:

server {
    listen 80;

    server_name homestead.local;

    root /var/www.projects/example.phar_embed_assets/public/;

    index index.phar index.php index.html index.htm;

    error_log /var/log/nginx/homestead.error.log;
    access_log /var/log/nginx/homestead.access.log;

    location / {
	     try_files $uri $uri/ /index.phar?$query_string;
    }

    # Обработка PHAR файлов
    location ~ \.phar$ {
        try_files $uri =404;
        fastcgi_pass php-handler-8;
        fastcgi_index index.phar;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
        
        fastcgi_split_path_info ^(.+\.phar)(/.+)$;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }


    location ~ \.php$ {
        include         fastcgi_params;
        fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_pass    php-handler-8;
        fastcgi_index   index.php;
    }

    location = /favicon.ico {
        log_not_found off;
        return 204;       
    }
}

But when opening the site on a virtual host, the assets (styles and scripts embedded in the PHAR file) do not load.

Instead of a CSS file, I see an HTML page:

Image

How I can embed assets (templates, icons, styles etc) to phar archive and use it?

Complete project:

https://github.com/KarelWintersky/example.phar_embed_assets

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions