<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Abdulrasheed Apampa'blog]]></title><description><![CDATA[Abdulrasheed Apampa'blog]]></description><link>https://abdulrasheedapampa.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Thu, 24 Sep 2026 07:15:11 GMT</lastBuildDate><atom:link href="https://abdulrasheedapampa.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Comprehensive Guide: Linux User(s) Creation using Bash Script]]></title><description><![CDATA[Introduction
In the dynamic field of DevOps, automating routine tasks like user management is pivotal for efficiency and consistency. This guide explores a Bash script designed to create Linux users, assign them to specified groups, log actions, and ...]]></description><link>https://abdulrasheedapampa.hashnode.dev/comprehensive-guide-linux-users-creation-using-bash-script</link><guid isPermaLink="true">https://abdulrasheedapampa.hashnode.dev/comprehensive-guide-linux-users-creation-using-bash-script</guid><category><![CDATA[Bash]]></category><dc:creator><![CDATA[Apampa Abdulrasheed]]></dc:creator><pubDate>Mon, 01 Jul 2024 20:30:36 GMT</pubDate><content:encoded><![CDATA[<h2 id="heading-introduction">Introduction</h2>
<p>In the dynamic field of DevOps, automating routine tasks like user management is pivotal for efficiency and consistency. This guide explores a Bash script designed to create Linux users, assign them to specified groups, log actions, and securely store passwords. Whether you're a seasoned DevOps engineer, a budding system administrator, or an enthusiastic learner like myself enrolled in the HNG internship, mastering this script can significantly enhance your automation skills and contribute to robust system management practices.</p>
<h2 id="heading-script-overview">Script Overview</h2>
<h3 id="heading-shebang-and-description">Shebang and Description</h3>
<pre><code class="lang-bash"><span class="hljs-meta">#!/bin/bash</span>
</code></pre>
<p>The script starts with <code>#!/bin/bash</code>Ensuring compatibility with the Bash shell environment is essential for executing Bash scripts effectively.</p>
<h3 id="heading-checking-for-arguments">Checking for Arguments</h3>
<pre><code class="lang-bash"><span class="hljs-keyword">if</span> [ <span class="hljs-string">"<span class="hljs-variable">$#</span>"</span> -ne 1 ]; <span class="hljs-keyword">then</span>
    <span class="hljs-built_in">echo</span> <span class="hljs-string">"Usage: <span class="hljs-variable">$0</span> &lt;user_file&gt;"</span>
    <span class="hljs-built_in">exit</span> 1
<span class="hljs-keyword">fi</span>
</code></pre>
<p>To maintain script integrity, it checks whether the correct number of arguments (in this case, the user input file) is provided during execution. This ensures clarity and prevents unexpected errors.</p>
<h3 id="heading-file-existence-check">File Existence Check</h3>
<pre><code class="lang-bash">USER_FILE=<span class="hljs-string">"<span class="hljs-variable">$1</span>"</span>

<span class="hljs-keyword">if</span> [ ! -f <span class="hljs-string">"<span class="hljs-variable">$USER_FILE</span>"</span> ]; <span class="hljs-keyword">then</span>
    <span class="hljs-built_in">echo</span> <span class="hljs-string">"Error: File <span class="hljs-variable">$USER_FILE</span> does not exist."</span>
    <span class="hljs-built_in">exit</span> 1
<span class="hljs-keyword">fi</span>
</code></pre>
<p>The script verifies the existence of the specified user input file (<code>$1</code>). If the file is not found, it promptly notifies the user with an error message, ensuring smooth execution by handling potential file-related issues upfront.</p>
<h3 id="heading-variable-assignments">Variable Assignments</h3>
<pre><code class="lang-bash">LOG_FILE=<span class="hljs-string">"/var/log/user_management.log"</span>
PASSWORD_DIR=<span class="hljs-string">"/var/secure"</span>
PASSWORD_FILE=<span class="hljs-string">"<span class="hljs-variable">$PASSWORD_DIR</span>/user_passwords.csv"</span>
</code></pre>
<p>To streamline file management and ensure clarity within the script, critical paths and filenames are assigned to variables. This practice not only enhances script readability but also facilitates future modifications and scalability.</p>
<h3 id="heading-log-file-creation">Log File Creation</h3>
<pre><code class="lang-bash">touch <span class="hljs-variable">$LOG_FILE</span>
</code></pre>
<p>To maintain a systematic record of script actions and facilitate troubleshooting, the script ensures the existence of a log file (<code>user_management.log</code>). The <code>touch</code> command updates the file's access and modification timestamps or creates it if it doesn't already exist.</p>
<h3 id="heading-password-directory-and-file-setup">Password Directory and File Setup</h3>
<pre><code class="lang-bash"><span class="hljs-keyword">if</span> [ ! -d <span class="hljs-string">"<span class="hljs-variable">$PASSWORD_DIR</span>"</span> ]; <span class="hljs-keyword">then</span>
    mkdir -p <span class="hljs-string">"<span class="hljs-variable">$PASSWORD_DIR</span>"</span>
    chmod 700 <span class="hljs-string">"<span class="hljs-variable">$PASSWORD_DIR</span>"</span>
