Palzin Track
Get 15% off with code PTRACKSIGNUP15 

Laravel Diary Logo

Setting up a Laravel Project on AWS Cloud9

aws
Table of Contents

If you've ever wanted to set up a development environment on AWS Cloud9, especially using Amazon Linux OS, you're in the right place. This blog will guide you through the process step by step. It might seem like a daunting task, but fear not – I'm here to help. Let's dive in and set up a Laravel project on AWS Cloud9.

Before we get started, make sure you have an AWS account and have set up the Cloud9 service. If you haven't already, create a fresh new environment for your project.

AWS Cloud9

When you access your newly created environment, you'll be welcomed by the Cloud9 integrated development environment and a terminal window. Before you start creating Laravel projects, you need to set up your environment properly.

The first step is to prepare your environment and install the necessary packages, including PHP extensions. Let's begin by making sure all existing packages are up to date:

sudo yum -y update

Next, you'll want to install PHP 7.1 along with required extensions. If you prefer a different PHP version, feel free to substitute "php71" with your version of choice (e.g., "php70" or "php56"):

sudo yum install -y php71   
sudo yum install -y php71-devel   
sudo yum install -y php71-mysql   
sudo yum install -y php71-mysqlnd  
sudo yum install -y php71-pdo   
sudo yum install -y php71-mbstring   
sudo yum install -y php71-mcrypt

Now, link the newly installed PHP version to the configuration files and set it as the default version:

sudo ln -sf /etc/httpd/conf.d/php-conf.7.1 /etc/alternatives/php.conf
sudo ln -sf /etc/httpd/conf.modules.d/15-php-conf.7.1 /etc/alternatives/10-php.conf

Select PHP 7.1 as the default version:

sudo alternatives --config php

Next, let's install Composer and move it to the user bin:

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

Now you're ready to create a fresh Laravel application. Alternatively, you can use git clone to get an existing repository:

composer create-project laravel/laravel projectname

Once you run this command, you'll see a new directory within your environment directory with a fresh Laravel installation.

Fresh Laravel Install

Before your project is up and running, you'll need to set up the environment and ensure the database connection is working. Make sure that the MySQL server is running:

sudo service mysqld start

You'll use the regular -uroot -p credentials, but you can change them as needed. Update these credentials in your .env file, and then run migrations as required.

If you encounter the following error with PHP 7.1:

SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes (SQL: alter table `users` add unique `users_email_unique`(`email`))

You can resolve it by adding the following line of code to the AppServiceProvider:

use Illuminate\Support\Facades\Schema;

public function boot()
{
    Schema::defaultStringLength(191);
}

Now, you're all set to run your app. To view it in the Cloud9 browser, run the following command in the terminal:

php artisan serve --port=8080

We chose port 8080 since this is the one that Cloud9 serves the local browser from.

Laravel Welcome Page

Congratulations! You should now be greeted with the Laravel welcome page. You're all set to start coding. Good luck! 🚀

::Share it on::

Comments (0)

What are your thoughts on "Setting up a Laravel Project on AWS Cloud9"?

You need to create an account to comment on this post.

Related articles