Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Second laravel project(v5.4) PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 262144 bytes)

Ask Question

this is my second laravel project running on the same machine. the first works just fine.

I use xampp for the projects.

after I install another fresh new version(5.4) laravel, when I run

artisan serve

phpstorm tell me

PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 262144 bytes) in E:\xampp\htdocs*****\vendor\laravel\framework\src\Illuminate\Container\Container.php on line 549

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 262144 bytes) in E:\xampp\htdocs*****\vendor\laravel\framework\src\Illuminate\Container\Container.php on line 549

Process finished with exit code 255 at 13:58:28. Execution time: 4,976 ms.

I tried other post about this, and tried to change php.ini. It does not apply to my case.

You must have some kind of bug in your code - e.g. circular reference or other error. Calling php artisan serve certainly should not use 130+ MB ram.

Fix the bug and try again... php artisan serve should use a max of say 20mb?

If you really want to run the code, then try php -d memory_limit=500M artisan serve which will increase the mem available to php for that particular process.

Thank you for the effort. but,like I said, I did try to increase the memory_limit in the php.ini file which is not working in my case. user228 Mar 15, 2017 at 20:27

Can you explain a bit more of what your project is about?

I ask because that error is directly related to what a single PHP script is trying to load in memory, i.e.: loading a Model or a File, and the resulting object would use more than the memory allowed per script under the php.ini configuration.

Looking at the error, your php.ini is set to have a max script memory usage of 128Mb (134217728 bytes/1024 Kb /1024 Mb) and whatever is loading is trying to load an extra 256Kb.

I'd recommend two things

  • Check your php.ini to confirm your memory limits ( memory_limit = ? )
  • Provide the full stack trace so we can help you diagnose ( I'm guessing the container is trying to load a model from DB, and the data size is quite large that when loaded, it goes over the limit stablished )
  • The project is clean laravel I just downloaded from laravel server. Like I said, I tried to change the memory_limit in php.ini but it's not working. Also, what I posted are all I got for the full stack trace. yeah, there is nothing else. user228 Mar 15, 2017 at 20:16 While I think of other alternatives, I have another question. If you set the memory limit to 256Mb, after restarting Apache, does it throw the same error (same number of bytes)? ( If so, then the php.ini you are modifying is not the one read by the application )( which can be a side effect of how XAMPP is configured ) AlphaZygma Mar 15, 2017 at 22:33

    You might want to check your Laravel configuration, and ensure that all the configuration files (inside the config/ directory) are valid PHP.

    I had this issue when my config/app.php file was missing a ' , ' between two array items.

    This doesn't sound like a server setup issue. This is a Laravel setup issue. Increasing memory_limit in the php.ini will not fix the issue in your case. Laravel will commonly throw unhelpful errors if not setup correctly.

    After running composer, make sure before you try to run php artisan serve that you have done the following.

  • Root is pointed to /public folder
  • Run composer install. You may be missing some vendor folders
  • Permissions of /storage are 777 . /storage/logs/laravel.log <- here you will find your real error.
  • Make sure to create .env aka a copy of .env.example
  • Generate a key php artisan key:generate
  • Also be careful that you don't have any spaces when creating your variables in your .env file this will cause problems as well.

  • bad DB_DATABASE=my database name
  • good DB_DATABASE=my_database_name
  • Lastly if you are running something like MAMP you may have to include a UNIX_SOCKET variable in your .env file like so:

    DB_CONNECTION=mysql
    DB_HOST=127.0.0.1
    DB_PORT=3306
    DB_DATABASE=your_database_name_here
    DB_USERNAME=root
    DB_PASSWORD=root
    UNIX_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock
    

    and create the variable in your /config/database.php file

    'mysql' => [
        'driver' => 'mysql',
        'engine' => null,
        'unix_socket'   => env('UNIX_SOCKET','')
                    Thanks @user3029357 . you get the right direction for this. looks like there was something wrong with the hosting setting.
    – user228
                    Mar 15, 2017 at 20:26
                    Currently people are down voting, please explain? I believe its because they think its a server setup question. This is a Laravel question. Increasing memory_limit in the php.ini will not fix this issue. This a common error thrown when Laravel isn't setup correctly.
    – BlueYama
                    Mar 17, 2017 at 11:59
                    Thanks  @BlueYama I tried to vote for but the system told me I don't have enough reputation.
    – user228
                    Mar 18, 2017 at 14:09
            

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.