How to setup Laravel on Cloud 9

Tsubasa Kondo
3 min readJun 8, 2019

--

1. Remove PHP5 and install PHP7

$ rpm -qa | grep php
$ sudo yum remove php56*
$ sudo yum install -y php73
$ sudo yum install -y php73-mbstring
$ sudo yum install -y php73-pdo
$ sudo yum install -y php73-mysqlnd

2. Install Composer

$ curl -sS https://getcomposer.org/installer | php
$ sudo mv composer.phar /usr/bin/composer

3A. Setup RDS (if needed)

1. Services > RDS > Create database (Aurora + MySQL 5.7-compatible)2. Services > RDS > Databases (Writer) > VPC security groups > Inbound > Edit (MYSQL/Aurora [YOUR EC2 LOCAL IP]/32)3. Create database for your app.
$ mysql -u [USER NAME] -h [WRITER DB ENDPOINT] -p
CREATE SCHEMA `[DBNAME]` DEFAULT CHARACTER SET utf8;
CREATE SCHEMA `[DBNAME]_testing` DEFAULT CHARACTER SET utf8;

3B. Setup local MySQL

If you want to use the default MySQL instead of RDS, run the following command.$ rpm -qa | grep mysql
$ sudo yum remove mysql55*
$ sudo yum install -y mysql57-server
$ sudo service mysqld start
$ mysql -u root
CREATE SCHEMA `[DBNAME]` DEFAULT CHARACTER SET utf8;
CREATE SCHEMA `[DBNAME]_testing` DEFAULT CHARACTER SET utf8;

4A. Setup your app (for existing project)

$ git clone [URL] laravel && cd laravel$ cp .env.example .env
Edit ".env" as following.
DB_HOST=[Your DB endpoint]
DB_DATABASE=[Your DB name]
DB_USERNAME=root
DB_PASSWORD=root
$ touch .env.testing
Edit ".env.testing" as following.
DB_HOST=[Your DB endpoint]
DB_DATABASE=[Your DB name]_testing
DB_USERNAME=root
DB_PASSWORD=root
$ composer install
$ php artisan key:generate
$ php artisan migrate --seed
(or php artisan migrate && php artisan db:seed)
$ php artisan migrate --seed --env=testing
(or php artisan migrate --env=testing && php artisan db:seed --env=testing)
$ ./vendor/bin/phpunit

4B. Setup your app (for new project)

$ composer create-project --prefer-dist laravel/laravel laravel
$ cd laravel
$ vi .env

5. git config

$ git config --local user.name "Tsubasa Kondo"
$ git config --local user.email kondows95@gmail.com

extra. Share your app over the Internet (You do not have to do this)

1. Associate Elastic IP to your EC2 local IP.2. Open Security Group of your EC2, then Add Inbound rule (TCP8080 anywhere).3. Sevices > VPC > Subnets > Security Network ACL > Inbound Rules > Edit inbound rules > Add Rule (TPC8080 0.0.0.0/0 ALLOW)4. $ php artisan serve --host=[EC2 LOCAL IP] --port=80805. http://[ELASTIC IP]:8080For more detail:
https://docs.aws.amazon.com/cloud9/latest/user-guide/app-preview.html

--

--

Tsubasa Kondo

I am a Japanese software developer living in Mandalay (Myanmar).