<span class="hljs-keyword">fi</span>

<span class="hljs-keyword">if</span> [ ! -f <span class="hljs-string">"<span class="hljs-variable">$PASSWORD_FILE</span>"</span> ]; <span class="hljs-keyword">then</span>
    <span class="hljs-built_in">echo</span> <span class="hljs-string">"username,password"</span> &gt;&gt; <span class="hljs-variable">$PASSWORD_FILE</span>
<span class="hljs-keyword">fi</span>
chmod 600 <span class="hljs-variable">$PASSWORD_FILE</span>
</code></pre>
<p>Recognizing the importance of security in managing sensitive data like passwords, the script meticulously sets up the password directory (<code>/var/secure</code>). If the directory doesn't exist, it creates it with restricted permissions (<code>700</code>), ensuring only authorized access. Additionally, it manages the password file (<code>user_passwords.csv</code>) by initializing it with a header and setting appropriate permissions (<code>600</code>) to safeguard sensitive information.</p>
<h3 id="heading-logging-function">Logging Function</h3>
<pre><code class="lang-bash"><span class="hljs-function"><span class="hljs-title">log_action</span></span>() {
    <span class="hljs-built_in">echo</span> <span class="hljs-string">"<span class="hljs-subst">$(date '+%Y-%m-%d %H:%M:%S')</span> - <span class="hljs-variable">$1</span>"</span> &gt;&gt; <span class="hljs-variable">$LOG_FILE</span>
}
</code></pre>
<p>To provide visibility into script execution and facilitate comprehensive audit trails, a dedicated <code>log_action</code> function is defined. This function captures timestamped actions and appends them to the log file (<code>user_management.log</code>), ensuring clarity and accountability in script operations.</p>
<h3 id="heading-reading-and-processing-the-input-file">Reading and Processing the Input File</h3>
<pre><code class="lang-bash"><span class="hljs-keyword">while</span> IFS=<span class="hljs-string">';'</span> <span class="hljs-built_in">read</span> -r username groups; <span class="hljs-keyword">do</span>

    username=$(<span class="hljs-built_in">echo</span> <span class="hljs-string">"<span class="hljs-variable">$username</span>"</span> | xargs)
    groups=$(<span class="hljs-built_in">echo</span> <span class="hljs-string">"<span class="hljs-variable">$groups</span>"</span> | xargs)
</code></pre>
<p>Operating in dynamic environments often necessitates handling varied input formats effectively. The script utilizes <code>IFS=';'</code> to process each line of the user input file, separating <code>username</code> and <code>groups</code> data fields. This technique ensures consistency and accuracy in data parsing, preparing the script for diverse operational scenarios.</p>
<h3 id="heading-user-and-group-creation">User and Group Creation</h3>
<pre><code class="lang-bash">    <span class="hljs-keyword">if</span> id -u <span class="hljs-string">"<span class="hljs-variable">$username</span>"</span> &gt;/dev/null 2&gt;&amp;1; <span class="hljs-keyword">then</span>
        log_action <span class="hljs-string">"User <span class="hljs-variable">$username</span> already exists."</span>
        <span class="hljs-built_in">continue</span>
    <span class="hljs-keyword">fi</span>

    <span class="hljs-keyword">if</span> ! getent group <span class="hljs-string">"<span class="hljs-variable">$username</span>"</span> &gt;/dev/null 2&gt;&amp;1; <span class="hljs-keyword">then</span>
        groupadd <span class="hljs-string">"<span class="hljs-variable">$username</span>"</span>
    <span class="hljs-keyword">fi</span>

    useradd -m -g <span class="hljs-string">"<span class="hljs-variable">$username</span>"</span> -s /bin/bash <span class="hljs-string">"<span class="hljs-variable">$username</span>"</span>

    chmod 700 /home/<span class="hljs-string">"<span class="hljs-variable">$username</span>"</span>
    chown <span class="hljs-string">"<span class="hljs-variable">$username</span>:<span class="hljs-variable">$username</span>"</span> /home/<span class="hljs-string">"<span class="hljs-variable">$username</span>"</span>

    password=$(openssl rand -base64 12)

    <span class="hljs-built_in">echo</span> <span class="hljs-string">"<span class="hljs-variable">$username</span>:<span class="hljs-variable">$password</span>"</span> | chpasswd

    <span class="hljs-built_in">echo</span> <span class="hljs-string">"<span class="hljs-variable">$username</span>,<span class="hljs-variable">$password</span>"</span> &gt;&gt; <span class="hljs-variable">$PASSWORD_FILE</span>
