字體:  

在 AWS AMI EC2安裝 PHP7.1+Laravel Composer+MongoDB+Swagger

dyson6 發表於: 2017-11-03 08:51 來源: ADJ網路控股集團


AMI(Amazon Machine Images)說得簡單一點的話,其實就是映象檔(Image),它可以將目前的EC2做快速的複製.
如果要使用安裝 PHP7.1+Laravel Composer+MongoDB.可以這樣安裝~


(1)安裝 PHP7.1
# yum install php71*

(2)安裝 composer
# curl -sS https://getcomposer.org/installer | sudo php
# mv composer.phar /usr/local/bin/composer
# ln -s /usr/local/bin/composer /usr/bin/composer

(3)安裝Laravel mongodb Driver
# yum install php7-pear php7-devel gcc openssl-devel git
# pecl7 install mongodb
# echo "extension=mongodb.so" > /etc/php.d/mongodb.ini

在Laravel項目中安裝swagger-php:
# composer require zircote/swagger-php

(4)安裝mongodb 3.4 server
請建立 /etc/yum.repos.d/mongodb-org-3.4.repo 檔案,並加入以下內容:

QUOTE:


[mongodb-org-3.4]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/amazon/2013.03/mongodb-org/3.4/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.4.asc


# yum install mongodb-org mongodb-org-server

啟動 mongod service
# service mongod start

這樣就可以囉~~

安裝過程有出現一些狀況...可以這樣解~
問題(一):
Laravel composer install 出現這個問題:
PHP Composer update “cannot allocate memory” error (using Laravel 5.3)
proc_open() fork failed - cannot allocate memory composer

解法(增加swap空間):
# /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024
# /sbin/mkswap /var/swap.1
# /sbin/swapon /var/swap.1

問題(二): 幫 git 加上 Auto Complete
# curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash -o ~/.git-completion.bash

Next, add the following lines to your .bash_profile.

QUOTE:


if [ -f ~/.git-completion.bash ]; then
  . ~/.git-completion.bash
fi


參考文章:
https://stackoverflow.com/questions/18116261/php-composer-update-cannot-allocate-memory-error-using-laravel-4
http://code-worrier.com/blog/autocomplete-git/