How to install Laravel on AWS free tier? [duplicate] - laravel

This question already has an answer here:
Server composer install --no-dev killed
(1 answer)
Closed 2 years ago.
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?

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.

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.

Related

composer require laravel/dusk error

I am trying to install Laravel/Dusk on a laravel 5.4 application.
The command that I am running is, according to the documentation: https://laravel.com/docs/5.4/dusk
composer require laravel/dusk
The output in terminal:
Using version ^1.0 for laravel/dusk
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
- Installing facebook/webdriver (1.3.0)
Loading from cache
- Installing laravel/dusk (v1.0.10)
Downloading: 100%
Killed
That Killed is what's bothering. So, the package is being added to my composer.json file but no files can be found in vendor/laravel/dusk
I am trying to install this on my webhost and not on my local environment.
Any ideas?
The error is due to your machine on the host running out of memory, like described on this thread: https://github.com/composer/composer/issues/1815
So you may have to increase the performance on your account to be able to run more composer commands from your webhost.

Composer doesn't run in presence of composer.json

I installed composer globally on my Debian server
~$ which composer
/usr/local/bin/composer
It works, gets updated and I used it for three different (Symfony) sites.
~$ composer self-update
You are already using composer version 1.3.3 (stable channel).
However, when I am in the directory of one of the sites, and try to update all dependencies, I get an error (before, this just worked and updated the vendors etc).
~/website-path$ ls composer.*
composer.json composer.lock
~/website-path$ composer update
[ErrorException]
Illegal string offset 'version'
~/website-path$ composer
[ErrorException]
Illegal string offset 'version'
When I rename composer.json, this Error disappears (but the lack of .json file makes this quite useless)
What went wrong here and how can I fix this?
The problem magically went away overnight by upgrading to 1.4.0
~$ composer -V
Composer version 1.4.0 2017-03-08 17:51:24
~/website-path$ composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
[...]

Why Travis CI can't connect to GitHub API?

I'm running the following commands in Travis CI for my build:
before_install:
- curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
script:
- sudo composer -nqq update
I'm installing composer manually as I want to use sudo with it, as it's installed only for the user.
The error which I'm having are:
Updating dependencies (including require-dev)
- Installing jakub-onderka/php-console-color (0.1)
Downloading: Connecting... Failed to download jakub-onderka/php-console-color from dist: The "https://api.github.com/repos/JakubOnderka/PHP-Console-Color/zipball/e0b393dacf7703fc36a4efc3df1435485197e6c1" file could not be downloaded (HTTP/1.1 403 Forbidden)
Now trying to download from source
- Installing symfony/yaml (v2.7.4)
Downloading: Connecting... Failed to download symfony/yaml from dist: The "https://api.github.com/repos/symfony/Yaml/zipball/2dc7b06c065df96cc686c66da2705e5e18aef661" file could not be downloaded (HTTP/1.1 403 Forbidden)
Now trying to download from source
I've tried these links and they work fine.
Does it mean Travis is blocking GitHub API for some reason? If not, how do I fix it?
By fix, I mean either to know what's going on, or suppress these error messages (e.g. by using some special parameter in composer or changes to JSON file to force downloads from the source).
My composer.json file is:
{
"config": {
"vendor-dir": "/var/lib/vendor",
"bin-dir": "/usr/local/bin"
},
"require": {
"drush/drush": "dev-master"
}
}
For the reference, the full .travis.yml looks like:
before_install:
- env
- curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
- sudo apt-get -qy update
install:
- sudo apt-get install vagrant
script:
- set -e # This makes build to fail on first error.
- sudo composer -nqq update
- make
- make vm
after_failure:
- sudo apt-get -qy install tree && - tree -d -L 6 # Print directory structure in the form of a tree.
- env
sudo: true
language: php
python:
- "5.5"
Most probable reason for the error is limited amount of downloads from github. What you need to do is create a token in your github account and add it globally to your composer with
composer config -g github-oauth.github.com <your-token>
Source: https://getcomposer.org/doc/articles/troubleshooting.md#api-rate-limit-and-oauth-tokens
My suggestions are:
Remove:
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
sudo composer -nqq update
First line: not needed, because Composer is pre-installed, when you use language: php.
Second line: its better to execute composer install, because update uses the data from composer.lock if your repo contains one. And sudo is not needed here.
(Sidenote on the usage of sudo on Travis-CI:
sudo is only available in the non-containainer based infrastructure. I don't know if you really need this, but maybe you could switch to the faster container based infrastrucutre by setting sudo: false in your travis.yml, see http://docs.travis-ci.com/user/workers/container-based-infrastructure/ . Just a hint.)
Add to travis.yml
before_install:
- composer self-update
- composer install --no-interaction --optimize-autoloader
First line: update the (possibly) outdated composer of this Travis instance.
Second line: install dependencies described in composer.json with Composer.
The additional parameters to switch between downloading "Dist" or downloading "Source" are --prefer-dist and --prefer-source.
So its either
- composer install --prefer-dist --no-interaction --optimize-autoloader
or
- composer install --prefer-source --no-interaction --optimize-autoloader
Does it mean Travis is blocking GitHub API for some reason?
If its not a temporary issue, then its seems your Composer is running into the Github API rate-limit. The GitHub API allows only a low number of requests for unauthenticated users. You can raise the API limit by authenticating at Github from Travis.
See FAQ: https://getcomposer.org/doc/articles/troubleshooting.md#api-rate-limit-and-oauth-tokens
Please try it with prefer-source first.

What does the different flags of Composer when creating a Laravel project?

Anyone can tell me the difference between this commands
composer create-project laravel/laravel your-project-name --prefer-dist
composer create-project laravel/laravel your-project-name
composer create-project laravel/laravel your-project-name -dev
From the documentation for composer:
--prefer-dist: Reverse of --prefer-source, composer will install from dist if possible. This can speed up installs substantially on build servers and other use cases where you typically do not run updates of the vendors. It is also a way to circumvent problems with git if you do not have a proper setup.
That means Composer will install the dependencies from the distribution build, instead of the sources.
And for the --dev flag:
--dev: Install packages listed in require-dev.
That means Composer will also install all package dependencies list in require-dev key from your composer.json. The require-dev key are dependences only required for development.
Please, for more information, read the docs regarding Composer CLI: https://getcomposer.org/doc/03-cli.md#create-project

Installing laravel and composer on Debian 6

I want to use laravel, so, firstly I have to install composer, I uploaded laravel in a folder "laravel" now i go to the folder and I do this
curl -sS https://getcomposer.org/installer | php
according the site of composer...
So, now, according laravel I should do this
composer create-project laravel/laravel
but returns "composer command not found"
When I finished installing composer I get this Use it: php composer.phar
So, I try again php composer.phar create-project laravel/laravel
and it runs,but it stays as Installing dependencies (incluiding require-dev) for a long long time.
My enviroment is Debian 6, and its a cloud server, so, internet should not be a problem.
It just stays like that, any idea what I'm doing wrong? How to solve this and make it run?
Thanks
$ curl -sS https://getcomposer.org/installer | php
$ mv composer.phar /usr/local/bin/composer
# if you're installing as root or privileged account, don't leave the permissions on default 777
$ chmod 755 /usr/local/bin/composer
$ composer install

Resources