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

The current configuration and driver for TYPO3 does not work with version 11 of the CMS #1423

Closed
Konafets opened this issue Jun 23, 2023 · 4 comments
Assignees

Comments

@Konafets
Copy link

Description

With version 11 TYPO3 changed the URL rewriting which breaks Valet. Valet routes always to the frontend even if you open the backend at https://example.com/typo3. The error is: "The page did not exist or was inaccessible. Reason: No site configuration found."

I got it running by adjusting the Nginx configuration and the TYPO3ValetDriver. I added a LocalValetDriver and made the changes there. Here are the two files:

<?php

declare(strict_types=1);

use Valet\Drivers\LaravelValetDriver;

class LocalValetDriver extends Typo3ValetDriver
{
    protected $documentRoot = '/public';

    /**
     * Determine if the driver serves the request.
     */
    public function serves($sitePath, $siteName, $uri)
    {
        return true;
    }

    /**
     * Get the fully resolved path to the application's front controller.
     */
    public function frontControllerPath($sitePath, $siteName, $uri)
    {
        // without modifying the URI, redirect if necessary
        $this->handleRedirectBackendShorthandUris($uri);

        // from now on, remove trailing / for convenience for all the following join operations
        $uri = rtrim($uri, '/');

        if (file_exists($absoluteFilePath = $sitePath.$this->documentRoot.$uri)) {
            if (is_dir($absoluteFilePath)) {
                if (file_exists($absoluteFilePath.'/index.php')) {
                    // this folder can be served by index.php
                    return $this->serveScript($sitePath, $siteName, $uri.'/index.php');
                }

                if (file_exists($absoluteFilePath.'/index.html')) {
                    // this folder can be served by index.html
                    return $absoluteFilePath.'/index.html';
                }
            } elseif (pathinfo($absoluteFilePath, PATHINFO_EXTENSION) === 'php') {
                // this file can be served directly
                return $this->serveScript($sitePath, $siteName, $uri);
            }
        } elseif(str_contains($uri, '/typo3/')) {
            return $this->serveScript($sitePath, $siteName, '/typo3/index.php'); // basically added this line to route requests to the backend to the right file.
        }

        return $this->serveScript($sitePath, $siteName, '/index.php');
    }

    private function handleRedirectBackendShorthandUris($uri)
    {
        if (rtrim($uri, '/') === '/typo3/install') {
            header('Location: /typo3/sysext/install/Start/Install.php');
            exit();
        }
    }

    private function serveScript($sitePath, $siteName, $uri)
    {
        $docroot = $sitePath.$this->documentRoot;
        $abspath = $docroot.$uri;

        $_SERVER['SERVER_NAME'] = $siteName.'.dev';
        $_SERVER['DOCUMENT_ROOT'] = $docroot;
        $_SERVER['DOCUMENT_URI'] = $uri;
        $_SERVER['SCRIPT_FILENAME'] = $abspath;
        $_SERVER['SCRIPT_NAME'] = $uri;
        $_SERVER['PHP_SELF'] = $uri;

        return $abspath;
    }
}

and change the corresponding Nginx file for the domain to:

server {
    listen 127.0.0.1:80;
    #listen 127.0.0.1:80; # valet loopback
    server_name example.loc www.example.loc *.example.loc;
    return 301 https://$host$request_uri;
}

