LoginSignup
1
1

More than 5 years have passed since last update.

AWS EC2、Cloud9、Laravel5.7環境でide-helperをインストール

Last updated at Posted at 2019-02-06

環境

Amazon Linux EC2 t2.micro
Laravel Framework 5.7.22
PHP 7.2.13
Apache 2.4.37
mysql 5.7.23

ide-helperのインストール

コマンドなどは [Laravel] IDEによるコード補完まとめ を参考にさせていただきました。

$ composer require --dev barryvdh/laravel-ide-helper

失敗

Cannot allocate memoryが発生

mmap() failed: [12] Cannot allocate memory

mmap() failed: [12] Cannot allocate memory
PHP Fatal error:  Out of memory (allocated 569384960) (tried to allocate 16777224 bytes) in phar:///usr/local/bin/composer/src/Composer/DependencyResolver/RuleSet.php on line 83

Fatal error: Out of memory (allocated 569384960) (tried to allocate 16777224 bytes) in phar:///usr/local/bin/composer/src/Composer/DependencyResolver/RuleSet.php on line 83

対処

かなり時間を使ってしまいました。もともとphp.iniの設定で2Gも割り当てていたし、過去にスワップファイルを設定していたので、なんでメモリ割当ができないのか謎でした。
一旦、下記のように対処しました。※以前の手順を参考

/etc/php.ini
memory_limit = -1
# apache再起動
$ sudo systemctl restart httpd

#確認
$ php -r 'phpinfo();' | grep memory_limit

memory_limit => 512M => 512M
# スワップファイルの作成
$ sudo -s /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024

$ sudo -s /sbin/mkswap /var/swap.1
$ sudo -s /sbin/swapon /var/swap.1

成功しました

念のためcomposerをupdate。

$ composer update

Package manifest generated successfully.
$ composer require --dev barryvdh/laravel-ide-helper

Package manifest generated successfully.

後から

よく考えたら、スワップファイルは一時的であるような気がしました。
確認してみたら、やっぱりスワップファイル作成後&作業完了時点ですが、スワップファイルの割当がされています。

$ sudo vmstat

#スワップファイル作成前
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 0  1      0 625124      0  85640    0    0    17     6   33  168  0  0 100  0  0


#スワップファイル作成後&作業完了後
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 0  0 115200 656136      0 146036    0    1    33    17   47  186  0  0 100  0  0

補完ファイルの作成

app/config/app.phpのservice providerの箇所に追記

config/app.php
'providers' => array(
    // ↓ 下記を追記 ↓
    'Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider', 
),

Facade の補完

IDEに読み込ませるとFacadeのコード補完ができるようになるみたい。

$ php artisan ide-helper:generate
A new helper file was written to _ide_helper.php

modelプロパティーの補完

仕組み的には doctrine/dbal を使い実際にデータベースにアクセスして各テーブルのカラムを判別しコードに落としているらしい。

$ php artisan ide-helper:model

Do you want to overwrite the existing model files? Choose no to write to _ide_helper_models.php instead? (yes/no) [no]:
 > 何も指定しない

Model information was written to _ide_helper_models.php

設定できたのでこれからがしがし活用していきたい。

本当はPHP Stormを使ってみたい

ここで紹介されているような機能を使えたら嬉しいので、今後要検討。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1