</code></pre>
<p>Effective user management forms the backbone of system administration tasks. The script checks for existing users and, if necessary, creates corresponding user groups to maintain organizational structure and operational efficiency. It ensures home directory permissions (<code>700</code>) are correctly set, assign ownership, generate secure passwords using OpenSSL, and manage password storage securely in the designated file (<code>user_passwords.csv</code>).</p>
<h3 id="heading-additional-groups">Additional Groups</h3>
<pre><code class="lang-bash">    <span class="hljs-keyword">if</span> [ -n <span class="hljs-string">"<span class="hljs-variable">$groups</span>"</span> ]; <span class="hljs-keyword">then</span>
        IFS=<span class="hljs-string">','</span> <span class="hljs-built_in">read</span> -r -a group_array &lt;&lt;&lt; <span class="hljs-string">"<span class="hljs-variable">$groups</span>"</span>
        <span class="hljs-keyword">for</span> group <span class="hljs-keyword">in</span> <span class="hljs-string">"<span class="hljs-variable">${group_array[@]}</span>"</span>; <span class="hljs-keyword">do</span>
            group=$(<span class="hljs-built_in">echo</span> <span class="hljs-string">"<span class="hljs-variable">$group</span>"</span> | xargs)
            <span class="hljs-keyword">if</span> ! getent group <span class="hljs-string">"<span class="hljs-variable">$group</span>"</span> &gt;/dev/null 2&gt;&amp;1; <span class="hljs-keyword">then</span>
                groupadd <span class="hljs-string">"<span class="hljs-variable">$group</span>"</span>
            <span class="hljs-keyword">fi</span>
            usermod -aG <span class="hljs-string">"<span class="hljs-variable">$group</span>"</span> <span class="hljs-string">"<span class="hljs-variable">$username</span>"</span>
        <span class="hljs-keyword">done</span>
    <span class="hljs-keyword">fi</span>

    log_action <span class="hljs-string">"User <span class="hljs-variable">$username</span> created with groups: <span class="hljs-variable">$username</span>, <span class="hljs-variable">$groups</span>"</span>
<span class="hljs-keyword">done</span> &lt; <span class="hljs-variable">$USER_FILE</span>
</code></pre>
<p>In dynamic environments, user roles often extend beyond primary assignments. The script accommodates additional user groups specified in the input file (<code>$groups</code>). It iterates through each group, ensuring their existence and adding the user to these groups using <code>usermod -aG</code>. This flexibility ensures comprehensive user role management, adapting to diverse organizational needs seamlessly.</p>
<h3 id="heading-logging-completion">Logging Completion</h3>
<pre><code class="lang-bash">log_action <span class="hljs-string">"User creation process completed."</span>
</code></pre>
<p>Upon successfully creating users and assigning roles, the script concludes by logging the completion of the user creation process. This final step provides a comprehensive overview of script operations, ensuring transparency and enabling effective troubleshooting if needed.</p>
<h2 id="heading-running-the-script">Running the Script</h2>
<p>To run the script, follow these steps:</p>
<ol>
<li><p><strong>Clone the Script</strong>: Ensure you have the <a target="_blank" href="https://github.com/AbdulrasheedApampa/DevOps-Stage-1-Linux-User-Creation-Bash-Script.git">Bash script</a> (<code>create_users.sh</code>) available on your Linux machine.</p>
</li>
<li><p><strong>Prepare User Input File</strong>: Create a text file (<code>user_list.txt</code>) containing usernames and their associated groups in the format <code>username;groups</code>. For example:</p>
<pre><code class="lang-plaintext"> user1;group1,group2
 user2;group3
 user3;
</code></pre>
</li>
<li><p><strong>Execute the Script</strong>: Open your terminal and navigate to the directory containing <code>create_</code><a target="_blank" href="http://users.sh"><code>users.sh</code></a>.</p>
<pre><code class="lang-bash"> chmod +x create_users.sh
 ./create_users.sh user_list.txt
