Php error file not found

Let’s fix – php fpm file not found error

The php fpm file not found error is normally caused due to permissions error or due to improper details in the configuration file.

At Bobcares, we receive requests to fix php-fpm related errors as a part of our Server Management Services.

Today, let’s discuss the causes for PHP-FPM error and see how our Support Engineers fix it.

How php-fpm works?

Let’s begin by checking the working of PHP-FPM ( FastCGI Process Manager ).

Traditionally, the web server compiles PHP scripts through server modules such as suPHP, CGI, DSO. PHP-FPM provides a new experience that avoids the drawbacks of other PHP handlers like suPHP, CGI, DSO.

In PHP-FPM, a separate service is designed specifically for processing PHP scripts. In addition, PHP-FPM has a “master process” managing pools of individual “worker processes.”

When the webserver requests for any PHP scripts, it uses a proxy, Fastcgi connection to forward the request to PHP-FPM service. As PHP-FPM receives a proxied connection, a free PHP-FPM worker accepts the web server’s request.

PHP-FPM then compiles and executes the PHP script, sending the output back to the webserver. Once a PHP-FPM worker finishes handling a request, the system releases the worker and waits for new requests.

Читайте также:  Королевский питон нормал взрослый

What causes PHP FPM file not found error?

Often when accessing the website files, Nginx server may not be serve the pages. It ends up in file not found error. For instance, on a misconfigured server, the error shows up as:

Now, let’s discuss the different reasons causing this error.

1. Parameter placement error

Usually, when the configuration file of Nginx has improper parameters, then it will throw errors. Also, placing the configuration file in the wrong path will cause errors.

There must not be any confusion for the webserver modules to understand these parameters. This includes setting the proper document root. For the website files to show up, they must be accessible for the Nginx server.

2. Wrong permissions

In a similar way, the user running the php-fpm must have proper permissions to run the PHP scripts. By default, Nginx runs under the ownership of the user ‘www-data‘. This varies according to the configuration of the server.

If the files have any incorrect permissions, then the scripts don’t execute and end up with the file not found error.

Occasionally, security settings like SELinux may also affect the file access.

3. FPM not running

FPM not running on the server can also be an obvious reason for the error. In many cases, improper configuration of PHP-FPM results in frequent restart of the service. At times, the service may not even start. Then also it would report the file not found error.

How we fix php fpm file not found error?

Till now we saw what causes this error to occur. Now, let’s see how our Support Engineers fix it.

1. Configuration details problem

One of our customers received the below error message while accessing info.php

And, he was using the configuration that set the default file location as /var/www. But, the FastCGI was set as /usr/share/nginx/html.

server < listen 80; listen [::]:80 default ipv6only=on; server_name localhost; location / < root /var/www; index index.html index.htm index.php; ># pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ < fastcgi_pass 127.0.0.1:7777; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name; . . >>

This caused FastCGI to look for the file at /usr/share/nginx/html/info.php;

As this was unavailable, it returned the error.

To fix the error, our Dedicated Engineers updated the above code and set the same root for html and PHP. Also, we kept the root and index parameters outside the location except for specific users.

Then, we suggested customer to write $document_root$fastcgi_script_name instead of /usr/share/nginx/html$fastcgi_script_name within the location as below.

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 

Finally, this fixed the error.

2. Checking permissions to fix php fpm file not found

We received another request from our customer telling us that he received a “file not found” error on all PHP files.

Initially, our Support Engineers went checking the configuration file and suggested to put “include fastcgi_params;” before all “fastcgi_param *” lines.

Here, “include fastcgi_params;” overrides all the “fastcgi_param *” lines as below.

Then, we went checking the user running Nginx, PHP-FPM, etc. Then we checked their permissions for accessing the website folder.

We used the below commands:

ps aux | grep php-fpm ps aux | grep nginx

Finally, we solved this problem by changing user and group to the current user:group in php-fpm.d/www.conf

[Need any help in fixing php-fpm errors? – We’ll help you]

Conclusion

In short, the php fpm file not found error normally occurs due to permissions error or due to improper details in the configuration file. Today, we saw how our Support Engineers fix this error.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

Источник

Nginx + php-fpm file not found почему?

Когда в браузере пытаюсь открыть любой файл php (например education.clouder.xyz/index2.php), отличный от index.php то выдает ошибку file not found. Все остальное отлично перенаправляется на index.php. Почему так? В чем ошибка?

denistu10

Уберите апстрим
и в location пропишите
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
Перезапустите nginx и проверьте

user28

denistu10

user28

denistu10

user28

denistu10

user28

Можно. Вот мойphp.ini.
И еще вопрос если можно. Я же правильно понимаю, что если у меня настроено перенаправление (rewrite ^(.+)$ /index.php?url=$1;) на index.php, то даже когда я набираю в адресной строке несуществующий файл, например education.clouder.xyz/nofile.php меня все равно должно перенаправить на index.php, в независимости от того существует такой файл или нет?

