phplaravellaravel-artisanserve

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


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.


Solution

  • 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.

    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','')
    ],