Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

eggplantSword's avatar

500 error when updating server, getting unexpected '?' error

I updated my laravel project to a server using cpanel and then it wouldn't load and I get the 500 error, and not even the Laravel 500 like the This page isn't working 500 error page. I checked the project's errors logs and found that on the error_log I see this error

[10-Jul-2020 11:35:46 America/New_York] PHP Parse error:  syntax error, unexpected '?' in /home/vcubed/public_html/encuestas/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php on line 500

I've checked the project php version by doing php -v which returns

PHP 7.1.33 (cli) (built: Jul  8 2020 18:57:25) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies

And in the MultiPHP Manager the subdomains php version is also 7.1.

How can I fix this error?

0 likes
30 replies
bobbybouwmann's avatar

It seems that your application is not running PHP 7.+. The cli version which you check with php -v can be different from the one that is running for your webserver.

bobbybouwmann's avatar

Run phpinfo() in php artisan tinker or in one of your views. However, it will probably not get there because you still have this error.

In most cases, you can just override the index.php in the public directory with the following content. Then you can see it

<?php

phpinfo();
eggplantSword's avatar

@bobbybouwmann I have a file with that code in the server /public_html/info.php but I'm unsure how to reach it. I tried www.url.com/public_html/info.php but I get a 404, in my public_html there isn't a index.php

bobbybouwmann's avatar

Mmh, it might be an actual code error but in general, this is a PHP error.

How did you run composer install? It could be that it has a version that only supports PHP 5.6 in the composer.lock file and therefore it can't install the correct package. Try running composer update using the correct PHP version.

eggplantSword's avatar

@bobbybouwmann I usually can't just do composer update because for some reason it always gives me errors, so I usually install composer in each project on the server and use a composer.phar instead, but that one is updated and I tried the normal composer update and I get this error

[13-Jul-2020 10:48:42 America/New_York] PHP Fatal error:  Allowed memory size of 1610612736 bytes exhausted (tried to allocate 268435456 bytes) in phar:///home/vcubed/composer.phar/src/Composer/DependencyResolver/Solver.php on line 223

When googling this error I ran this command php -r "echo ini_get('memory_limit').PHP_EOL;" the returned value is 128M, since this is on a server I'm not sure what would be an appropriate size or amount

bobbybouwmann's avatar

You probably need to update it to 256M or 512M.

Another option is running it without memory limit like so

php -d memory_limit=-1 /path/to/composer update
eggplantSword's avatar

@bobbybouwmann I tried doing this command COMPOSER_MEMORY_LIMIT=-1 composer update but the issue is the server itself has php 5.6 and has old projects on it that I don't know if they would be affected by changing the php version (also it's not up to me to change the server php version), that's why I have the subdomain php version as 7.1 for this project. So I'm not sure if that is affecting, the weird thing is I can update the composer.phar no problem which is supposedly the one the project is using. I'm not sure what I can do?

bobbybouwmann's avatar

Yeah, well this is the problem right away. You need PHP 7 to make this work.

But it seems to me that you run multiple PHP versions on the server. You just need to find the path to the PHP 7 executable and then you can use that for php composer update and so on.

eggplantSword's avatar

@bobbybouwmann I'm so confused because before the project update this wasn't an issue, I didn't even add a new dependency or library to need to update the composer. I tried to do a get request with inertia-vue and got a 500 error and after reloading it shut down the page basically. That's when I looked around for the error but realistically I didn't need to mess with the composer to begin with.

When I check the different php versions on the project they all say it's using php 7.1

bobbybouwmann's avatar

I really can't help you any further without more information. You should probably ask the person who manages the server to see if they have more information for you

BryanK's avatar

Try to find the path to the newer php version, then use that path with the composer line bobby posted.

Your info.php should tell you the path. You can also try: which php from cli.

Example path:

/usr/local/php7.1/bin/php

So that will turn into:

/usr/local/php7.1/bin/php -d memory_limit=-1 /path/to/composer update
eggplantSword's avatar

@bryank when I run the command I get this /usr/local/bin/php , how can I tell if the other php7.1 file exists?

BryanK's avatar

Type this to see what that version is:

/usr/local/bin/php -v

bobbybouwmann's avatar

@msslgomez It's probably in /usr/local/bin/php7.1 or somewhere else. Run phpinfo() in your index.php file and it should show you the correct location.

eggplantSword's avatar

