Hosting in AWS Ubuntu Lightsail
You are going to host laravel project in ubuntu
Get started
Step 1
If you have aws account, you can skip this step.
Follow the link if you are new to aws to create aws account AWS Website:
You may follow the vide how to create aws account:
Setp 2
Go to AWS Lightsail dashboard to create ubuntu server. aws
login Then, after you are in dashboard, search
Lightsail as show in photo below then open the link.
Setp 3
To create new instance, click on create instance
Setp 4
You can chose the zone. If the zone is near to user client, the performace and network request is fast.
In here, we will chose Singapore
. Then we will Select a platform Linux
.
Then we will Select a blueprint Operating System (OS) Only.
After that, we will pick the Ubuntu 24.04 LTS
Setp 5
After that scroll down, you will see optional. I recommended you do create ssh
key then select your ssh key. In this example, my ssh key is
ultratechinnovations
. You may chose the price for the server, I recommended
you to chose starting from $7.
Setp 6
You may give the name you want for the server. Then clicke on Create instance
Congratulation 🎉 you just create your ubuntu server from aws.
Setp 7
Go to networking
tap as shown in picture. Then we will add IPv4 Firewall
rules for https
. Click add rules
then search https
then click create
. Now you are ready for the next step to host laravel proejct.
Setp 8
Go to connect
tap as shown in picture. Then click connect using ssh
.
Setp 9
After that you are in the ubuntu server now.
Setp 10
Copy and past these commands in order to update the server.
sudo apt update
sudo apt upgrade -y
Setp 10
Copy and past this commands and press enter
in order to install the apache2.
sudo apt install apache2 -y
Setp 10
Please copy and past thses commands in your server terminal.
- Install PHP 8.2: Add the necessary repository for PHP 8.2:
sudo add-apt-repository ppa:ondrej/php
sudo apt update
- Install PHP 8.2 and required extensions:
sudo apt-get install -y php8.2-cli php8.2-common php8.2-fpm php8.2-mysql php8.2-zip php8.2-gd php8.2-mbstring php8.2-curl php8.2-xml php8.2-bcmath libapache2-mod-php
- Install the grpc Extension
sudo apt install php8.2-grpc
sudo phpenmod grpc
- Install MySQL:
sudo apt install mysql-server -y
Secure MySQL installation:
sudo mysql_secure_installation
Afte that you will be asking questions. You can type
N
N
y
y
create database and user
type mysql
then press enter
mysql
Then you can copy below code, closer
is the database name. You may give whatever you like.
CREATE DATABASE closer;
Then you should add database user using following cmd. Please copy and past line by line.
your_user
you have to replace with your databse user name for example admin
. Then replace your_password
.
CREATE USER 'your_user'@'%' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON *.* TO 'your_user'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
EXIT;
Setp 11 Clone Your Laravel Project
- Navigate to the web root:
cd /var/www/html
- Clone your repository:
sudo git clone https://github.com/your-repo/your-laravel-project.git
- Set permissions for Laravel:
sudo chown -R www-data:www-data /var/www/html/your-laravel-project
sudo chmod -R 755 /var/www/html/your-laravel-project
sudo chmod -R 775 /var/www/html/your-laravel-project/storage
sudo chmod -R 775 /var/www/html/your-laravel-project/bootstrap/cache
- copy
.env.example
sudo cp .env.example .env
then add the databases information and other API information in .env
file.
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel_db
DB_USERNAME=laravel_user
DB_PASSWORD=your_password
Step 6: Install Laravel Dependencies
- Install Composer:
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
- Install project dependencies: Navigate to your project folder:
cd /var/www/html/your-laravel-project
Run Composer to install dependencies:
sudo composer install
sudo php artisan key:generate
sudo php artisan migrate
Step 7: Configure Apache for Laravel
- Create a new Apache virtual host file:
sudo nano /etc/apache2/sites-available/your-laravel-project.conf
Add the following configuration:
<VirtualHost *:80>
ServerAdmin admin@example.com
DocumentRoot /var/www/html/your-laravel-project/public
ServerName yourdomain.com
<Directory /var/www/html/your-laravel-project>
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
3.Enable the new virtual host and mod_rewrite:
sudo a2ensite your-laravel-project.conf
sudo a2enmod rewrite
4.sudo systemctl restart apache2
sudo systemctl restart apache2
Please look at the video instructions if you love to see reather doc. But this video will not the same like doc we discuss above.