Score:0

NGINX + PHP + ASDF: asdf plugin is using PHP 5.6 instead of 7.4

br flag

Goal: I need to load a PHP website (7.4) running NGINX using ASDF plugin. (Mac OS, M2 processor, NGINX and ASDF installed)

issue: when I load the website via nginx I get this:

Fatal error: Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 7.4.0". You are running 5.6.40. in /usr/local/var/www/my_sulu_project/vendor/composer/platform_check.php on line 25

Trying to debug the Error

Here are some commands I ran:

$ php -v
PHP 7.4.33 (cli) (built: Apr  5 2023 18:33:55) ( NTS )
Copyright (c) The PHP Group

$ asdf list php
 *7.4.33
  8.2.6

$ which php
/Users/**redacted**/.asdf/shims/php

$ which php-fpm
/Users/**redacted**/.asdf/shims/php-fpm

$ composer -V
Composer version 2.2.21 2023-02-15 13:07:40

### !!! note that is showing `php-fpm` version 5.6 below
$ ps aux | grep php
**redacted**          2043   0.0  0.0 34851832   2016   ??  S    11:14am   0:00.01 /usr/local/opt/[email protected]/sbin/php-fpm --nodaemonize
**redacted**          2042   0.0  0.0 34982908   2116   ??  S    11:14am   0:00.03 /usr/local/opt/[email protected]/sbin/php-fpm --nodaemonize
**redacted**          1938   0.0  0.0 34851948   1332   ??  S    11:14am   0:00.66 /usr/local/opt/[email protected]/sbin/php-fpm --nodaemonize

$ nginx -t && nginx -s reload
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful

More Info: I installed it via ASDF, because I need to use multiple versions of PHP, depending on which project I'm working on, including a migration to 8.x in the pipeline.

I'm using framework Sulu CMS 1.6 (Symfony), and according to these docs is how you configure nginx, but because I'm using asdf plugin, I had to edit the fastcgi_pass line, which I changed to fastcgi_pass 127.0.0.1:9000;

Running the php command gives me the correct version, even running composer

I installed PHP 7.4 via ASDF both locally and globally.

I'm thinking is that maybe there is a way to point /usr/local/opt/[email protected]/sbin/php-fpm to /Users/**redacted**/.asdf/shims/php-fpm ?

or maybe NGINX needs to be configured another way?

I also tried changing fastcgi_pass unix:/usr/local/opt/[email protected]/sbin/php-fpm; to the asdf php-fpm shim location, but without success.

Example of Installation to Reproduce this

brew install libzip
asdf install php latest:7
asdf local php latest:7
git clone https://github.com/sulu/sulu-minimal.git
# composer 2.2 is required in my project
composer self-update --2.2
composer install

nginx site config:

{
    server {
    listen 80;

    server_name local.my_project;
    root /usr/local/var/www/my_project/web;

    error_log /usr/local/var/www/my_project/var/logs/nginx_error.log;
    access_log /usr/local/var/www/my_project/var/logs/nginx_access.log;

    # strip app.php/ prefix if it is present
    rewrite ^/app\.php/?(.*)$ /$1 permanent;

    # recommended security headers
    add_header X-Frame-Options sameorigin;
    add_header X-Content-Type-Options nosniff;
    add_header X-XSS-Protection "1; mode=block";
    location /admin {
        index admin.php;
        try_files $uri @rewriteadmin;
    }

    location @rewriteadmin {
        rewrite ^(.*)$ /admin.php/$1 last;
    }

    location / {
      index website.php;
      try_files $uri @rewritewebsite;
    }

    # expire
    location ~* \.(?:ico|css|js|gif|webp|jpe?g|png|svg|woff|woff2|eot|ttf|mp4)$ {
        try_files $uri /website.php/$1?$query_string;
        access_log off;
        expires 1y;
        add_header Pragma public;
        add_header Cache-Control "public";
    }

    location @rewritewebsite {
        rewrite ^(.*)$ /website.php/$1 last;
    }

    # pass the PHP scripts to FastCGI server from upstream phpfcgi
    location ~ ^/(website|admin|app|config)\.php(/|$) {
       fastcgi_pass 127.0.0.1:9000;
    #    fastcgi_pass unix:/usr/local/opt/[email protected]/sbin/php-fpm;
       fastcgi_split_path_info ^(.+\.php)(/.*)$;
       include fastcgi_params;
       fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
       fastcgi_param DOCUMENT_ROOT $realpath_root;
       fastcgi_param SYMFONY_ENV dev;
       internal;
    }
}
w3jimmy avatar
br flag
nginx version: nginx/1.21.1
djdomi avatar
za flag
Questions seeking installation, configuration or diagnostic help must include the desired end state, the specific problem or error, sufficient information about the configuration and environment to reproduce it, and attempted solutions. Questions without a clear problem statement are not useful to other readers and are unlikely to get good answers.
w3jimmy avatar
br flag
thank you for feedback @djdomi, I'll rewrite it
djdomi avatar
za flag
I've seen your edit but only 30% has been implemented
w3jimmy avatar
br flag
I added an installation example, let me know which parts are unclear
w3jimmy avatar
br flag
added nginx config
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.