So Murakami - BlogSetting up a Laravel App on AWS Cloud9

Updated: February 18, 2024

Published: February 18, 2024

Title Image

In this article, we go through the steps to get a laravel application up and running on AWS cloud9.

prerequisite

  • you already have an AWS account and created a cloud9 environment.

Update Packages

First things first, it's a good practice to run this command to make sure all packages are updated.

sudo yum update -y

Next, we remove all php packages.

sudo yum -y remove php-*

Then we update amazon-linux-extras

sudo yum update -y amazon-linux-extras

We can check all the packages in use and packages currently available by

amazon-linux-extras

Next, we stop using lamp-mariadb10.2-php7.2 and start using php8.1.

sudo amazon-linux-extras disable lamp-mariadb10.2-php7.2
sudo amazon-linux-extras enable php8.1

Then we install the necessary packages.

sudo yum clean metadata
sudo yum install php-cli php-common php-json php-devel php-fpm php-gd php-mysqlnd php-mbstring php-pdo php-xml

Then we restart apache.

sudo systemctl restart httpd.service
sudo systemctl restart php-fpm.service

Then we install xdebug.

sudo yum install php-pear php-devel
sudo pecl uninstall xdebug
sudo pecl install xdebug

Next step is to install MariaDB

sudo amazon-linux-extras install mariadb10.5 -y

and to start MariaDB.

sudo systemctl start mariadb
sudo mysql_secure_installation
sudo systemctl enable mariadb
sudo systemctl is-enabled mariadb

Install Laravel

Finally, we are ready to install composer

curl -sS https://getcomposer.org/installer | php

sudo mv composer.phar /usr/bin/composer

To check if you installed composer successfully

composer

Now you can make a laravel application

composer create-project "laravel/laravel=10.*" your_appname

You can adjust your_appname to the name of your application. This command creates a new directory with the name of your application.

To run your application, type in the following command

php artisan serve --port=8080

Connect your application to database

Inside /app/Providers/AppServiceProvider.php, write

#/app/Providers/AppServiceProvider.php

use Illuminate\Support\Facades\URL;    //Add this line
public function boot() {
   URL::forceScheme('https');          //Add this line
}

Next, in your termnal, run

mysql -u root -p

root

Once you successfully logged in your database, you can create a new database. Let's call our database testdb

create database testdb;
exit;

Next, we modify .env file in the root directory with the following lines.

This lines enable your app to connect to the testdb database.

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=testdb
DB_USERNAME=root
DB_PASSWORD=root

Summary

With these steps you can get a laravel application up and running.

Hope this article was helpful. Happy coding!

@2025