Fastcgi sent in stderr php message php parse error syntax error unexpected

nginx / php-fpm error logging

I’m trying to figure out where the PHP errors are going in my setup. I’m running nginx as the reverse proxy to PHP-FPM, but I’m not seeing the various E_NOTICE or E_WARNING messages my app is producing. The only reason I know they’re happening is failed responses and NewRelic catching stack traces. Here’s the logging config: nginx.conf

proxy_intercept_errors on; fastcgi_intercept_errors on; 
error_reporting = E_ALL display_errors = Off display_startup_errors = Off log_errors = On log_errors_max_len = 1024 ignore_repeated_errors = Off ignore_repeated_source = Off report_memleaks = On track_errors = On error_log = syslog 
[global] error_log = /var/log/php-fpm/fpm-error.log [www] access.log = /var/log/php-fpm/access.log access.format = "%t \"%m %r%Q%q\" %s %dms %Mkb %C%%" catch_workers_output = yes php_flag[display_errors] = on php_admin_flag[log_errors] = true 
:syslogtag, contains, "php" /var/log/php-fpm/error.log 

I’ve configured PHP to log to syslog, however FPM has no syslog function so it’s logging to a file. I don’t really care where the errors end up, just that they end up somewhere. Any clues on how I might get this to work?

I would try make errors display first (in a test.php file you could manually trigger an error), then put them in a file and so on. . Could be errors triggered are from cli, thus using a different php.ini

Did you try this? php_admin_value[error_log] = /var/log/php-fpm/www-error.log php_admin_flag[log_errors] = on

4 Answers 4

Your php-fpm.conf file is not set up to send errors to syslog. See below for an example of how to do this.

; 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 = syslog ; 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 

Are you sure about your assumption for the rsyslog.conf? That is, are you sure all such syslog messages are tagged with lower-case «php»?

Try setting syslog.facility to something like local2 (or local1, or local7) and replacing your rsyslog.conf config-line accordingly:

local2.* /var/log/php-fpm/error.log 

When you’re using php-fpm, it appears to override the php.ini settings.

The logging most likely needs to be configured in . /www.conf .

I uncommented these lines in order to grab the PHP logs.

php_admin_value[error_log] = /var/log/php-errors.log php_admin_flag[log_errors] = on 

The webserver user and group can also be found in this file under lines similar to this (may differ between unix socket & proxy configuration).

listen.owner = www-data listen.group = www-data 

Then it’s just a matter of creating the file and configuring it properly.

touch /var/log/php-errors.log chmod 644 /var/log/php-errors.log chgrp www-data /var/log/php-errors.log chown www-data /var/log/php-errors.log 

I believe the log level is still used from php-fpm.conf so you may also need to check this.

Читайте также:  Add first element to array javascript

Thanks. It works. But adding this line log_level = error would cause an error and stop php-fpm from launching. My php-fpm version is 7.2 .

to get php-fpm errors in nginx error log you need:

as for nginx: it s enough just basic config

# cat default | grep -v "#" server < listen 80 default_server; listen [::]:80 default_server; root /var/www/html; index index.html index.htm index.nginx-debian.html; server_name _; index index.html; location / < try_files $uri $uri/ =404; >location ~ \.php$ < include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php7.0-fpm.sock; >> 

as for php-fpm the main setting is

basically it s enough. but to be on the safe side i would suggest to put the following block in php-fpm config(/etc/php/7.0/fpm/php.ini) :

[PHP] . error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT display_errors = Off display_startup_errors = On log_errors = On log_errors_max_len = 1024 ignore_repeated_errors = Off ignore_repeated_source = Off report_memleaks = On track_errors = Off html_errors = On . 

after that all php stack traces will be in

# tail /var/log/nginx/error.log 2023/06/20 23:37:06 [error] 20307#20307: *1 FastCGI sent in stderr: "PHP message: PHP Parse error: syntax error, unexpected '"asd"' (T_CONSTANT_ENCAPSED_STRING) in /var/www/html/php1.php on line 2" while reading response header from upstream, client: 127.0.0.1, server: _, request: "GET /php1.php HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.0-fpm.sock:", host: "localhost" 2023/06/20 23:48:40 [error] 20307#20307: *5 FastCGI sent in stderr: "PHP message: PHP Parse error: syntax error, unexpected '"asd"' (T_CONSTANT_ENCAPSED_STRING) in /var/www/html/php1.php on line 2" while reading response header from upstream, client: 127.0.0.1, server: _, request: "GET /php1.php HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.0-fpm.sock:", host: "localhost" 2023/06/21 00:18:17 [error] 20307#20307: *7 FastCGI sent in stderr: "PHP message: PHP Parse error: syntax error, unexpected '"asd"' (T_CONSTANT_ENCAPSED_STRING) in /var/www/html/php1.php on line 2" while reading response header from upstream, client: 127.0.0.1, server: _, request: "GET /php1.php HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.0-fpm.sock:", host: "localhost:4545" 

if you want to see php stack traces not in nginx erorr file but instead in a separate file you need to add error_log setting that is

