Laravel Vue Breeze EC2

User
configure laravel vue breeze on aws ec2 ubuntu instance
Assistant
To configure Laravel with Vue.js and Breeze on an AWS EC2 Ubuntu instance, follow these steps:

### Prerequisites:
1. **AWS EC2 instance** running Ubuntu.
2. **Node.js** and **npm** installed on your EC2 instance.
3. **PHP**, **Composer**, and **Laravel** installed.
4. **MySQL** (or another database) set up for Laravel if you plan to use a database.

### Step 1: Connect to your EC2 instance
SSH into your EC2 instance using the following command:

ssh -i /path/to/your/key.pem ubuntu@ec2-16-170-254-93.eu-north-1.compute.amazonaws.com

### Step 2: Update your system
Update the package list and install any available updates:

sudo apt update && sudo apt upgrade -y

### Step 3: Install PHP, Composer, and Laravel
#### Install PHP (PHP 8.3)

sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt install php8.3 php8.3-cli php8.3-fpm php8.3-mbstring php8.3-xml php8.3-mysql php8.3-curl php8.3-zip unzip -y

#### Install Composer

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

#### Install Laravel

composer global require laravel/installer

### Step 4: Install Node.js and npm
Install Node.js (You can skip this if Node.js is already installed):

curl -fsSL https://deb.nodesource.com/setup_21.x | sudo -E bash -
sudo apt install -y nodejs

### Step 5: Install Git
If Git is not installed, install it:

sudo apt install git -y

### Step 6: Set up the Laravel project
#### Create a Laravel Project
Navigate to the directory where you want to set up your Laravel project:

cd /var/www
composer create-project --prefer-dist laravel/laravel share

#### Set the project folder permissions
Ensure the `storage` and `bootstrap/cache` folders are writable:

sudo chmod -R 775 /var/www/share/storage /var/www/share/bootstrap/cache

### Step 7: Install Breeze and Vue.js
#### Install Laravel Breeze
Navigate to the Laravel project directory:

cd /var/www/share
composer require laravel/breeze --dev
php artisan breeze:install vue
npm install

#### Install npm dependencies
Run `npm install` to install the necessary JavaScript dependencies:

npm install

#### Build the assets
Run the following command to compile the assets:

npm run dev

### Step 8: Configure the `.env` file
Set your environment variables for the database (if applicable) and app URL:

nano .env

Set your database details:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=your_database_name
DB_USERNAME=your_database_username
DB_PASSWORD=your_database_password

### Step 9: Set up Apache or Nginx (Optional)
If you want to serve your Laravel application with Apache or Nginx, you'll need to install and configure one of them.

#### Install Apache

sudo apt install apache2 libapache2-mod-php -y

#### Configure Apache to serve Laravel
Create a virtual host configuration for Apache:

sudo nano /etc/apache2/sites-available/laravel.conf

Add the following configuration:

<VirtualHost *:80>
    DocumentRoot /var/www/share/public
    ServerName your-domain.com
    <Directory /var/www/share/public>
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

Enable the site and rewrite module:

sudo a2ensite laravel.conf
sudo a2enmod rewrite
sudo systemctl restart apache2

### Step 10: Set up SSL (Optional)
To enable HTTPS, you can use **Let's Encrypt** with Apache or Nginx. Here is how you can set it up with Apache:

sudo apt install certbot python3-certbot-apache -y
sudo certbot --apache

### Step 11: Check your app
Now, navigate to your EC2 public IP address or domain in your browser, and you should see your Laravel application running with Vue.js and Breeze installed.

These steps should get your Laravel, Vue.js, and Breeze setup running on your EC2 Ubuntu instance. Let me know if you need help with any specific step!

Leave a Comment

Your email address will not be published. Required fields are marked *