Skip to main content

AWS EC2, LAMP, Laravel and RDS Installation / setup


This document shows you how to configure AWS environment in Amazon EC2 with RDS Instance. We need to login in to AWS to start the configuration.
http://aws.amazon.com
Login screen for AWS Management console:

First thing we have to select is region. On which region you want to deploy your server. I am going to select Oregon region here for my setup.
1.      click on the launch instance button,
2.      It redirects to following screen. Here we have to search for required operating system or select from list, here im selecting Ubuntu latest version


4.      After selecting operating system, choose the instance type according to our requirement. Here I need lower configuration so choosing t2.micro type instance.  


5.      Click Next button, then you see the below screen. Here we to modify if any settings need to modify
Like changing network/subnet. or can skip this by keeping default settings.

6.      Click on next button and Add the storage that you need in below screen

7.      Click on next and Give the name of the server in below screen

8.      Create a new security group or existing security groups and allow port access that needs on the server like 22, 80, 443 and 10000 or All


9.      Click on the Review and Launch button, then Enter the name of the key pair if you want the new key and click on download key pair or select an existing key pair. keep the key safe in some locations.


10.  Wait for few minutes until the instance state is ready. then you can connect your server with SSH.
11.  When we download key we will get .pem file, We have to convert a key file that Amazon accept from us. Download puttygen.exe software
12.  Click on the Load button to load an existing private key file, Select all files from the drop-down box and select your-secret-key.pem file and click on open then You will see the following notice from puttygen.exe

13.  Click ok and save the private key file option and save the file with your-secret-key.ppk extension, Keep your-secret-key.ppk file in a safe location.
14.  Now we are ready to connect our server with SSH, select putty.exe or any other SSH client software to connect to the server with SSH. Here I'm using puuty.exe



15.  Enter Hostname and port 22, then Select SSH -> Auth tab and select your-secret-key.ppk file to connect to serve
16.  Click on the open button and Type->    the username root/ubuntu to connect to server.
17.  To set roo user password enter following commands
#sudo passwd root
Enter password: XXXXX
Confirm password: XXXX
#su root
Enter password: XXXX
#Cd (Now you are logged in to server)

 

Step 1: Install Apache2

Run the following command to update your server repository for update and install apache

#  sudo apt update
# sudo apt install apache2
After installing, the commands below can be used to stop, start and enable Apache2 service to always start up with the server boots.
# sudo systemctl stop apache2.service
# sudo systemctl start apache2.service
# sudo systemctl enable apache2.service
Or
# sudo apache2 service restart

Step 2: Install PHP 7.2 and Related Modules

Laravel is based on PHP. so, you’ll need to install it. To install PHP and related modules run the commands below
#  sudo apt install php7.2 libapache2-mod-php7.2 php7.2-mbstring php7.2-xmlrpc php7.2-soap php7.2-gd php7.2-xml php7.2-cli php7.2-zip
After install PHP, run the commands below to open PHP-FPM default file. After running the commands above, a new project directory will be created. Run the commands below to set the correct permissions for that directory.
# sudo chown -R www-data:www-data /var/www/html/MyProject/
# sudo chmod -R 755 /var/www/html/MyProject/

Step 5: Configure Apache2

Finally, configure Apahce2 site configuration file for Laravel. This file will control how user’s access Laravel content. Run the commands below to create a new configuration file called laravel.conf
# sudo nano /etc/apache2/sites-available/laravel.conf

Then copy and paste the content below into the file and save it. Replace the highlighted line with your own domain name and directory root location.


<VirtualHost *:80>   
  ServerAdmin admin@example.com
     DocumentRoot /var/www/html/MyProject/public
     ServerName example.com
 
     <Directory /var/www/html/MyProject/public>
        Options +FollowSymlinks
        AllowOverride All
        Require all granted
     </Directory>
 
     ErrorLog ${APACHE_LOG_DIR}/error.log
     CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Save the file and exit.

Step 5: Enable the Laravel and Rewrite Module

After configuring the VirtualHost above, enable it by running the commands below
# sudo a2ensite laravel.conf
# sudo a2enmod rewrite

Step 6: Restart Apache2

To load all the settings above, restart Apache2 by running the commands below.
# sudo systemctl restart apache2.service
 # sudo service apache2 restart
  
Then open your browser and browse to the server domain name. You should see Laravel page.
http://example.com
# sudo nano /etc/php/7.2/apache2/php.ini
Then make the change the following lines below in the file and save.
memory_limit = 1024M
upload_max_filesize = 1024M
cgi.fix_pathinfo=0

Step 3: Install Composer

Run the commands below to install composer package and install. you must have curl package installed for the commands to work. if not run #sudo apt install curl 
just run below command to install it composer.
# curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer

Change into Laravel directory
cd /var/www/html
now here you can upload source files with by using GIT or FTP
TO upload code using FTP download FileZilla Client and connect
TO upload source code with GIT, we have to install GIT by following command
# apt-get update
# apt-get install git-core
# git –version (to check git installed version)
By using following command, code can be uploaded to the server
To clone selected branch only enter following command
# git clone -b mybranch --single-branch https://path-of-repository
After uploading source code configure DB and other settings in .ENV file
then run #composer update command in root directory
then if you have passport library in your code run in root directory # php artisan passport:install
then if you have to run any migrations run following code in root directory # php artisan migrate




Now Create RDS
First login in to AWS console and go to RDS,
1.      In RDS dashboard Click on Create Database button



2.      Then choose the Database creation method
·         Standard Create: with custom settings (Here I have choose Standard Create)
·         Easy Create: default settings
3.      Then choose DB Engine & version according to the requirement, here im choosing MySql Engine and the latest version


4.      Next, choose template Production or Dev/test or Free tier (here im choosing Dev/test)

5.      Next settings
·         Choose a unique DB instance name
·         Add DB Username
·         Add autogenerated passwords/ enter manual passwords





6.      Next, choose DB instance size and storage as per need

7.      Choose availability & durability -> Create stand by instance
8.      Connectivity -> select VPC

9.      Choose DB authentication as password




Comments

Post a Comment

Popular posts from this blog

Laravel Request Validator json response example

 Step 1 :  php artisan make : request  StoreArticleRequest Step 2 : <?php namespace App\Http\Requests; use Illuminate\Foundation\Http\FormRequest; use Illuminate\Http\JsonResponse; use Illuminate\Contracts\Validation\Validator; use Illuminate\Http\Exceptions\HttpResponseException; class StoreArticleRequest extends FormRequest { /** * Determine if the user is authorized to make this request. * * @return bool */ public function authorize () { return true ; } /** * Get the validation rules that apply to the request. * * @return array */ public function rules () { return [ 'title' => 'required' ]; } protected function failedValidation (Validator $validator ) { if ($this -> wantsJson () || $this -> ajax ()) { throw new HttpResponseException( response () -> json ([ 'status' => '