PHP Directory


  • Grav CMS: Permission problems on setup

    I tried to setup a new site with Grav CMS 1.5.10 and ran into permission problems after unpacking one of the skeleton .zip files. The reason is that on my Linux machine I am running as user+group "cweiske", while Apache is running under "www-data" - and Grav wants to write some files even when it tries to reach the setup check screen.

    Grav has a manual page about permissions which is complete nonsense if you want a secure system, and only give the web server process as few writable files and directories as possible. The manual page instructs you to change the permissions and group of every file and directory, which is unneeded.


    Error messages I encountered before the setup check page worked:

    Fatal error: Uncaught RuntimeException: Creating directory '/.../cache/compiled/files' failed on error

    This is simple:

    $ chgrp -R www-data cache
    $ chmod -R g+w cache/

    But now:

    Fatal error: Uncaught RuntimeException: Opening file for writing failed on error

    No more information. And what's worse: No stack trace, because Grav catches the Exception and throws it again.

    The solution is to edit vendor/rockettheme/toolbox/File/src/File.php and let it output the file it tried to write:

    - throw new \RuntimeException("Opening file for writing failed on error {$error['message']}");
    + throw new \RuntimeException("Opening file for writing failed on error {$error['message']}" . $this->filename);

    We now see that it wants to write into user/config/security.yaml.

    $ chgrp -R www-data user/config/
    $ chmod -R g+w user/config/

    And now I saw the setup check page.

    Final solution

    In the end I had to give this permissions:

    $ chgrp -R www-data assets/ backup/ cache/ images/ logs/ system/config/ tmp/ user/accounts/ user/config/ user/data/ user/pages/
    $ chmod -R g+w assets/ backup/ cache/ images/ logs/ system/config/ tmp/ user/accounts/ user/config/ user/data/ user/pages/

    I'm also disappointed that Grav puts all files publicly available into the server's document root directory, because it does not have a public/ or www/ directory. The issue was closed without a proper solution; Grav's authors chose to patch their .htaccess file instead :/

  • PHP Internals News: Episode 4: Short Arrow Functions

  • PSR-14: Compound Providers

    PSR-14: Compound Providers

    Submitted by Larry on 3 April 2019 - 10:45am

    In part 3 of this series we looked at the more common patterns of Providers that may be used with a PSR-14 Event Dispatcher. In part 4 we looked at some more complex cases of Providers. Today, we'll bring them all together: Literally.

    Recall that a Provider is responsible only for receiving an Event and returning a list of callables that it believes should be invoked on it, in the order it decides (if it cares). How it does that is up to the implementation. In fact, it's not even required to do so itself at all. A Provider can defer that decision to another Provider if it wishes, or, critically, to multiple Providers.

    Continue reading this post on SteemIt.

  • Slim 4 Cyclomatic Complexity

    There's not much wrong with Slim 3; lots of people are using it very successfully producing APIs and websites of all kinds. For Slim 4 the main goals have been to support PSR-15, make it easier to use your own PSR-7 implementation, improve error handling and remove assumptions that look magical if you don't know they are there. The latter one is the most important to me, personally!

    Secondarily, Pierre has concentrated on making Slim's code more flexible and hopefully making it easier to swap out our internal components with your own if you need to. On a whim, I ran phploc on the current Slim 3 and Slim 4-dev codebases to see what differences were. The full results are in this gist.

    Note that Slim 4 doesn't have the PSR-7 implementation or the container wrapper, so it's maybe not possible to directly compare some of the numbers, but the cyclomatic complexity numbers are interesting and a direct outcome of Pierre's work:

                                        Slim 3    Slim 4-dev
    Cyclomatic Complexity
      Average Complexity per LLOC         0.30          0.18
      Average Complexity per Class       10.40          4.76
        Minimum Class Complexity          1.00          1.00
        Maximum Class Complexity         67.00         25.00
      Average Complexity per Method       2.44          2.05
        Minimum Method Complexity         1.00          1.00
        Maximum Method Complexity        15.00         15.00

    Cyclomatic complexity is a measure of the complexity of a codebase. It's really hard to ensure that a method with a high cyclomatic complexity works as intended and I'm delighted to see these numbers go down! Hopefully this means that Slim 4's internals are easier to understand and it will be easier to contribute to.

    We need to find, assess and simplify the method that has that 15.00 though!

  • 418 I'm a teapot

    The IETF has a tradition to publish one or more april-fools RFC documents every year. Among the most famous are IP over Avian Carriers with Quality of Service, and of course Hyper Text Coffee Pot Control Protocol, which introduced the 418 I'm a teapot HTTP status.

    This status-code is of course not an official one. You won’t find it in the IANA HTTP Status code registry. However, people have such a liking to it that it’s supported in many HTTP libraries.

    About a year ago, the HTTP working group tried to reach out to various projects to try and remove their support for 418, so the number could be re-used for a new purpose, but this was met with a lot of resistance, even spawning

    Several implementations of HTCPCP can be found, including:

    The 418 code also appears as easter eggs in numerous systems.

    Wikipedia has a page on all the IETF april fools jokes, which is well worth a read. It also features the HTCPCP-TEA extension!

    All we need now is a WHATWG living standard that just solidifies everyone’s buggy implementations (looking at you URL standard), and a W3C committee that forks it once per year.

    References & sources

  • Interview with Olivia Liddell

    Show Notes


    This episode is sponsored by

    The post Interview with Olivia Liddell appeared first on Voices of the ElePHPant.

  • PSR-14: Advanced Providers

    PSR-14: Advanced Providers

    In part 3 of our series we looked at some common Provider patterns for PSR-14. But the flexibility and complexity of Providers is limited only by your imagination. Today we'll look at a few more interesting examples of Providers that are all equally valid but tailored to particular use cases.

    Continue reading this post on SteemIt.

    Larry 1 April 2019 - 11:34am
  • PSR-14: Being a good Provider

    PSR-14: Being a good Provider

    As mentioned back in part 1, PSR-14 splits the core mediator into two objects: The Dispatcher and the Provider. The Dispatcher is fairly straightforward and most implementations will be fairly simple and fairly similar.

    Providers are the exact opposite; A Listener Provider has one requirement: It maps the Event object into an iterable of callables, in the order it chooses. How it does that is left up to the Provider to define, and there are dozens of possible ways.

    Continue reading this post on SteemIt.

    Larry 30 March 2019 - 11:00am
  • PSR-14: All about Events

    PSR-14: All about Events

    In the last installment we discussed the overall structure of PSR-14. Today I'd like to dive into the key aspect of any event system: The Events themselves.

    Various different event systems structure events in different ways. Some require that it be an object. Others it's any arbitrary value. Others it's any number of arbitrary values, depending on the Event. Some really really want pass-by-reference arrays.

    For PSR-14, we chose to standardize on an object and always an object. There were three main reasons for that:

    Continue reading this post on SteemIt.

    Larry 28 March 2019 - 11:03am
  • Using loops instead of higher order functions

:: Our Favorites

Featured Sites Using PHP

>Halifax WordPress Development