@bryank it returns 7.1.33 (cli) and @bobbybouwmann I'm looking and on the Core part, I see this line, I'm not sure if that's what you're referring to

include_path	.:/usr/lib/php:/usr/local/lib/php	.:/usr/lib/php:/usr/local/lib/php
BryanK's avatar

Ok. I suggest deleting your vendor folder and running composer install again.

eggplantSword's avatar

@bryank I did and reinstalled it, like I said to bobby I use a composer.phar file that I download from the composer website I don't use the normal composer commands because those give me errors. I reinstalled it using php composer.phar install and that still didn't change the 500 error page.

BryanK's avatar

Sorry, little confused. Are you getting an error with composer or a 500 error when you visit the site?

BryanK's avatar

Does cpanel know that the root of the site is public_html/encuestas not public_html?

If not set, move all the files to the root of public_html.

eggplantSword's avatar

@bryank essentially both (I think), but I think the 500 error when I visit the site is caused by something messed up somewhere maybe the composer, the thing is the composer and php versions on the project are all "working" when I use the local composer file for the project composer.phar I can install it, update it with no problems. The global composer however does have problems as bobby said because of the servers system php version (5.6) so I can't use the regular composer commands only the php composer.phar commands. This usually isn't an issue but the page has also never showed a 500 error page like this before.

With the second comment, there are like 10+ projects on this server I can't move the files straight into the public_html, and yea this project is on a subdomain as it was working before with no issues

BryanK's avatar

This seems like a server configuration error if you're getting a server 500 (not a laravel one). I guess my only advice now is to make sure that the directory for the subdomain is setup correctly.

Should be public_html/encuestas/public so that index.php is in the root.

eggplantSword's avatar

@bobbybouwmann I did but they said nothing was wrong. I think discovered the trigger, I have a page where I try filtering some data which works locally but on the server it returns a 500 server error and causes the page to crash for around 2 hours every time I try to execute the getFiltered function. I don't know what is going on, I made a question about it here https://laracasts.com/discuss/channels/requests/get-request-on-server-returning-500-error.

But I'll elaborate here. Basically I have this function, after I set the returned data to the variable survey_question I do a bunch of stuff to the data but that shouldn't matter as I work on the data that returned as it's saved in the survey_question and not from where it's coming from.

getFiltered() {
     this.$inertia.replace('/result/filter', {
         method: 'get',
         data: {
             period: this.filters.period_id,
             major: this.filters.major_id,
             course: this.filters.course_id,
             school: this.filters.school
         }
     })
         .then(() => {
             if (this.$page.auth.user.flash.success) {
                 this.survey_question = this.$page.auth.user.flash.success[0];
        },
}

This crashes the site every time I try and execute it and returns this error, with any of the filters data in the url, this case the search was empty but the ids would be the variables sent

GET http://url.com/result/filter?period=&major=&course=&school= 500 (Internal Server Error)

I tried removing the data portion on the get to see if that was affecting it somehow but that didn't work (it still crashed), I've never got this error on the server before so I'm not sure why this function is triggering it. The process in the route and controller is like this

Route::get('result/filter', 'ResultController@filter');

//controller
 public function filter(Request $request)
    {
        $filtered = $this->search($request);

        if (empty($filtered)) {
            return back()->with('info', 'No results!');
        }

        $items[] = $filtered;
        return back()->with('success', $items);
    }

 public function search(Request $request)
    {
       //do a bunch of searches here
       $filtered = $this->modify_filter(data from search);

        if (!empty($filtered)) {
            return $filtered;
        } else {
            return $filtered = null;
        }

    }

public function modify_filter(\Illuminate\Database\Eloquent\Collection $array)
    {
        //format $array and save to $items

        return $items;
    }

The reason I use 3 functions in the controller is that I needed to separate the search from the actual filter function because I also need to search for an excel download and the search code is very long so I don't want to copy/paste it in another method.

I don't know how even to try and figure this out when every time I try to execute the getFiltered() I get a crashed page for 2 hours.

Any ideas on what I can try?

BryanK's avatar

Does laravel log the error before the site crashes?

Does the server log anything in error_log?

eggplantSword's avatar
eggplantSword
OP
Best Answer
Level 9

@bryank It seems to have been a problem with the php.ini file after the server admin changed the memory to -1 and the post_max_size to 128MB, and I also changed the route from get to post and now it's not crashing anymore. Thanks to you and @bobbybouwmann for all your help!

Please or to participate in this conversation.