denistu10

user28

В папке fpm есть файл php-fpm.conf, а www.conf в подпапке pool.d. www.conf не влезает в комментарии. тут
php-fpm.conf

;;;;;;;;;;;;;;;;;;;;; ; FPM Configuration ; ;;;;;;;;;;;;;;;;;;;;; ; All relative paths in this configuration file are relative to PHP's install ; prefix (/usr). This prefix can be dynamically changed by using the ; '-p' argument from the command line. ;;;;;;;;;;;;;;;;;; ; Global Options ; ;;;;;;;;;;;;;;;;;; [global] ; Pid file ; Note: the default prefix is /var ; Default Value: none pid = /run/php/php7.0-fpm.pid ; Error log file ; If it's set to "syslog", log is sent to syslogd instead of being written ; in a local file. ; Note: the default prefix is /var ; Default Value: log/php-fpm.log error_log = /var/log/php7.0-fpm.log ; syslog_facility is used to specify what type of program is logging the ; message. This lets syslogd specify that messages from different facilities ; will be handled differently. ; See syslog(3) for possible values (ex daemon equiv LOG_DAEMON) ; Default Value: daemon ;syslog.facility = daemon ; syslog_ident is prepended to every message. If you have multiple FPM ; instances running on the same server, you can change the default value ; which must suit common needs. ; Default Value: php-fpm ;syslog.ident = php-fpm ; Log level ; Possible Values: alert, error, warning, notice, debug ; Default Value: notice ;log_level = notice ; If this number of child processes exit with SIGSEGV or SIGBUS within the time ; interval set by emergency_restart_interval then FPM will restart. A value ; of '0' means 'Off'. ; Default Value: 0 ;emergency_restart_threshold = 0 ; Interval of time used by emergency_restart_interval to determine when ; a graceful restart will be initiated. This can be useful to work around ; accidental corruptions in an accelerator's shared memory. ; Available Units: s(econds), m(inutes), h(ours), or d(ays) ; Default Unit: seconds ; Default Value: 0 ;emergency_restart_interval = 0 ; Time limit for child processes to wait for a reaction on signals from master. ; Available units: s(econds), m(inutes), h(ours), or d(ays) ; Default Unit: seconds ; Default Value: 0 ;process_control_timeout = 0 ; The maximum number of processes FPM will fork. This has been design to control ; the global number of processes when using dynamic PM within a lot of pools. ; Use it with caution. ; Note: A value of 0 indicates no limit ; Default Value: 0 ; process.max = 128 ; Specify the nice(2) priority to apply to the master process (only if set) ; The value can vary from -19 (highest priority) to 20 (lower priority) ; Note: - It will only work if the FPM master process is launched as root ; - The pool process will inherit the master process priority ; unless it specified otherwise ; Default Value: no set ; process.priority = -19 ; Send FPM to background. Set to 'no' to keep FPM in foreground for debugging. ; Default Value: yes ;daemonize = yes ; Set open file descriptor rlimit for the master process. ; Default Value: system defined value ;rlimit_files = 1024 ; Set max core size rlimit for the master process. ; Possible Values: 'unlimited' or an integer greater or equal to 0 ; Default Value: system defined value ;rlimit_core = 0 ; Specify the event mechanism FPM will use. The following is available: ; - select (any POSIX os) ; - poll (any POSIX os) ; - epoll (linux >= 2.5.44) ; - kqueue (FreeBSD >= 4.1, OpenBSD >= 2.9, NetBSD >= 2.0) ; - /dev/poll (Solaris >= 7) ; - port (Solaris >= 10) ; Default Value: not set (auto detection) ;events.mechanism = epoll ; When FPM is build with systemd integration, specify the interval, ; in second, between health report notification to systemd. ; Set to 0 to disable. ; Available Units: s(econds), m(inutes), h(ours) ; Default Unit: seconds ; Default value: 10 ;systemd_interval = 10 ;;;;;;;;;;;;;;;;;;;; ; Pool Definitions ; ;;;;;;;;;;;;;;;;;;;; ; Multiple pools of child processes may be started with different listening ; ports and different management options. The name of the pool will be ; used in logs and stats. There is no limitation on the number of pools which ; FPM can handle. Your system will tell you anyway :) ; Include one or more files. If glob(3) exists, it is used to include a bunch of ; files from a glob(3) pattern. This directive can be used everywhere in the ; file. ; Relative path can also be used. They will be prefixed by: ; - the global prefix if it's been set (-p argument) ; - /usr otherwise include=/etc/php/7.0/fpm/pool.d/*.conf

denistu10

user28

Теперь при заходе на education.clouder.xyz chrome скачивает php файл, edge показывает php код.

denistu10

user28

Подключил fastcgi_pass unix:/run/php/php7.0-fpm.sock;
Отрабатывает нормально php файлы. Не существующие как положено страница с 404.
При подключении rewrite опять index.php нормально отрабатывает, остальные с php расширением file not found.

Источник

Оцените статью