</code></pre>
<p> Replace <code>user_list.txt</code> with the path to your prepared user input file.</p>
</li>
<li><p><strong>Verify Execution</strong>: Monitor the terminal for script output. Check <code>/var/log/user_management.log</code> for detailed logs of the script's actions.</p>
</li>
<li><p><strong>Password Storage</strong>: Passwords are securely stored in <code>/var/secure/user_passwords.csv</code>. Only the file owner has read access to maintain confidentiality.</p>
</li>
</ol>
<h2 id="heading-conclusion">Conclusion</h2>
<p>This comprehensive guide demonstrates the critical role of automation in DevOps environments, emphasizing efficient user management practices through a Bash script. By understanding and customizing this script, DevOps engineers, system administrators, and aspiring interns like myself can enhance operational efficiency, strengthen security protocols, and maintain meticulous audit trails. As I continue my journey in the HNG internship program, mastering these foundational skills is essential for progressing to more advanced stages and contributing effectively to real-world projects.</p>
<p>For more information about the HNG Internship program and its benefits, visit <a target="_blank" href="https://hng.tech/internship">HNG Internship</a> and <a target="_blank" href="https://hng.tech/premium">HNG Premium</a>.</p>
<hr />
]]></content:encoded></item><item><title><![CDATA[Laravel Application Deployment  With Docker]]></title><description><![CDATA[Prerequisites
Before you start, you will need;
1. A running ubuntu operating system download or you can use a cloud provider
2. You must have docker installed on your VM
Step1 - Download laravel and it's dependencies
The first step is to get the lara...]]></description><link>https://abdulrasheedapampa.hashnode.dev/laravel-application-deployment-with-docker</link><guid isPermaLink="true">https://abdulrasheedapampa.hashnode.dev/laravel-application-deployment-with-docker</guid><category><![CDATA[laravelframework]]></category><category><![CDATA[Laravel]]></category><category><![CDATA[PHP]]></category><category><![CDATA[nginx]]></category><category><![CDATA[MySQL]]></category><dc:creator><![CDATA[Apampa Abdulrasheed]]></dc:creator><pubDate>Sun, 12 Feb 2023 15:35:14 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1676215633315/8f8571fb-6851-4e33-b5fa-d6240eaa65a2.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-prerequisites">Prerequisites</h2>
<h4 id="heading-before-you-start-you-will-need">Before you start, you will need;</h4>
<h4 id="heading-1-a-running-ubuntu-operating-system-download-or-you-can-use-a-cloud-provider"><em>1. A running ubuntu operating system download or you can use a cloud provider</em></h4>
<h4 id="heading-2-you-must-have-docker-installed-on-your-vm"><em>2. You must have docker installed on your VM</em></h4>
<h2 id="heading-step1-download-laravel-and-its-dependencies">Step1 - Download laravel and it's dependencies</h2>
<h4 id="heading-the-first-step-is-to-get-the-laravel-clone-to-our-home-directory-or-if-you-can-create-a-directory-and-clone-laravel-app-to-the-directory-the-github-repo-comes-with-a-composer-file-an-application-level-dependey-manager-for-php-since-we-are-trying-to-used-all-the-dependencies-as-a-docker-container-let-fire-up-our-terminal">The first step is to get the laravel clone to our home directory or if you can create a directory and clone laravel app to the directory. The Github repo comes with a composer file, an application-level dependey manager for PHP. Since we are trying to used all the dependencies as a docker container. let fire up our terminal...</h4>
<h4 id="heading-cd-to-home-directory-or-you-can-cd-to-your-project-directory"><strong>cd to home directory or you can cd to your project directory.</strong></h4>
<h4 id="heading-git-clone-httpsgithubcomlaravellaravelgithttpsgithubcomlaravellaravelgit-home-directory"><strong>git clone</strong> <a target="_blank" href="https://github.com/laravel/laravel.git"><strong>https://github.com/laravel/laravel.git</strong></a> <strong>home directory</strong>.</h4>
<p><code>git clone</code> <a target="_blank" href="https://github.com/laravel/laravel.git"><code>https://github.com/laravel/laravel.git</code></a></p>
<h4 id="heading-now-copy-the-content-in-laravel-directory-to-a-new-laravel-app-directory">Now copy the content in laravel directory to a new laravel-app directory</h4>
<p><code>cp laravel laravel-app</code></p>
<h4 id="heading-after-it-is-done-cloning-move-into-your-laravel-app-directory-and-use-dockers-composer-image-to-mount-the-directories-that-you-will-need-for-your-laravel-project-and-avoid-the-overhead-of-installing-composer-globally-with-the-below-command">After it is done cloning, move into your laravel-app directory and use Docker’s composer image to mount the directories that you will need for your Laravel project and avoid the overhead of installing Composer globally with the below command:</h4>
<p><code>docker run --rm -v $(pwd):/app composer install</code></p>
<h4 id="heading-the-v-and-rm-create-an-an-ephemeral-container-that-will-be-bind-mounted-to-your-current-directory-before-being-removed-and-copy-the-content-of-you-laravel-app-directory-to-the-container-and-also-make-sure-that-the-vendor-folder-composer-creates-inside-the-container-is-copied-to-your-current-directory">The -v and -rm create an an ephemeral container that will be bind-mounted to your current directory before being removed. And copy the content of you laravel-app directory to the container and also make sure that the vendor folder Composer creates inside the container is copied to your current directory.</h4>
<h4 id="heading-the-next-step-is-to-set-a-permissions-on-the-laravel-app-project-directory-so-that-it-is-owned-by-your-non-root-user">The next step is to set a permissions on the laravel-app project directory so that it is owned by your non-root user</h4>
<p><code>sudo chown -R $USER:$USER ~/laravel-app</code></p>
<h4 id="heading-this-will-be-very-important-when-you-are-writing-a-dockerfile-for-your-application-image-as-it-will-allow-your-application-container-to-run-as-non-root-user">This will be very important when you are writing a dockerfile for your application image, as it will allow your application container to run as non-root user.</h4>
<h2 id="heading-step-2-let-create-dockerfile-in-our-laravel-app-directory">Step - 2 Let create dockerfile in our laravel-app directory</h2>
<p><code>cd laravel-app</code></p>
<h4 id="heading-dockerfile-includes-instructions-that-docker-can-use-to-build-custom-docker-images-it-can-also-install-the-software-required-and-configure-the-necessary-settings-for-your-application-they-specify-the-environment-inside-a-container-that-will-host-your-application-code-you-may-push-the-images-you-create-to-docker-hub-for-sharing-or-place-them-on-other-private-registries">Dockerfile includes instructions that Docker can use to build custom Docker images. It can also install the software required and configure the necessary settings for your application. They specify the environment inside a container that will host your application code. You may push the images you create to docker hub for sharing or place them on other private registries.</h4>
<h4 id="heading-we-will-create-a-dockerfile-that-will-specify-the-instructions-to-build-the-laravel-application-image-use-nano-to-create-the-dockerfile-in-laravel-web-directory">We will create a Dockerfile that will specify the instructions to build the Laravel application image. Use nano to create the Dockerfile in ~/laravel-web directory:</h4>
<h3 id="heading-copy-the-content-of-the-dockerfile-in-this-repo-to-create-your-dockerfile-in-your-vm">Copy the content of the Dockerfile in this repo to create your Dockerfile in your VM</h3>
<p><code>sudo nano Dockerfile</code></p>
<h2 id="heading-what-is-going-in-the-dockerfile">What is going in the dockerfile??</h2>
<h4 id="heading-first-the-dockerfile-creates-an-image-on-top-of-the-php8-fpm-docker-image-this-is-a-debian-based-image-that-has-the-php-fastcgi-implementation-php-fpm-installed-the-file-also-installs-the-prerequisite-packages-for-laravel-mcrypt-pdomysql-mbstring-and-imagick-with-composer">First, the Dockerfile creates an image on top of the php:8-fpm Docker image. This is a Debian-based image that has the PHP FastCGI implementation PHP-FPM installed. The file also installs the prerequisite packages for Laravel: mcrypt, pdo_mysql, mbstring, and imagick with composer.</h4>
<h4 id="heading-the-run-directive-specifies-the-commands-to-update-install-and-configure-settings-inside-the-container-including-creating-a-dedicated-user-and-group-called-www-the-workdir-instruction-specifies-the-varwww-directory-as-the-working-directory-for-the-application">The RUN directive specifies the commands to update, install, and configure settings inside the container, including creating a dedicated user and group called www. The WORKDIR instruction specifies the /var/www directory as the working directory for the application.</h4>
<h4 id="heading-creating-a-dedicated-user-and-group-with-restricted-permissions-mitigates-the-inherent-vulnerability-when-running-docker-containers-which-run-by-default-as-root-instead-of-running-this-container-as-root-weve-created-the-www-user-who-has-readwrite-access-to-the-varwww-folder-thanks-to-the-copy-instruction-that-we-are-using-with-the-chown-flag-to-copy-the-application-folders-permissions">Creating a dedicated user and group with restricted permissions mitigates the inherent vulnerability when running Docker containers, which run by default as root. Instead of running this container as root, we’ve created the www user, who has read/write access to the /var/www folder thanks to the COPY instruction that we are using with the --chown flag to copy the application folder’s permissions.</h4>
<h4 id="heading-finally-the-expose-command-exposes-a-port-in-the-container-9000-for-the-php-fpm-server-cmd-specifies-the-command-that-should-run-once-the-container-is-created-here-cmd-specifies-php-fpm-which-will-start-the-server">Finally, the EXPOSE command exposes a port in the container, 9000, for the php-fpm server. CMD specifies the command that should run once the container is created. Here, CMD specifies "php-fpm", which will start the server.</h4>
<h4 id="heading-save-the-file-and-exit-your-editor-when-you-are-finished-making-changes">Save the file and exit your editor when you are finished making changes.</h4>
<h2 id="heading-step-3-let-make-configuration-directory-inside-our-laravel-app">step 3 - Let make configuration directory inside our laravel-app</h2>
<h4 id="heading-this-configuration-directory-will-be-called-inside-our-docker-compose-file-as-volumes-to-mount-the-dirctory-to-our-containers">This configuration directory will be called inside our docker-compose file as volumes to mount the dirctory to our containers.</h4>
<h3 id="heading-1-php-configuratioin-directory">1. PHP Configuratioin Directory</h3>
<h4 id="heading-to-configure-php-you-will-create-the-localini-file-inside-the-php-folder-this-is-the-file-that-you-bind-mounted-to-usrlocaletcphpconfdlocalini-inside-the-our-laravel-app-container-creating-this-file-will-allow-you-to-override-the-default-phpini-file-that-php-reads-when-it-starts">To configure PHP, you will create the local.ini file inside the php folder. This is the file that you bind-mounted to /usr/local/etc/php/conf.d/local.ini inside #### the our laravel-app container. Creating this file will allow you to override the default php.ini file that PHP reads when it starts.</h4>
<h3 id="heading-create-the-php-directory-inside-our-laravel-app-directory">Create the php directory inside our laravel-app directory:</h3>
<p><code>mkdir /laravel-app/php</code></p>
<h4 id="heading-next-you-have-nano-out-the-localini-inside-the-php-directory">next you have nano out the local.ini inside the php directory.</h4>
<p><code>nano laravel-app/php/local.ini</code></p>
<h4 id="heading-the-default-phpini-file-has-an-upload-limit-set-to-2m-as-an-example-we-will-show-you-to-adjust-and-set-php-configurations-by-changing-the-value-of-the-allowed-upload-limit-in-case-you-want-to-upload-larger-files-enter-the-following-lines-of-code-inside-the-file">The default php.ini file has an upload limit set to 2M. As an example, we will show you to adjust and set php configurations by changing the value of the allowed #### upload limit, in case you want to upload larger files. Enter the following lines of code inside the file:</h4>
<p><code>upload_max_filesize=40M</code></p>
<p><code>post_max_size=40M</code></p>
<h4 id="heading-2-nginx-configuration-directory">2. Nginx configuration directory</h4>
<h4 id="heading-in-this-step-we-will-configure-nginx-to-use-the-php-service-we-defined-earlier-it-will-use-php-fpm-as-the-fastcgi-server-to-serve-dynamic-content-fastcgi-server-is-a-software-that-enables-interactive-programs-to-interface-with-a-web-server">In this step, we will configure Nginx to use the php service we defined earlier. It will use PHP-FPM as the FastCGI server to serve dynamic content. FastCGI server is a software that enables interactive programs to interface with a web server.</h4>
<h4 id="heading-to-configure-nginx-you-will-create-an-appconf-file-with-the-service-configuration-in-the-laravel-appnginxconfd-folder">To configure Nginx, you will create an app.conf file with the service configuration in the ~/laravel-app/nginx/conf.d/ folder.</h4>
<h4 id="heading-create-the-nginxconfd-directory">create the nginx/conf.d/ directory</h4>
<p><code>mkdir -p laravel-app/nginx/conf.d</code></p>
<h4 id="heading-next-create-appconf-configuration-file-inside-you-nginxconfd-directory">Next create app.conf configuration file inside you nginx/conf.d directory</h4>
<p><code>nano ~/laravel-app/nginx/conf.d/app.conf</code></p>
<h4 id="heading-add-the-following-line-of-code-insed-the-appconf-to-specify-nginx-configuration">Add the following line of code insed the app.conf to specify nginx configuration</h4>
<p><code>server { listen 80; index index.php index.html; error_log /var/log/nginx/error.log; access_log /var/log/nginx/access.log; root /var/www/public; location ~ .php$ { try_files $uri =404; fastcgi_split_path_info ^(.+.php)(/.+)$; fastcgi_pass app:9000; fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; } location / { try_files $uri $uri/ /index.php?$query_string; gzip_static on; } }</code></p>
<h4 id="heading-3-mysql-configuration-dirctory">3. Mysql configuration dirctory</h4>
<h4 id="heading-to-configure-mysql-you-will-create-the-mycnf-file-in-the-mysql-folder-this-is-the-file-that-you-bind-mounted-to-etcmysqlmycnf-inside-the-container-in-step-this-bind-mount-allows-you-to-override-the-mycnf-settings-as-and-when-required">To configure MySQL, you will create the my.cnf file in the mysql folder. This is the file that you bind-mounted to /etc/mysql/my.cnf inside the container in Step This bind mount allows you to override the my.cnf settings as and when required.</h4>
<h4 id="heading-to-demonstrate-how-this-works-well-add-settings-to-the-mycnf-file-that-enable-the-general-query-log-and-specify-the-log-file">To demonstrate how this works, we’ll add settings to the my.cnf file that enable the general query log and specify the log file.</h4>
<h4 id="heading-create-mysql-directory">create mysql directory;</h4>
<p><code>mkdir laravel-app/mysql</code></p>
<h4 id="heading-next-create-a-file-inside-your-mysql-directory">Next create a file inside your mysql directory</h4>
<p><code>nano laravel-app/mysql/my.cnf</code></p>
<h4 id="heading-in-the-file-add-the-following-code-to-enable-the-query-log-and-set-the-log-file-location">In the file, add the following code to enable the query log and set the log file location:</h4>
<p><code>[mysqld]</code></p>
<p><code>general_log = 1</code></p>
<p><code>general_log_file = /var/lib/mysql/general.log</code></p>
<h4 id="heading-this-mycnf-file-enables-logs-defining-the-generallog-setting-as-1-to-allow-general-logs-the-generallogfile-setting-specifies-where-the-logs-will-be-stored-save-and-exit-the-editor">This my.cnf file enables logs, defining the general_log setting as 1 to allow general logs. The general_log_file setting specifies where the logs will be stored. save and exit the editor.</h4>
<h4 id="heading-step-4-modifying-environment-settings-and-running-the-containers">Step 4 - Modifying Environment Settings and Running the Containers</h4>
<h4 id="heading-will-make-a-copy-of-the-envexample-file-that-laravel-includes-by-default-and-name-the-copy-env-which-is-the-file-laravel-expects-to-define-its-environment">will make a copy of the .env.example file that Laravel includes by default and name the copy .env, which is the file Laravel expects to define its environment:</h4>
<p>cp .env.example .env</p>
<h4 id="heading-you-can-now-modify-the-env-file-on-the-app-container-to-include-specific-details-about-your-setup">You can now modify the .env file on the app container to include specific details about your setup.</h4>
<h4 id="heading-open-the-file-using-nano-or-your-text-editor-of-choice">Open the file using nano or your text editor of choice:</h4>
<p>nano .env</p>
<h4 id="heading-find-the-block-that-specifies-dbconnection-and-update-it-to-reflect-the-specifics-of-your-setup-you-will-modify-the-following-fields">Find the block that specifies DB_CONNECTION and update it to reflect the specifics of your setup. You will modify the following fields:</h4>
<h5 id="heading-dbhost-will-be-your-db-database-container"><mark>.DB_HOST will be your </mark> <strong><mark>db</mark></strong> <mark> database container.</mark></h5>
<h5 id="heading-dbdatabase-will-be-the-laravel-database"><mark>.DB_DATABASE will be the</mark> <strong><mark> laravel database</mark></strong><mark>.</mark></h5>
<h5 id="heading-dbusername-will-be-the-username-you-will-use-for-your-database-in-this-case-we-will-use-laraveluser"><mark>.DB_USERNAME will be the username you will use for your database. In this case, we will use </mark> <strong><mark>laraveluser</mark></strong><mark>.</mark></h5>
<h5 id="heading-dbpassword-will-be-the-secure-password-you-would-like-to-use-for-this-user-account"><mark>.DB_PASSWORD will be the secure password you would like to use for this user account.</mark></h5>
<h4 id="heading-save-the-file-and-exit-your-editor">Save the file and exit your editor.</h4>
<h2 id="heading-step-5-creating-the-docker-compose-file">Step - 5 Creating the Docker Compose File</h2>
<h4 id="heading-docker-compose-simplifies-the-process-of-setting-up-and-versioning-your-infrastructure-to-set-up-our-laravel-application-we-will-write-a-docker-compose-file-that-defines-our-web-server-database-and-application-services">Docker Compose simplifies the process of setting up and versioning your infrastructure. To set up our Laravel application, we will write a docker-compose file that defines our web server, database, and application services.</h4>
<h3 id="heading-please-checkout-my-docker-compose-file-code-in-this-repo">Please checkout my docker compose file code in this repo.</h3>
<h2 id="heading-note-the-volumes-inside-the-docker-compose-file-is-used-in-mounting-the-configuration-files-we-created-in-step-3-to-our-container-directory">Note: the volumes inside the docker compose file is used in mounting the configuration files we created in step 3 to our container directory.</h2>
<h4 id="heading-with-all-of-your-services-defined-in-your-docker-compose-file-you-just-need-to-issue-a-single-command-to-start-all-of-the-containers-create-the-volumes-and-set-up-and-connect-the-networks">With all of your services defined in your docker-compose file, you just need to issue a single command to start all of the containers, create the volumes, and set up and connect the networks:</h4>
<p><code>sudo apt install docker-compose</code></p>
<p><code>sudo docker-compose up -d</code></p>
<h4 id="heading-when-you-run-docker-compose-up-for-the-first-time-it-will-download-all-of-the-necessary-docker-images-which-might-take-a-while-once-the-images-are-downloaded-and-stored-in-your-local-machine-compose-will-create-your-containers-the-d-flag-daemonizes-the-process-running-your-containers-in-the-background">When you run docker-compose up for the first time, it will download all of the necessary Docker images, which might take a while. Once the images are downloaded and stored in your local machine, Compose will create your containers. The -d flag daemonizes the process, running your containers in the background.</h4>
<h4 id="heading-well-now-use-docker-compose-exec-to-set-the-application-key-for-the-laravel-application-the-docker-compose-exec-command-allows-you-to-run-specific-commands-in-containers">We’ll now use docker-compose exec to set the application key for the Laravel application. The docker-compose exec command allows you to run specific commands in containers.</h4>
<h4 id="heading-the-following-command-will-generate-a-key-and-copy-it-to-your-env-file-ensuring-that-your-user-sessions-and-encrypted-data-remain-secure">The following command will generate a key and copy it to your .env file, ensuring that your user sessions and encrypted data remain secure:</h4>
<p><code>sudo docker-compose exec app php artisan key:generate</code></p>
<p><code>sudo docker-compose exec app php artisan config:cache</code></p>
<h4 id="heading-step-6-creating-a-user-for-mysql">Step - 6 Creating a User for MySQL</h4>
<h4 id="heading-the-default-mysql-installation-only-creates-the-root-administrative-account-which-has-unlimited-privileges-on-the-database-server-in-general-its-better-to-avoid-using-the-root-administrative-account-when-interacting-with-the-database-instead-well-create-a-dedicated-database-user-for-our-applications-laravel-database">The default MySQL installation only creates the root administrative account, which has unlimited privileges on the database server. In general, it’s better to avoid using the root administrative account when interacting with the database. Instead, we'll create a dedicated database user for our application’s Laravel database.</h4>
<h4 id="heading-to-create-a-new-user-execute-an-interactive-bash-shell-on-the-db-container-with-docker-compose-exec">To create a new user, execute an interactive bash shell on the db container with docker-compose exec:</h4>
<p><code>sudo docker-compose exec db bash</code></p>
<h4 id="heading-inside-the-container-log-into-the-mysql-root-administrative-account">Inside the container, log into the MySQL root administrative account:</h4>
<p><code>mysql -u root -p</code></p>
<h4 id="heading-you-will-be-prompted-for-the-password-you-set-for-the-mysql-root-account-during-installation-in-your-docker-compose-file">You will be prompted for the password you set for the MySQL root account during installation in your docker-compose file.</h4>
<h4 id="heading-next-create-the-user-account-that-will-be-allowed-to-access-this-database-in-my-case-my-username-is-laravel-though-you-can-replace-this-with-another-name-if-youd-prefer-just-be-sure-that-your-username-and-password-here-match-the-details-you-set-in-your-env-file-in-the-previous-step">Next, create the user account that will be allowed to access this database. in my case, my username is laravel, though you can replace this with another name if you’d prefer. Just be sure that your username and password here match the details you set in your .env file in the previous step:</h4>
<p><code>GRANT ALL ON laravel.* TO 'laravel'@'%' IDENTIFIED BY 'your_laravel_db_password';</code></p>
<h4 id="heading-flush-the-privileges-to-notify-the-mysql-server-of-the-changes">Flush the privileges to notify the MySQL server of the changes:</h4>
<p><code>FLUSH PRIVILEGES;</code></p>
<h4 id="heading-then-exit-mysql-and-exit-your-container-also">Then exit mysql and exit your container also</h4>
<h2 id="heading-step-7-migration-composer-install-and-composer-update">Step - 7 Migration, composer install and composer update</h2>
<h4 id="heading-run-the-below-commands">Run the below commands</h4>
<p><code>sudo docker-compose exec app composer install</code></p>
<p><code>sudo docker-compose exec app composer update</code></p>
<p><code>sudo docker-compose exec app php artisan migrate</code></p>
<h2 id="heading-conclusion">Conclusion</h2>
<h4 id="heading-with-this-readme-you-will-able-to-deploy-laravel-applications-with-docker-and-understand-how-to-use-docker">With this README, you will able to deploy laravel applications with docker and understand how to use docker</h4>
<h2 id="heading-sourcehttpswwwdigitaloceancomcommunitytutorialshow-to-set-up-laravel-nginx-and-mysql-with-docker-compose"><a target="_blank" href="https://www.digitalocean.com/community/tutorials/how-to-set-up-laravel-nginx-and-mysql-with-docker-compose"><code>SOURCE</code></a></h2>
<h2 id="heading-thank-you">Thank You</h2>
]]></content:encoded></item></channel></rss>