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;
}
}