Deploy Laravel Project on AWS EC2 Apache 2 Ubuntu Server

First of all, install git and composer on aws ec2 instance with Apache 2 server, because you can easily deploy laravel project with the help of Git clone command and run it on the server with the help of composer.

Here are some steps, which you can easily deploy laravel project on aws ec2 apache 2 server:

Step 1: Connect to AWS EC2 via SSH or Putty

To connect Amazon AWS EC2 instance via putty SSH.

If you do not how to connect AWS EC2 instance via SSH, Read this => Connect AWS EC2 instance via ssh for Windows, Mac, and Linux users.

Step 2: Install LAMP on AWS EC2

Once you connect aws ec2 instance, now install lamp stack linux, apache, php and mysql on aws ec2 instance.

Here is the guide on How to Install LAMP Stack on AWS EC2 Ubuntu.

Step 3: Install GIT

Type sudo apt-get install git command on terminal window and press enter, this will install git on aws ec2 server:

sudo apt-get install git

Step 4: Install Composer

Once installed curl by using the above command, Now, run this curl command on the terminal to download composer:

curl -sS https://getcomposer.org/installer -o composer-setup.php

Once the composer has been downloaded. After that, run the following command on the ssh terminal window to install and set up composer on aws ec2 apache ubuntu server:

sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer

Option 5: Deploy Laravel Project on AWS EC2 Instance

After that, To navigate to var/www/html directory of your aws ec2 apache 2 ubuntu server by using cd /var/www/html command on terminal window:

cd /var/www/html

To deploy laravel application on aws ec2 with apache 2 ubuntu server, Type sudo git clone https://github.com/username/reponame.git command on the terminal window and press enter:

sudo git clone https://github.com/username/reponame.git

Once it is deployed on the Apache 2 Ubuntu server, To install composer inside Laravel directory, Use cd laravel composer install command for that:

cd laravel composer install

Step 6: Configure Database with Laravel App

Once you deploy Laravel project on apache 2 Ubuntu server, You need to configure database in .env file and generate an encryption key. To type this commands on terminal window for that:

cd /var/www/html
cp .env.example .env
php artisan key:generate

These commands will copy the file from .env.example to .env and generate an encryption key, execute the following commands.

Step 7: Setup Permission and Ownership of Laravel Directory

To set up permission and ownership for laravel directory, simply open your terminal window and type the following comamnd into it to setup correct permission for that:

chown -R www-data.www-data /var/www/html/laravel chmod -R 755 /var/www/html/laravel chmod -R 777 /var/www/html/laravel/storage

Step 8: Configure Apache 2 with Laravel Application

Finally, you need to create virtual host in the defalut conf file of the aws ec2 apache ubuntu server.

Simply type sudo nano /etc/apache2/sites-available/000-default.conf command on terminal window to open your virtual host file for editing:

sudo nano /etc/apache2/sites-available/000-default.conf

Do not forget to replace 000-default.conf with the name of your virtual host file if you are using multiple virtual hosts on your server. Now, add /public at the end of the document root so that Apache will route all the traffic inside the /public route that holds the main index.php file of our project.

For example, Here is the updated default virtual host configuration file without comments.

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html/public
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

After updating your virtual host file, press CTRL+X followed by Y followed by the Enter key to save the updated virtual host file.

To restart the aws ec2 apache2 server to apply the changes, Simply type sudo service apache2 restart command on terminal window and press enter:

sudo service apache2 restart

Congratulations! Now open your web browser and run laravel project into it with aws ec2 apache 2 ubuntu server.

Conclusion

In this tutorial, you have learned how to deploy laravel project on aws ec2 apache 2 ubuntu linux server.

Recommended Tutorials

AuthorDevendra Dode

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

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