1

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.

Community
  • 1
  • 1
user228
  • 67
  • 2
  • 10

4 Answers4

0

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.

Gravy
  • 12,264
  • 26
  • 124
  • 193
  • 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 '17 at 20:27
0

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

  1. Check your php.ini to confirm your memory limits (memory_limit = ?)
  2. 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)
AlphaZygma
  • 228
  • 2
  • 9
  • 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 '17 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 '17 at 22:33
0

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.

  1. Root is pointed to /public folder
  2. Run composer install. You may be missing some vendor folders
  3. Permissions of /storage are 777. /storage/logs/laravel.log <- here you will find your real error.
  4. Make sure to create .env aka a copy of .env.example
  5. 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','')
],
BlueYama
  • 44
  • 4
  • Thanks @user3029357 . you get the right direction for this. looks like there was something wrong with the hosting setting. – user228 Mar 15 '17 at 20:26
  • 1
    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 '17 at 11:59
  • Thanks @BlueYama I tried to vote for but the system told me I don't have enough reputation. – user228 Mar 18 '17 at 14:09
  • I had the same issue on a brand new laravel project, just set up without any own code. It turned out that the permissions on /storage were the reason. Thank you for this helpful article! – Andreas Jul 10 '23 at 18:38
0

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.

Tim Groeneveld
  • 8,739
  • 3
  • 44
  • 60