问题
I am struggling to install Laravel on the AWS free tier Ubuntu instance. It gets stucks on the Composer installation due to a memory limit.
I initially ran the following commands:
sudo apt update && sudo apt upgrade
sudo apt install php7.2-common php7.2-cli php7.2-gd php7.2-mysql php7.2-curl php7.2-intl php7.2-mbstring php7.2-bcmath php7.2-imap php7.2-xml php7.2-zip
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
composer --version
composer create-project --prefer-dist laravel/laravel my_app
I set the storage limit to 30gb in the instance. I tried to find a solution and everybody suggested to set the Composer limit to =-1
. It still didn't resolve my issue.
I got this error when installing packages with Composer:
composer updating dependencies (including require-dev) killed
I tried to find the memory limit like this:
php -r "echo ini_get('memory_limit').PHP_EOL;"
It showed -1.
I also got this memory information:
It showed the memory limit as 128M. Is my issue due to this? If yes, then how can I increase the memory?
I just wanted to know that can we install Laravel with Composer on the free tier. I am not understanding everything clearly on this matter or is it any other configuration issue?
回答1:
Yes, we can.
I verified that on AWS using t2.micro Ubuntu 18.04 with 30GB (don't need 30GB, but I used what you have).
For laravel
installation, the following command was used:
composer global require laravel/installer
And also got memory error:
The following exception is caused by a lack of memory or swap, or not having swap configured
Check https://getcomposer.org/doc/articles/troubleshooting.md#proc-open-fork-failed-errors for details
In Process.php line 344:
proc_open(): fork failed - Cannot allocate memory
Based on the message, I added 1GB of swap by following these steps.
Once the swap was setup, I executed laravel
installation command again and this time it worked.
I tested newly installed laravel
by generating its standard blog
project:
composer create-project --prefer-dist laravel/laravel blog
The command worked:
Installing laravel/laravel (v7.12.0)
- Installing laravel/laravel (v7.12.0): Loading from cache
Created project in blog
> @php -r "file_exists('.env') || copy('.env.example', '.env');"
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 92 installs, 0 updates, 0 removals
#
# not shown
#
Package manifest generated successfully.
> @php artisan key:generate --ansi
Application key set successfully.
Hope this helps.
p.s.
Installing php
and various php
extensions were also required.
回答2:
Rob suggested this previously:
Download an existing composer.lock
file from your git project. Then install Composer in same location. If you don't have a composer.lock
file in your git repository, first push it to git from your development environment. Thanks Rob.
来源:https://stackoverflow.com/questions/62043063/how-to-install-laravel-on-aws-free-tier