our client using NGINX with php 7.0.33-1. after deployed automad to NGINX I got 502 Bad Gateway in pages (index.php) but dashboard is working. I debug automad code and see preg_replace_callback make automad not working on this server.
who also encounters errors like me?
also I test this code on server and get same 502.

<?php
$str = "<@ snippets/header.php @>
	<@ snippets/videoj.php @>
	<@ snippets/thebook.php @>
	<@ snippets/theicons.php @>
	<@ snippets/the-author.php @>
	<@ snippets/thc-reviews.php @>
	<@ snippets/thc-press.php @>
	<section class=\"thc-davos\">
	<div class=\"container\">
	<div class=\"row\">
	<@# with '/davos' @>
	<@ snippets/has-popup.php @>
	<@# end @>
	</div>
	</div>
	</section>
	<section class=\"thc-video-playlist\">
	<div class=\"container\">
	<div class=\"row\">
	<@ set { %listKeys: 'PL5WW3f45kHqiBy8uCEWuvaG7XWY9Rm3t-', %namePlaylist: 'Gathering of Minds Interviews' } @>
	<@ snippets/videoplaylist.php @>
	</div>
	</div>
	</section>
	<@ snippets/videosLibs.php @>
	<@ snippets/footer.php @>";

$reg = "((?P<var>(@\{\s*([%:\?\w\.\-]+)\s*((?:\|(\s*([\w][\w\-]*)\s*(?:\((\s*("(?:[^"\\]|\\.)*+"|'(?:[^'\\]|\\.)*+'|\w+|\d+(?:\.\d+)?|(?-7))\s*(?:,\s*("(?:[^"\\]|\\.)*+"|'(?:[^'\\]|\\.)*+'|\w+|\d+(?:\.\d+)?|(?-8))\s*)*?)?\)\s*)?|\s*([\+\-\*\/])\s*(\d+(?:\.\d+)?|(?-10))\s*))*)\}))|\<@\s*(?:(?P<file>[\w\/\-\.]+\.[a-z0-9]{2,5})|(?P<call>[\w\/\-]+)\s*(?P<callOptions>\{.*?\})?|#\s*snippet\s+(?P<snippet>[\w\-]+)\s*@\>(?P<snippetSnippet>.*?)\<@#\s*end|#\s*with\s+(?P<with>"[^"]*"|'[^']*'|(@\{\s*([%:\?\w\.\-]+)\s*((?:\|(\s*([\w][\w\-]*)\s*(?:\((\s*("(?:[^"\\]|\\.)*+"|'(?:[^'\\]|\\.)*+'|\w+|\d+(?:\.\d+)?|(?-7))\s*(?:,\s*("(?:[^"\\]|\\.)*+"|'(?:[^'\\]|\\.)*+'|\w+|\d+(?:\.\d+)?|(?-8))\s*)*?)?\)\s*)?|\s*([\+\-\*\/])\s*(\d+(?:\.\d+)?|(?-10))\s*))*)\})|prev|next)\s*(?P<withOptions>\{.*?\})?\s*@\>(?P<withSnippet>.*?)(?:\<@#\s*else\s*@\>(?P<withElseSnippet>.*?))?\<@#\s*end|#\s*for\s+(?P<forStart>(@\{\s*([%:\?\w\.\-]+)\s*((?:\|(\s*([\w][\w\-]*)\s*(?:\((\s*("(?:[^"\\]|\\.)*+"|'(?:[^'\\]|\\.)*+'|\w+|\d+(?:\.\d+)?|(?-7))\s*(?:,\s*("(?:[^"\\]|\\.)*+"|'(?:[^'\\]|\\.)*+'|\w+|\d+(?:\.\d+)?|(?-8))\s*)*?)?\)\s*)?|\s*([\+\-\*\/])\s*(\d+(?:\.\d+)?|(?-10))\s*))*)\})|\d+(?:\.\d+)?)\s+to\s+(?P<forEnd>(@\{\s*([%:\?\w\.\-]+)\s*((?:\|(\s*([\w][\w\-]*)\s*(?:\((\s*("(?:[^"\\]|\\.)*+"|'(?:[^'\\]|\\.)*+'|\w+|\d+(?:\.\d+)?|(?-7))\s*(?:,\s*("(?:[^"\\]|\\.)*+"|'(?:[^'\\]|\\.)*+'|\w+|\d+(?:\.\d+)?|(?-8))\s*)*?)?\)\s*)?|\s*([\+\-\*\/])\s*(\d+(?:\.\d+)?|(?-10))\s*))*)\})|\d+(?:\.\d+)?)\s*@\>(?P<forSnippet>.*?)\<@#\s*end|#\s*foreach\s+in\s+(?P<foreach>pagelist|filters|tags|filelist|"[^"]*"|'[^']*'|(@\{\s*([%:\?\w\.\-]+)\s*((?:\|(\s*([\w][\w\-]*)\s*(?:\((\s*("(?:[^"\\]|\\.)*+"|'(?:[^'\\]|\\.)*+'|\w+|\d+(?:\.\d+)?|(?-7))\s*(?:,\s*("(?:[^"\\]|\\.)*+"|'(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s*))*)\}))))*)\s*@\>(?P<ifSnippet>.*?)(?:\<@#\s*else\s*@\>(?P<ifElseSnippet>.*?))?\<@#\s*end)\s*@\>)";

$a = preg_replace_callback('/'.$reg.'/is', function($m){
	print_r($m);
}, $str);

echo $a;
  • mad replied to this.

    hoangloi Hi, is this a template you use? And does it work on another server? I’m not sure it’s related to Nginx. Could you please elaborate a bit more?

    I guess this issue from php version. Because when i switch to another use php 7.2 or 7.3, it's work.
    Code is example when preg_replace_callback use value from automad, I get it from automad/core/view.php. it's mean php 7.0.33 not work with preg_replace_callback with value from automad, maybe format of $str make automad not work. This leads to Automad not working.

    • mad replied to this.

      hoangloi All versions of PHP from 5.4+ are tested and working. Maybe your PHP binary was compiled without some features? I think it’s not related to the version.

        hoangloi Hi, thanks. Do you have also a site where i can see the error message?

        hoangloi Hi, but that’s just a server configuration problem and not related to a CMS. Does it work on another machine?

          mad sever's man configuration same on another but run php 7.3 or 7.2, it's work. only not work on this sever. I'm reappearing php7.0.33 install on my Mac. I hope it's work and problem from sever configuration.

          Newest Discussions