server {
    listen 127.0.0.1:443 ssl http2;
    #listen 127.0.0.1:443 ssl http2; # valet loopback
    server_name example.loc www.example.loc *.example.loc;
    root /;
    charset utf-8;
    client_max_body_size 512M;
    http2_push_preload on;

    location /41c270e4-5535-4daa-b23e-c269744c2f45/ {
        internal;
        alias /;
        try_files $uri $uri/;
    }

    ssl_certificate "/Users/$USER/.config/valet/Certificates/example.crt";
    ssl_certificate_key "/Users/$USER/.config/valet/Certificates/example.key";

    location / {
        rewrite ^ "/Users/$USER/.composer/vendor/laravel/valet/server.php" last;
    }

    # Compressing resource files will save bandwidth and so improve loading speed especially for users
    # with slower internet connections. TYPO3 can compress the .js and .css files for you.
    # *) Set $GLOBALS['TYPO3_CONF_VARS']['BE']['compressionLevel'] = 9 for the Backend
    # *) Set $GLOBALS['TYPO3_CONF_VARS']['FE']['compressionLevel'] = 9 together with the TypoScript properties
    #    config.compressJs and config.compressCss for GZIP compression of Frontend JS and CSS files.
    location ~ \.js\.gzip$ {
        add_header Content-Encoding gzip;
        gzip off;
        types { text/javascript gzip; }
    }

    location ~ \.css\.gzip$ {
        add_header Content-Encoding gzip;
        gzip off;
        types { text/css gzip; }
    }

    # TYPO3 - Rule for versioned static files, configured through:
    # - $GLOBALS['TYPO3_CONF_VARS']['BE']['versionNumberInFilename']
    # - $GLOBALS['TYPO3_CONF_VARS']['FE']['versionNumberInFilename']
    if (!-e $request_filename) {
        rewrite ^/(.+)\.(\d+)\.(php|js|css|png|jpg|gif|gzip)$ /$1.$3 last;
    }

    # TYPO3 - Block access to composer files
    location ~* composer\.(?:json|lock) {
        deny all;
    }

    # TYPO3 - Block access to flexform files
    location ~* flexform[^.]*\.xml {
        deny all;
    }

    # TYPO3 - Block access to language files
    location ~* locallang[^.]*\.(?:xml|xlf)$ {
        deny all;
    }

    # TYPO3 - Block access to static typoscript files
    location ~* ext_conf_template\.txt|ext_typoscript_constants\.txt|ext_typoscript_setup\.txt {
        deny all;
    }

    # TYPO3 - Block access to miscellaneous protected files
    location ~* /.*\.(?:bak|co?nf|cfg|ya?ml|ts|typoscript|tsconfig|dist|fla|in[ci]|log|sh|sql|sqlite)$ {
        deny all;
    }

    # TYPO3 - Block access to recycler and temporary directories
    location ~ _(?:recycler|temp)_/ {
        deny all;
    }

    # TYPO3 - Block access to configuration files stored in fileadmin
    location ~ fileadmin/(?:templates)/.*\.(?:txt|ts|typoscript)$ {
        deny all;
    }

    # TYPO3 - Block access to libraries, source and temporary compiled data
    location ~ ^(?:vendor|typo3_src|typo3temp/var) {
        deny all;
    }

    # TYPO3 - Block access to protected extension directories
    location ~ (?:typo3conf/ext|typo3/sysext|typo3/ext)/[^/]+/(?:Configuration|Resources/Private|Tests?|Documentation|docs?)/ {
        deny all;
    }

    location = /typo3 {
        rewrite ^ /typo3/;
    }

    location /typo3/ {
        absolute_redirect off;
        try_files $uri /typo3/index.php$is_args$args;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    access_log off;
    error_log "/Users/$USER/.config/valet/Log/nginx-error.log" debug;

    error_page 404 "/Users/$USER/.composer/vendor/laravel/valet/server.php";

    location ~ [^/]\.php(/|$) {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass "unix:/Users/$USER/.config/valet/valet.sock";
        fastcgi_index "/Users/$USER/.composer/vendor/laravel/valet/server.php";
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME "/Users/$USER/.composer/vendor/laravel/valet/server.php";
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }

    location ~ /\.ht {
        deny all;
    }
}

server {
    listen 127.0.0.1:60;
    #listen 127.0.0.1:60; # valet loopback
    server_name example.loc www.example.loc *.example.loc;
    root /;
    charset utf-8;
    client_max_body_size 128M;

    add_header X-Robots-Tag 'noindex, nofollow, nosnippet, noarchive';

    location /41c270e4-5535-4daa-b23e-c269744c2f45/ {
        internal;
        alias /;
        try_files $uri $uri/;
    }

    location / {
        rewrite ^ "/Users/$USER/.composer/vendor/laravel/valet/server.php" last;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    access_log off;
    error_log "/Users/$USER/.config/valet/Log/nginx-error.log";

    error_page 404 "/Users/$USER/.composer/vendor/laravel/valet/server.php";

    location ~ [^/]\.php(/|$) {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass "unix:/Users/$USER/.config/valet/valet.sock";
        fastcgi_index "/Users/$USER/.composer/vendor/laravel/valet/server.php";
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME "/Users/$USER/.composer/vendor/laravel/valet/server.php";
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }

    location ~ /\.ht {
        deny all;
    }
}

Steps To Reproduce

Install a new TYPO3

composer create-project typo3/cms-base-distribution:"^11" example

Link Valet

cd example && valet link example && valet secure

Add a FIRST_INSTALL file

touch example/public/FIRST_INSTALL

Go through the installation process and open the backend (https://example.com/typo3) or the frontend (https://example.com).

Diagnosis

Not Needed

@github-actions
Copy link

github-actions bot commented Jul 3, 2023

Thank you for reporting this issue!

As Laravel is an open source project, we rely on the community to help us diagnose and fix issues as it is not possible to research and fix every issue reported to us via GitHub.

If possible, please make a pull request fixing the issue you have described, along with corresponding tests. All pull requests are promptly reviewed by the Laravel team.

Thank you!

@driesvints
Copy link
Member

Hi there, I'm sorry but I'm going to close this as we only have received one report for this so far. We'd welcome a PR to solve this one, thanks.

@Konafets
Copy link
Author

Konafets commented Oct 9, 2023

Hi @driesvints,

when I have some time, I will try to add an PR.

@SirNovi
Copy link

SirNovi commented May 31, 2024

This issue still seems to persist for v12

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants