<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Mani Vaidhy</title>
    <description>The latest articles on Forem by Mani Vaidhy (@manivaidhy).</description>
    <link>https://forem.com/manivaidhy</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F681250%2F5ce34db4-a5ff-402b-959d-ff07ac91c9ce.jpg</url>
      <title>Forem: Mani Vaidhy</title>
      <link>https://forem.com/manivaidhy</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/manivaidhy"/>
    <language>en</language>
    <item>
      <title>Laravel : Running single cron on multiple servers</title>
      <dc:creator>Mani Vaidhy</dc:creator>
      <pubDate>Fri, 28 Jul 2023 13:56:35 +0000</pubDate>
      <link>https://forem.com/manivaidhy/laravel-running-single-cron-on-multiple-servers-4bgp</link>
      <guid>https://forem.com/manivaidhy/laravel-running-single-cron-on-multiple-servers-4bgp</guid>
      <description>&lt;p&gt;This article is to setup a single cron on multiple servers in Laravel.&lt;/p&gt;

&lt;h3&gt;
  
  
  Create EC2 Instance in AWS
&lt;/h3&gt;

&lt;p&gt;Open the Amazon EC2 console at &lt;a href="https://console.aws.amazon.com/ec2/"&gt;https://console.aws.amazon.com/ec2/&lt;/a&gt; and click on “Running Instances”. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Click on Launch Instance.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Choose which type of Virtual Machine you would like to use. The Amazon Machine Images are pre-configured virtual machines that serve as a template for your instance. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;For our application select "Ubuntu 20.04 (64bit)" Instance.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Next, choose an instance type to set the storage and size of your instance. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;T2.micro is set as the type by default and eligible for Amazon’s free tier. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Next, click on Review and Launch to let the AWS wizard set up the default configurations for you.&lt;/p&gt;

&lt;p&gt;Next, review your instance and modify security groups, In that&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Add "http" as Type with port 80 and choose source "0.0.0.0/0" and click "Launch"&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You will have to specify a key pair. If you already have an AWS key-pair, you can select to use that one. If not, you will select Create a New Key Pair. Enter any name for the key pair. Then, click Download Key Pair. This will be the only time you will be able to download this key pair. Move it to some secure location, or somewhere you will not delete it. You need this key-pair to allow you to enter your instance. Consider it a password. Now, launch your instance!&lt;/p&gt;

&lt;p&gt;Now that your instance is launched, next we have to connect to the instance via SSH. On the EC2 instances dashboard, click the button next to your instance name, and click on Actions. A dropdown menu should appear under Actions, and click on Connect.&lt;/p&gt;

&lt;p&gt;Open Terminal and go to the folder at which your key-pair is stored. Run the chmod command to change permissions on your key-pair. Then, run the ssh command to enter your instance. You will need to rerun the chmod command to modify the permissions on your key-pair every time you restart your computer in order to enter your instance.&lt;/p&gt;

&lt;h3&gt;
  
  
  Installing Dependencies for Laravel
&lt;/h3&gt;

&lt;p&gt;In order to display web pages to our site visitors, we are going to employ Nginx, a high-performance web server. We’ll use the apt package manager to obtain this software.&lt;/p&gt;

&lt;h4&gt;
  
  
  Installing the Nginx Web Server
&lt;/h4&gt;

&lt;p&gt;Since this is our first time using apt for this session, start off by updating your server’s package index. Following that, you can use apt install to get Nginx installed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt update
&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When prompted, enter Y to confirm that you want to install Nginx. Once the installation is finished, the Nginx web server will be active and running on your Ubuntu 20.04 server.&lt;/p&gt;

&lt;p&gt;If you do not have a domain name pointed at your server and you do not know your server’s public IP address, you can find it by running the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ip addr show eth0 | &lt;span class="nb"&gt;grep &lt;/span&gt;inet | &lt;span class="nb"&gt;awk&lt;/span&gt; &lt;span class="s1"&gt;'{ print $2; }'&lt;/span&gt; | &lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="s1"&gt;'s/\/.*$//'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will print out a few IP addresses. You can try each of them in turn in your web browser.&lt;br&gt;
Type the address that you receive in your web browser and it will take you to Nginx’s default landing page:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;http://server_domain_or_IP
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Installing PHP
&lt;/h4&gt;

&lt;p&gt;You have Nginx installed to serve your content and MySQL installed to store and manage your data. Now you can install PHP to process code and generate dynamic content for the web server.&lt;/p&gt;

&lt;p&gt;While Apache embeds the PHP interpreter in each request, Nginx requires an external program to handle PHP processing and act as a bridge between the PHP interpreter itself and the web server. This allows for a better overall performance in most PHP-based websites, but it requires additional configuration. You’ll need to install php-fpm, which stands for “PHP fastCGI process manager”, and tell Nginx to pass PHP requests to this software for processing. Additionally, you’ll need php-mysql, a PHP module that allows PHP to communicate with MySQL-based databases. Core PHP packages will automatically be installed as dependencies.&lt;/p&gt;