error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT display_errors = Off display_startup_errors = On log_errors = On error_log = /var/log/php-errors.log log_errors_max_len = 1024 ignore_repeated_errors = Off ignore_repeated_source = Off report_memleaks = On track_errors = Off html_errors = On 

also very important to create /var/log/php-errors.log manually and set proper permisssions because php-fpm wont do that and will continue to transfer error to nginx. so

# touch /var/log/php-errors.log # chown www-data.www-data /var/log/php-errors.log # systemctl restart php7.0-fpm 

after that nginx error log /var/log/nginx/error.log will be empty but all php-errors will be in /var/log/php-errors.log

Источник

PHP parse error syntax error, unexpected end of file

Now file that is causing this error is here, and i noticed that line is the empty last line and i tried to remove that line but won’t get removed. Can anyone point me to what is causing this error? nano /var/www/www.example.com/public/wp-content/themes/techs/functions.php line 141 is the empty line after/under the closing tag; every attemp to delete that line failed

/*register_sidebar(array( 'name'=>'sidebar', 'before_widget' => '
  • ', 'after_widget' => '', 'before_title' => '

    ', 'after_title' => '

    ', )); */ # Displays a list of popular posts function gtt_popular_posts($num, $pre='
  • ', $suf='', $excerpt=true) < global $wpdb; $querystr = "SELECT $wpdb->posts.post_title,$wpdb->posts.post_date_gmt, $wpdb->posts.ID, $wpdb->posts.post_content FROM $wpdb->posts WHERE $wpdb->posts.post_status = 'publish' AND $wpdb->posts.post_type = 'post' ORDER BY $wpdb->posts.comment_count DESC LIMIT $num"; $myposts = $wpdb->get_results($querystr, OBJECT); foreach($myposts as $post) < echo $pre; ?>
    ID); ?>">post_title ?>
    post_date_gmt . " GMT")), time()) . " ago";> else ?>
    > function get_recent_posts($num) < $recent_posts = wp_get_recent_posts($num); foreach($recent_posts as $post)< ?>
  • '; ?>" />
    ' . $post["post_title"].' ';?>
    else ?>
    > function time_since($older_date, $newer_date = false) < // array of time period chunks $chunks = array( array(60 * 60 * 24 * 365 , 'year'), array(60 * 60 * 24 * 30 , 'month'), array(60 * 60 * 24 * 7, 'week'), array(60 * 60 * 24 , 'day'), array(60 * 60 , 'hour'), array(60 , 'minute'), ); // $newer_date will equal false if we want to know the time elapsed between a date and the current time // $newer_date will have a value if we want to work out time elapsed between two known dates $newer_date = ($newer_date == false) ? (time()+(60*60*get_settings("gmt_offset"))) : $newer_date; // difference in seconds $since = $newer_date - $older_date; // we only want to output two chunks of time here, eg: // x years, xx months // x days, xx hours // so there's only two bits of calculation below: // step one: the first chunk for ($i = 0, $j = count($chunks); $i < $j; $i++) < $seconds = $chunks[$i][0]; $name = $chunks[$i][1]; // finding the biggest chunk (if the chunk fits, break) if (($count = floor($since / $seconds)) != 0) < break; >> // set output var $output = ($count == 1) ? '1 '.$name : "$count s"; // step two: the second chunk if ($i + 1 < $j) < $seconds2 = $chunks[$i + 1][0]; $name2 = $chunks[$i + 1][1]; if (($count2 = floor(($since - ($seconds * $count)) / $seconds2)) != 0) < // add to output var $output .= ($count2 == 1) ? ', 1 '.$name2 : ", $count2 s"; > > return $output; > function get_post_thumbnail($pid) < $files = get_children('post_parent='.$pid.'&post_type=attachment&post_mime_type=image'); if($files) : $keys = array_reverse(array_keys($files)); $j=0; $num = $keys[$j]; $image=wp_get_attachment_image($num, 'large', false); $imagepieces = explode('"', $image); $imagepath = $imagepieces[1]; $thumb=wp_get_attachment_thumb_url($num); print $thumb; else: echo bloginfo('template_directory')."/images/smallimg.jpg"; endif; >function get_post_thumbnails() < $files = get_children('post_parent='.get_the_ID().'&post_type=attachment&post_mime_type=image'); if($files) : $keys = array_reverse(array_keys($files)); $j=0; $num = $keys[$j]; $image=wp_get_attachment_image($num, 'large', false); $imagepieces = explode('"', $image); $imagepath = $imagepieces[1]; $thumb=wp_get_attachment_thumb_url($num); print $thumb; else: echo bloginfo('template_directory')."/images/smallimg.jpg"; endif; >?>
  • Источник

    Saved searches

    Use saved searches to filter your results more quickly

    You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

    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

    FastCGI sent in stderr: «PHP message: PHP Parse error: syntax error, unexpected ‘?’, expecting variable (T_VARIABLE) #20635

    FastCGI sent in stderr: «PHP message: PHP Parse error: syntax error, unexpected ‘?’, expecting variable (T_VARIABLE) #20635

    Comments

    Preconditions (*)

    **We are using AWS Cloudformation template which was supported for Magento 2.1 but we have manually upgraded it to Magento 2.3.0. I am not sure how this can affect. **

    Upgraded Magento 2.1.16 to Magento 2.3.0, I am getting an error on the browser HTTP 500 but i can see the request on nginx.

    2019/01/26 06:44:59 [error] 12354#0: *1 FastCGI sent in stderr: «PHP message: PHP Parse error: syntax error, unexpected ‘?’, expecting variable (T_VARIABLE) in /var/www/html/vendor/magento/framework/Filesystem/Directory/Write.php on line 35» while reading response header from upstream, client: 10.0.157.172, server: www.example.com, request: «GET / HTTP/1.1», upstream: «fastcgi://unix:/tmp/php-cgi.socket:», host: «binaryhat.com»

    If i remove the ? new error occurs in Read.php

    image

    The text was updated successfully, but these errors were encountered:

    Источник

    Unable to send php7.3 fpm-alpine error logs to std within docker containers

    I cannot get the php-fpm error logs appear in docker std. So far I’ve tried many suggestions but for some reason no progress at all. I am posting my whole setup so that someone could kindly help me to right direction. All I see is app_php_1 | 172.21.0.7 — 06/Apr/2019:12:26:37 +0000 «GET /index.php» 500 PHP-FPM Dockerfile

    FROM php:7.2.13-fpm-alpine3.8 RUN apk update \ && apk add --no-cache $PHPIZE_DEPS \ bash git zip unzip RUN docker-php-ext-install opcache RUN docker-php-ext-enable opcache RUN rm -rf /var/cache/apk/* COPY php.ini /usr/local/etc/php/conf.d/php.override.ini COPY www.conf /usr/local/etc/php-fpm.d/www.conf WORKDIR /app CMD ["php-fpm", "--nodaemonize"] 
    [php] date.timezone=UTC log_errors=On error_reporting=E_ALL & ~E_DEPRECATED & ~E_STRICT display_errors=Off max_execution_time=60 memory_limit=256M [opcache] opcache.enable_cli=1 opcache.memory_consumption=256 opcache.max_accelerated_files=20000 realpath_cache_size=4096K realpath_cache_ttl=600 
    [global] daemonize=no [www] user=www-data group=www-data listen=app_nginx:9000 pm=dynamic pm.max_children=30 pm.start_servers=2 pm.min_spare_servers=2 pm.max_requests=1000 
    FROM nginx:1.15.8-alpine RUN apk add --no-cache bash RUN rm -rf /var/cache/apk/* COPY app.conf /etc/nginx/conf.d/default.conf COPY nginx.conf /etc/nginx/nginx.conf COPY app_ssl.crt /etc/ssl/certs/app_ssl.crt COPY app_ssl.key /etc/ssl/private/app_ssl.key 
    server < listen 80; server_name localhost; root /app/public; listen 443 default_server ssl; ssl_certificate /etc/ssl/certs/app_ssl.crt; ssl_certificate_key /etc/ssl/private/app_ssl.key; location / < try_files $uri /index.php$is_args$args; >location ~ ^/index\.php(/|$) < fastcgi_pass app_php:9000; fastcgi_split_path_info ^(.+\.php)(/.*)$; fastcgi_hide_header X-Powered-By; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; fastcgi_param DOCUMENT_ROOT $realpath_root; internal; >location ~ \.php$ < return 404; >> 
    user nginx; worker_processes 2; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events < worker_connections 1024; use epoll; >http < include /etc/nginx/mime.types; default_type application/octet-stream; log_format json_combined escape=json ''; access_log /var/log/nginx/access.log json_combined; fastcgi_buffers 8 16k; fastcgi_buffer_size 32k; fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; server_tokens off; add_header X-Content-Type-Options nosniff; add_header X-XSS-Protection '1; mode=block'; add_header X-Frame-Options DENY; add_header Strict-Transport-Security 'max-age=31536000; includeSubdomains; preload'; add_header 'Referrer-Policy' 'no-referrer-when-downgrade'; types_hash_max_size 2048; gzip on; include /etc/nginx/conf.d/*.conf; > 
    version: "3" services: app_php: build: context: "./php" volumes: - "../. /app:consistent" app_nginx: build: context: "./nginx" ports: - "5080:80" - "5443:443" volumes: - "../. /app:consistent" depends_on: - "aapp_php" 
    • Changed /proc/self/fd/2 to /dev/stdout / /dev/stderr for error_log and access.log properties in /usr/local/etc/php-fpm.d/docker.conf file.
    • Added code below at the bottom of www.conf file.
    catch_workers_output = yes php_flag[display_errors] = off php_admin_flag[log_errors] = on php_admin_value[error_log] = /var/log/php-fpm-error.log php_admin_value[error_log] = /dev/stdout php_admin_value[error_log] = /dev/stderr 

    Источник

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