&lt;p&gt;To install the php-fpm and php-mysql packages, run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;php-fpm php-mysql

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When prompted, type Y and ENTER to confirm installation.&lt;br&gt;
You now have your PHP components installed. Next, you’ll configure Nginx to use them.&lt;/p&gt;
&lt;h4&gt;
  
  
  Configuring Nginx to Use the PHP Processor
&lt;/h4&gt;

&lt;p&gt;open configuration file in Nginx’s sites-enabled directory using your preferred command-line editor. Here, we’ll use vim:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;vim /etc/nginx/sites-enabled/default
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Paste in the following bare-bones configuration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;server &lt;span class="o"&gt;{&lt;/span&gt;
        listen 80 default_server&lt;span class="p"&gt;;&lt;/span&gt;
        listen &lt;span class="o"&gt;[&lt;/span&gt;::]:80 default_server&lt;span class="p"&gt;;&lt;/span&gt;

        root /var/www/html&lt;span class="p"&gt;;&lt;/span&gt;

        index index.html index.htm index.nginx-debian.html&lt;span class="p"&gt;;&lt;/span&gt;

        server_name _&lt;span class="p"&gt;;&lt;/span&gt;

        location / &lt;span class="o"&gt;{&lt;/span&gt;
                try_files &lt;span class="nv"&gt;$uri&lt;/span&gt; &lt;span class="nv"&gt;$uri&lt;/span&gt;/ &lt;span class="o"&gt;=&lt;/span&gt;404&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;

        location ~ &lt;span class="se"&gt;\.&lt;/span&gt;php&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
                include snippets/fastcgi-php.conf&lt;span class="p"&gt;;&lt;/span&gt;
                fastcgi_pass unix:/var/run/php/php7.4-fpm.sock&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;

        location ~ /&lt;span class="se"&gt;\.&lt;/span&gt;ht &lt;span class="o"&gt;{&lt;/span&gt;
                deny all&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When you’re done editing, save and close the file. &lt;/p&gt;

&lt;p&gt;This will tell Nginx to use the configuration next time it is reloaded. You can test your configuration for syntax errors by typing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;nginx &lt;span class="nt"&gt;-t&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If any errors are reported, go back to your configuration file to review its contents before continuing.&lt;/p&gt;

&lt;p&gt;When you are ready, reload Nginx to apply the changes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;service nginx restart
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your LEMP stack is now fully configured. In the next step, we’ll create a PHP script to test that Nginx is in fact able to handle .php files within your newly configured website.&lt;/p&gt;

&lt;h4&gt;
  
  
  Testing PHP with Nginx
&lt;/h4&gt;

&lt;p&gt;Your LEMP stack should now be completely set up. You can test it to validate that Nginx can correctly hand .php files off to your PHP processor.&lt;/p&gt;

&lt;p&gt;You can do this by creating a test PHP file in your document root. Open a new file called info.php within your document root in your text editor:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;vim /var/www/html/info.php
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Type or paste the following lines into the new file. This is valid PHP code that will return information about your server:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&amp;lt;?php
phpinfo&lt;span class="o"&gt;()&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When you are finished, save and close the file. &lt;br&gt;
You can now access this page in your web browser by visiting the domain name or public IP address you’ve set up in your Nginx configuration file, followed by /info.php:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;http://server_domain_or_IP/info.php
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will see a web page containing detailed information about your server:&lt;/p&gt;

&lt;p&gt;After checking the relevant information about your PHP server through that page, it’s best to remove the file you created as it contains sensitive information about your PHP environment and your Ubuntu server. You can use rm to remove that file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo rm&lt;/span&gt; /var/www/html/info.php
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Installing Additional Dependencies
&lt;/h4&gt;

&lt;p&gt;In addition to dependencies that should be already included within your Ubuntu 20.04 system, such as git and curl, Composer requires php-cli in order to execute PHP scripts in the command line, and unzip to extract zipped archives. We’ll install these dependencies now.&lt;/p&gt;

&lt;p&gt;First, update the package manager cache by running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt update
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, run the following command to install the required packages:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;php-cli unzip
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will be prompted to confirm installation by typing Y and then ENTER.&lt;/p&gt;

&lt;p&gt;Once the prerequisites are installed, you can proceed to installing Composer.&lt;/p&gt;

&lt;h4&gt;
  
  
  Downloading and Installing Composer
&lt;/h4&gt;

&lt;p&gt;Composer provides an installer script written in PHP. We’ll download it, verify that it’s not corrupted, and then use it to install Composer.&lt;/p&gt;

&lt;p&gt;Make sure you’re in your home directory, then retrieve the installer using curl:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; ~
curl &lt;span class="nt"&gt;-sS&lt;/span&gt; https://getcomposer.org/installer &lt;span class="nt"&gt;-o&lt;/span&gt; composer-setup.php
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, we’ll verify that the downloaded installer matches the SHA-384 hash for the latest installer found on the Composer Public Keys / Signatures page. To facilitate the verification step, you can use the following command to programmatically obtain the latest hash from the Composer page and store it in a shell variable:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;HASH&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sb"&gt;`&lt;/span&gt;curl &lt;span class="nt"&gt;-sS&lt;/span&gt; https://composer.github.io/installer.sig&lt;span class="sb"&gt;`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want to verify the obtained value, you can run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$HASH&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;e0012edf3e80b6978849f5eff0d4b4e4c79ff1609dd1e613307e16318854d24ae64f26d17af3ef0bf7cfb710ca74755a
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now execute the following PHP code, as provided in the Composer download page, to verify that the installation script is safe to run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;php &lt;span class="nt"&gt;-r&lt;/span&gt; &lt;span class="s2"&gt;"if (hash_file('SHA384', 'composer-setup.php') === '&lt;/span&gt;&lt;span class="nv"&gt;$HASH&lt;/span&gt;&lt;span class="s2"&gt;') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You’ll see the following output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Installer verified
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To install composer globally, use the following command which will download and install Composer as a system-wide command named composer, under /usr/local/bin:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;php composer-setup.php &lt;span class="nt"&gt;--install-dir&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/usr/local/bin &lt;span class="nt"&gt;--filename&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;composer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You’ll see output similar to this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;All settings correct &lt;span class="k"&gt;for &lt;/span&gt;using Composer
Downloading...

Composer &lt;span class="o"&gt;(&lt;/span&gt;version 1.10.5&lt;span class="o"&gt;)&lt;/span&gt; successfully installed to: /usr/local/bin/composer
Use it: php /usr/local/bin/composer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To test your installation, run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;composer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   ______
  / ____/___  ____ ___  ____  ____  ________  _____
 / /   / __ &lt;span class="se"&gt;\/&lt;/span&gt; __ &lt;span class="sb"&gt;`&lt;/span&gt;__ &lt;span class="se"&gt;\/&lt;/span&gt; __ &lt;span class="se"&gt;\/&lt;/span&gt; __ &lt;span class="se"&gt;\/&lt;/span&gt; ___/ _ &lt;span class="se"&gt;\/&lt;/span&gt; ___/
/ /___/ /_/ / / / / / / /_/ / /_/ &lt;span class="o"&gt;(&lt;/span&gt;__  &lt;span class="o"&gt;)&lt;/span&gt;  __/ /
&lt;span class="se"&gt;\_&lt;/span&gt;___/&lt;span class="se"&gt;\_&lt;/span&gt;___/_/ /_/ /_/ .___/&lt;span class="se"&gt;\_&lt;/span&gt;___/____/&lt;span class="se"&gt;\_&lt;/span&gt;__/_/
                    /_/
Composer version 1.10.5 2020-04-10 11:44:22

Usage:
  &lt;span class="nb"&gt;command&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;options] &lt;span class="o"&gt;[&lt;/span&gt;arguments]

Options:
  &lt;span class="nt"&gt;-h&lt;/span&gt;, &lt;span class="nt"&gt;--help&lt;/span&gt;                     Display this &lt;span class="nb"&gt;help &lt;/span&gt;message
  &lt;span class="nt"&gt;-q&lt;/span&gt;, &lt;span class="nt"&gt;--quiet&lt;/span&gt;                    Do not output any message
  &lt;span class="nt"&gt;-V&lt;/span&gt;, &lt;span class="nt"&gt;--version&lt;/span&gt;                  Display this application version
      &lt;span class="nt"&gt;--ansi&lt;/span&gt;                     Force ANSI output
      &lt;span class="nt"&gt;--no-ansi&lt;/span&gt;                  Disable ANSI output
  &lt;span class="nt"&gt;-n&lt;/span&gt;, &lt;span class="nt"&gt;--no-interaction&lt;/span&gt;           Do not ask any interactive question
      &lt;span class="nt"&gt;--profile&lt;/span&gt;                  Display timing and memory usage information
      &lt;span class="nt"&gt;--no-plugins&lt;/span&gt;               Whether to disable plugins.
  &lt;span class="nt"&gt;-d&lt;/span&gt;, &lt;span class="nt"&gt;--working-dir&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;WORKING-DIR  If specified, use the given directory as working directory.
      &lt;span class="nt"&gt;--no-cache&lt;/span&gt;                 Prevent use of the cache
  &lt;span class="nt"&gt;-v&lt;/span&gt;|vv|vvv, &lt;span class="nt"&gt;--verbose&lt;/span&gt;           Increase the verbosity of messages: 1 &lt;span class="k"&gt;for &lt;/span&gt;normal output, 2 &lt;span class="k"&gt;for &lt;/span&gt;more verbose output and 3 &lt;span class="k"&gt;for &lt;/span&gt;debug
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This verifies that Composer was successfully installed on your system and is available system-wide.&lt;/p&gt;

&lt;h4&gt;
  
  
  Installing Required PHP modules for Laravel
&lt;/h4&gt;

&lt;p&gt;Before you can install Laravel, you need to install a few PHP modules that are required by the framework. We’ll use apt to install the php-mbstring, php-xml and php-bcmath PHP modules. These PHP extensions provide extra support for dealing with character encoding, XML and precision mathematics.&lt;/p&gt;

&lt;p&gt;update the package manager cache by running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt update
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you can install the required packages with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;php-mbstring php-xml php-bcmath
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your system is now ready to execute Laravel’s installation via Composer, but before doing so, you’ll need a database for your application.&lt;/p&gt;

&lt;h3&gt;
  
  
  Creating a New Laravel Application
&lt;/h3&gt;

&lt;p&gt;You will now create a new Laravel application using the composer create-project command. This Composer command is typically used to bootstrap new applications based on existing frameworks and content management systems.&lt;/p&gt;

&lt;p&gt;First, go to your user’s home directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; ~
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The following command will create a new my_app_name directory containing a barebones Laravel application based on default settings:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;composer create-project &lt;span class="nt"&gt;--prefer-dist&lt;/span&gt; laravel/laravel my_app_name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will see output similar to this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Installing laravel/laravel &lt;span class="o"&gt;(&lt;/span&gt;v5.8.17&lt;span class="o"&gt;)&lt;/span&gt;
  - Installing laravel/laravel &lt;span class="o"&gt;(&lt;/span&gt;v5.8.17&lt;span class="o"&gt;)&lt;/span&gt;: Downloading &lt;span class="o"&gt;(&lt;/span&gt;100%&lt;span class="o"&gt;)&lt;/span&gt;         
Created project &lt;span class="k"&gt;in &lt;/span&gt;my_app_name
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; @php &lt;span class="nt"&gt;-r&lt;/span&gt; &lt;span class="s2"&gt;"file_exists('.env') || copy('.env.example', '.env');"&lt;/span&gt;
Loading composer repositories with package information
Updating dependencies &lt;span class="o"&gt;(&lt;/span&gt;including require-dev&lt;span class="o"&gt;)&lt;/span&gt;
Package operations: 80 installs, 0 updates, 0 removals
  - Installing symfony/polyfill-ctype &lt;span class="o"&gt;(&lt;/span&gt;v1.11.0&lt;span class="o"&gt;)&lt;/span&gt;: Downloading &lt;span class="o"&gt;(&lt;/span&gt;100%&lt;span class="o"&gt;)&lt;/span&gt;         
  - Installing phpoption/phpoption &lt;span class="o"&gt;(&lt;/span&gt;1.5.0&lt;span class="o"&gt;)&lt;/span&gt;: Downloading &lt;span class="o"&gt;(&lt;/span&gt;100%&lt;span class="o"&gt;)&lt;/span&gt;         
  - Installing vlucas/phpdotenv &lt;span class="o"&gt;(&lt;/span&gt;v3.4.0&lt;span class="o"&gt;)&lt;/span&gt;: Downloading &lt;span class="o"&gt;(&lt;/span&gt;100%&lt;span class="o"&gt;)&lt;/span&gt;         
  - Installing symfony/css-selector &lt;span class="o"&gt;(&lt;/span&gt;v4.3.2&lt;span class="o"&gt;)&lt;/span&gt;: Downloading &lt;span class="o"&gt;(&lt;/span&gt;100%&lt;span class="o"&gt;)&lt;/span&gt;     
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When the installation is finished, access the application’s directory and run Laravel’s artisan command to verify that all components were successfully installed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;my_app_name
php artisan
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You’ll see output similar to this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Laravel Framework 8.11.0

Usage:
  &lt;span class="nb"&gt;command&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;options] &lt;span class="o"&gt;[&lt;/span&gt;arguments]

Options:
  &lt;span class="nt"&gt;-h&lt;/span&gt;, &lt;span class="nt"&gt;--help&lt;/span&gt;            Display this &lt;span class="nb"&gt;help &lt;/span&gt;message
  &lt;span class="nt"&gt;-q&lt;/span&gt;, &lt;span class="nt"&gt;--quiet&lt;/span&gt;           Do not output any message
  &lt;span class="nt"&gt;-V&lt;/span&gt;, &lt;span class="nt"&gt;--version&lt;/span&gt;         Display this application version
      &lt;span class="nt"&gt;--ansi&lt;/span&gt;            Force ANSI output
      &lt;span class="nt"&gt;--no-ansi&lt;/span&gt;         Disable ANSI output
  &lt;span class="nt"&gt;-n&lt;/span&gt;, &lt;span class="nt"&gt;--no-interaction&lt;/span&gt;  Do not ask any interactive question
      &lt;span class="nt"&gt;--env&lt;/span&gt;&lt;span class="o"&gt;[=&lt;/span&gt;ENV]       The environment the &lt;span class="nb"&gt;command &lt;/span&gt;should run under
  &lt;span class="nt"&gt;-v&lt;/span&gt;|vv|vvv, &lt;span class="nt"&gt;--verbose&lt;/span&gt;  Increase the verbosity of messages: 1 &lt;span class="k"&gt;for &lt;/span&gt;normal output, 2 &lt;span class="k"&gt;for &lt;/span&gt;more verbose output and 3 &lt;span class="k"&gt;for &lt;/span&gt;debug
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This output confirms that the application files are in place, and the Laravel command-line tools are working as expected. However, we still need to configure the application to set up the database and a few other details.&lt;/p&gt;

&lt;h4&gt;
  
  
  Configuring Laravel
&lt;/h4&gt;

&lt;p&gt;The Laravel configuration files are located in a directory called config, inside the application’s root directory. Additionally, when you install Laravel with Composer, it creates an environment file. This file contains settings that are specific to the current environment the application is running, and will take precedence over the values set in regular configuration files located at the config directory. Each installation on a new environment requires a tailored environment file to define things such as database connection settings, debug options, application URL, among other items that may vary depending on which environment the application is running.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Warning: The environment configuration file contains sensitive information about your server, including database credentials and security keys. For that reason, you should never share this file publicly.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;We’ll now edit the .env file to customize the configuration options for the current application environment.&lt;/p&gt;

&lt;p&gt;Open the .env file using your command line editor of choice.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;vim .env
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Even though there are many configuration variables in this file, you don’t need to set up all of them now. The following list contains an overview of the variables that require immediate attention:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;APP_NAME: Application name, used for notifications and messages.&lt;/li&gt;
&lt;li&gt;APP_ENV: Current application environment.&lt;/li&gt;
&lt;li&gt;APP_KEY: Used for generating salts and hashes, this unique key is automatically created when installing Laravel via Composer, so you don’t need to change it.&lt;/li&gt;
&lt;li&gt;APP_DEBUG: Whether or not to show debug information at client side.&lt;/li&gt;
&lt;li&gt;APP_URL: Base URL for the application, used for generating application links.&lt;/li&gt;
&lt;li&gt;DB_DATABASE: Database name.&lt;/li&gt;
&lt;li&gt;DB_USERNAME: Username to connect to the database.&lt;/li&gt;
&lt;li&gt;DB_PASSWORD: Password to connect to the database.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The following .env file sets up our example application for development:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;APP_NAME&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;My App Name
&lt;span class="nv"&gt;APP_ENV&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;production
&lt;span class="nv"&gt;APP_KEY&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;APPLICATION_UNIQUE_KEY_DONT_COPY
&lt;span class="nv"&gt;APP_DEBUG&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;true
&lt;/span&gt;&lt;span class="nv"&gt;APP_URL&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;http://domain_or_IP

&lt;span class="nv"&gt;LOG_CHANNEL&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;stack

&lt;span class="c"&gt;# We will update the below database details after this setup&lt;/span&gt;
&lt;span class="nv"&gt;DB_CONNECTION&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;mysql
&lt;span class="nv"&gt;DB_HOST&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;DATABASE_HOST
&lt;span class="nv"&gt;DB_PORT&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;3306
&lt;span class="nv"&gt;DB_DATABASE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;DATABASE_NAME
&lt;span class="nv"&gt;DB_USERNAME&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;DATABASE_USERNAME
&lt;span class="nv"&gt;DB_PASSWORD&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;DATABASE_PASSWORD
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Adjust your variables accordingly. When you are done editing, save and close the file to keep your changes. If you’re using nano, you can do that with CTRL+X, then Y and Enter to confirm.&lt;/p&gt;

&lt;p&gt;Your Laravel application is now set up, but we still need to configure the web server in order to be able to access it from a browser. In the next step, we’ll configure Nginx to serve your Laravel application.&lt;/p&gt;

&lt;h4&gt;
  
  
  Setting Up Nginx
&lt;/h4&gt;

&lt;p&gt;We have installed Laravel on a local folder of your remote user’s home directory, and while this works well for local development environments, it’s not a recommended practice for web servers that are open to the public internet. We’ll move the application folder to /var/www, which is the usual location for web applications running on Nginx.&lt;/p&gt;

&lt;p&gt;First, use the mv command to move the application folder with all its contents to /var/www/my_app_name:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo mv&lt;/span&gt; ~/my_app_name /var/www/my_app_name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we need to give the web server user write access to the storage and cache folders, where Laravel stores application-generated files:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo chown&lt;/span&gt; &lt;span class="nt"&gt;-R&lt;/span&gt; www-data.www-data /var/www/my_app_name/storage
&lt;span class="nb"&gt;sudo chown&lt;/span&gt; &lt;span class="nt"&gt;-R&lt;/span&gt; www-data.www-data /var/www/my_app_name/bootstrap/cache
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The application files are now in order, but we still need to configure Nginx to serve the content. To do this, we’ll create a new virtual host configuration file at /etc/nginx/sites-available:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;vim /etc/nginx/sites-available/my_app_name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The following configuration file contains the recommended settings for Laravel applications on Nginx:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;server &lt;span class="o"&gt;{&lt;/span&gt;
    listen 80&lt;span class="p"&gt;;&lt;/span&gt;
    server_name _&lt;span class="p"&gt;;&lt;/span&gt;
    root /var/www/my_app_name/public&lt;span class="p"&gt;;&lt;/span&gt;

    add_header X-Frame-Options &lt;span class="s2"&gt;"SAMEORIGIN"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    add_header X-XSS-Protection &lt;span class="s2"&gt;"1; mode=block"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    add_header X-Content-Type-Options &lt;span class="s2"&gt;"nosniff"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    index index.html index.htm index.php&lt;span class="p"&gt;;&lt;/span&gt;

    charset utf-8&lt;span class="p"&gt;;&lt;/span&gt;

    location / &lt;span class="o"&gt;{&lt;/span&gt;
        try_files &lt;span class="nv"&gt;$uri&lt;/span&gt; &lt;span class="nv"&gt;$uri&lt;/span&gt;/ /index.php?&lt;span class="nv"&gt;$query_string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    location &lt;span class="o"&gt;=&lt;/span&gt; /favicon.ico &lt;span class="o"&gt;{&lt;/span&gt; access_log off&lt;span class="p"&gt;;&lt;/span&gt; log_not_found off&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="o"&gt;}&lt;/span&gt;
    location &lt;span class="o"&gt;=&lt;/span&gt; /robots.txt  &lt;span class="o"&gt;{&lt;/span&gt; access_log off&lt;span class="p"&gt;;&lt;/span&gt; log_not_found off&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="o"&gt;}&lt;/span&gt;

    error_page 404 /index.php&lt;span class="p"&gt;;&lt;/span&gt;

    location ~ &lt;span class="se"&gt;\.&lt;/span&gt;php&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock&lt;span class="p"&gt;;&lt;/span&gt;
        fastcgi_index index.php&lt;span class="p"&gt;;&lt;/span&gt;
        fastcgi_param SCRIPT_FILENAME &lt;span class="nv"&gt;$realpath_root$fastcgi_script_name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        include fastcgi_params&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    location ~ /&lt;span class="se"&gt;\.&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;?!well-known&lt;span class="o"&gt;)&lt;/span&gt;.&lt;span class="k"&gt;*&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        deny all&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Copy this content to your /etc/nginx/sites-enabled/default file and, if necessary, adjust the highlighted values to align with your own configuration. Save and close the file when you’re done editing.&lt;/p&gt;

&lt;p&gt;To confirm that the configuration doesn’t contain any syntax errors, you can use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;nginx &lt;span class="nt"&gt;-t&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should see output like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf &lt;span class="nb"&gt;test &lt;/span&gt;is successful
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To apply the changes, restart Nginx with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl reload nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now go to your browser and access the application using the server’s domain name or IP address, as defined by the server_name directive in your configuration file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;http://server_domain_or_IP
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will see the Laravel default landing page.&lt;/p&gt;

&lt;p&gt;That confirms your Nginx server is properly configured to serve Laravel. From this point, you can start building up your application on top of the skeleton provided by the default installation.&lt;/p&gt;

&lt;h3&gt;
  
  
  Creating Database using AWS RDS
&lt;/h3&gt;

&lt;p&gt;Open the Amazon RDS console at &lt;a href="https://console.aws.amazon.com/rds/"&gt;https://console.aws.amazon.com/rds/&lt;/a&gt; and &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;click on “Create Database”.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Select the MySQL engine and click Next. Select the Dev/Test use case which keeps us within the RDS Free Usage Tier.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The next section is where we will specify the Database details. Select the t2.micro DB instance type, then scroll down to the Settings row at the bottom.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Set the DB instance identifier, the Master username, the Master Password and the Confirm Password&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Cick on "Create database"&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Your DB Instance is now being created.  Click View Your DB Instances.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note: Depending on the DB instance class and storage allocated, it could take several minutes for the new DB instance to become available.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The new DB instance appears in the list of DB instances on the RDS console. The DB instance will have a status of creating until the DB instance is created and ready for use.  When the state changes to available, you can connect to a database on the DB instance. &lt;/p&gt;

&lt;p&gt;Once the DB instance is created, Choose "modify" option and then select ""&lt;/p&gt;

&lt;p&gt;Click on the DB instance you have created and copy the Endpoint in Connectivity and security, you need to use it in MySQL connection(Host name).&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use the "end point" as a host and use the username and password which created during the Database creating process, in the laravel application's ".env" file.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Configuring Laravel .env File
&lt;/h4&gt;

&lt;p&gt;Now log back into our EC2 Instance via SSH and navigate to the project directory&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; /var/www/my_app_name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Open the environment file using your text editor,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;vim .env
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And update the database details in the .env file in the below fields,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;...
&lt;span class="nv"&gt;DB_CONNECTION&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;mysql
&lt;span class="nv"&gt;DB_HOST&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&amp;lt;RDS ENDPOINT&amp;gt;
&lt;span class="nv"&gt;DB_PORT&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;3306
&lt;span class="nv"&gt;DB_DATABASE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&amp;lt;RDS DATABASE NAME&amp;gt;
&lt;span class="nv"&gt;DB_USERNAME&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&amp;lt;RDS DATABASE USERNAME&amp;gt;
&lt;span class="nv"&gt;DB_PASSWORD&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&amp;lt;RDS DATABASE PASSWORD&amp;gt;
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once done, save and close the file&lt;/p&gt;

&lt;p&gt;Now we need to give Nginx write access to the storage folder, else Laravel will throw a write permission error.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo chmod&lt;/span&gt; &lt;span class="nt"&gt;-R&lt;/span&gt; 777 /var/www/my_app_name/storage
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Creating Cache Tables
&lt;/h4&gt;

&lt;p&gt;We are using the database cache driver, you will need to setup a table to contain the cache items.&lt;/p&gt;

&lt;p&gt;Artisan command to generate a migration with the proper schema. Run the following command in the project directory&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;php artisan cache:table
php artisan migrate&lt;span class="sb"&gt;`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now the cache table has been created in the database. &lt;/p&gt;

&lt;h3&gt;
  
  
  Changing Cache Configuration
&lt;/h3&gt;

&lt;p&gt;We need to tell the application to use our database cache in order to serve commands to run in a single server&lt;/p&gt;

&lt;p&gt;For that open cache config file located in "/my_app_name/config/cache.php"&lt;br&gt;
In that change the particular "CACHE_DRIVER" config to "database" as below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; &lt;span class="s1"&gt;'default'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;env&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'CACHE_DRIVER'&lt;/span&gt;, &lt;span class="s1"&gt;'database'&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;,
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Save and close the file.&lt;/p&gt;

&lt;p&gt;Next, open the ".env" file and change the "CACHE_DRIVER" config to "database" as below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; &lt;span class="nv"&gt;CACHE_DRIVER&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;database
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Save and close the file.&lt;br&gt;
 Now we have setup all the cache configuration to database in our application.&lt;/p&gt;
&lt;h4&gt;
  
  
  Create Console Commands
&lt;/h4&gt;

&lt;p&gt;To create a new command, you may use the "make:command" Artisan command. This command will create a new command class in the "app/Console/Commands" directory. Don't worry if this directory does not exist in your application - it will be created the first time you run the "make:command" Artisan command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;php artisan make:command CommandName
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The console commands file will be created in the location &lt;br&gt;
"/my_app_name/app/Console/Commands/CommandName.php"&lt;/p&gt;

&lt;p&gt;Open the file and replace the contents below,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&amp;lt;?php

namespace App&lt;span class="se"&gt;\C&lt;/span&gt;onsole&lt;span class="se"&gt;\C&lt;/span&gt;ommands&lt;span class="p"&gt;;&lt;/span&gt;
use Illuminate&lt;span class="se"&gt;\S&lt;/span&gt;upport&lt;span class="se"&gt;\F&lt;/span&gt;acades&lt;span class="se"&gt;\D&lt;/span&gt;B&lt;span class="p"&gt;;&lt;/span&gt;
use Illuminate&lt;span class="se"&gt;\C&lt;/span&gt;onsole&lt;span class="se"&gt;\C&lt;/span&gt;ommand&lt;span class="p"&gt;;&lt;/span&gt;
use Illuminate&lt;span class="se"&gt;\S&lt;/span&gt;upport&lt;span class="se"&gt;\F&lt;/span&gt;acades&lt;span class="se"&gt;\C&lt;/span&gt;ache&lt;span class="p"&gt;;&lt;/span&gt;

class CommandName extends Command
&lt;span class="o"&gt;{&lt;/span&gt;
    /&lt;span class="k"&gt;**&lt;/span&gt;
     &lt;span class="k"&gt;*&lt;/span&gt; The name and signature of the console command.
     &lt;span class="k"&gt;*&lt;/span&gt;
     &lt;span class="k"&gt;*&lt;/span&gt; @var string
     &lt;span class="k"&gt;*&lt;/span&gt;/
    protected &lt;span class="nv"&gt;$signature&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'command:name'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    /&lt;span class="k"&gt;**&lt;/span&gt;
     &lt;span class="k"&gt;*&lt;/span&gt; The console &lt;span class="nb"&gt;command &lt;/span&gt;description.
     &lt;span class="k"&gt;*&lt;/span&gt;
     &lt;span class="k"&gt;*&lt;/span&gt; @var string
     &lt;span class="k"&gt;*&lt;/span&gt;/
    protected &lt;span class="nv"&gt;$description&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Command description'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    /&lt;span class="k"&gt;**&lt;/span&gt;
     &lt;span class="k"&gt;*&lt;/span&gt; Create a new &lt;span class="nb"&gt;command &lt;/span&gt;instance.
     &lt;span class="k"&gt;*&lt;/span&gt;
     &lt;span class="k"&gt;*&lt;/span&gt; @return void
     &lt;span class="k"&gt;*&lt;/span&gt;/
    public &lt;span class="k"&gt;function &lt;/span&gt;__construct&lt;span class="o"&gt;()&lt;/span&gt;
    &lt;span class="o"&gt;{&lt;/span&gt;
        parent::__construct&lt;span class="o"&gt;()&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    /&lt;span class="k"&gt;**&lt;/span&gt;
     &lt;span class="k"&gt;*&lt;/span&gt; Execute the console command.
     &lt;span class="k"&gt;*&lt;/span&gt;
     &lt;span class="k"&gt;*&lt;/span&gt; @return int
     &lt;span class="k"&gt;*&lt;/span&gt;/
    public &lt;span class="k"&gt;function &lt;/span&gt;handle&lt;span class="o"&gt;()&lt;/span&gt;
    &lt;span class="o"&gt;{&lt;/span&gt;
        Cache::lock&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"update-visited-1"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;-&amp;gt;get&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            // Your &lt;span class="nb"&gt;command &lt;/span&gt;&lt;span class="k"&gt;function &lt;/span&gt;code goes here
        &lt;span class="o"&gt;})&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Save and close the file.&lt;/p&gt;

&lt;p&gt;Now run the console commands to check if its working properly by using the command below,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;php artisan &lt;span class="nb"&gt;command&lt;/span&gt;:name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After this, Add this command in "kernal.php". To do so, open "/my_app_name/app/Console/Kernel.php" and add the command as below,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;protected &lt;span class="k"&gt;function &lt;/span&gt;schedule&lt;span class="o"&gt;(&lt;/span&gt;Schedule &lt;span class="nv"&gt;$schedule&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$schedule&lt;/span&gt;-&amp;gt;command&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'command:name'&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;-&amp;gt;everyMinute&lt;span class="o"&gt;()&lt;/span&gt;-&amp;gt;onOneServer&lt;span class="o"&gt;()&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;save and close the file.&lt;/p&gt;

&lt;p&gt;To check the above condition, run the schedule job by running the below command,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;php artisan schedule:run
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It should run the functions we created in the console commands.&lt;br&gt;
Once it is verified, Last step is to add this scheduler in the crontab.&lt;/p&gt;

&lt;p&gt;Open crontab by using,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;crontab &lt;span class="nt"&gt;-e&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In that file add the following line to add our scheduler in the crontab,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;*&lt;/span&gt; &lt;span class="k"&gt;*&lt;/span&gt; &lt;span class="k"&gt;*&lt;/span&gt; &lt;span class="k"&gt;*&lt;/span&gt; &lt;span class="k"&gt;*&lt;/span&gt; &lt;span class="nb"&gt;cd&lt;/span&gt; /var/www/my_app_name &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; php artisan schedule:run &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; /dev/null 2&amp;gt;&amp;amp;1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's all. Viola ! We did this.&lt;/p&gt;

&lt;p&gt;We need to take a AMI Image of this instance and launch the AMI as a new instance and check all "Security Groups" to allow "http" with port "80" to server our application and launch the instance.&lt;/p&gt;

&lt;p&gt;Now we have the multiple instance with single cron running.&lt;/p&gt;

&lt;p&gt;Feel free to pull request on modifying this content on my github respository&lt;br&gt;
&lt;a href="https://github.com/manivaidhy/laravel-single-cron-on-multiple-servers"&gt;https://github.com/manivaidhy/laravel-single-cron-on-multiple-servers&lt;/a&gt;&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>php</category>
      <category>cron</category>
      <category>multiserver</category>
    </item>
  </channel>
</rss>
