<?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" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Omprakashlamichhane on Medium]]></title>
        <description><![CDATA[Stories by Omprakashlamichhane on Medium]]></description>
        <link>https://medium.com/@omprakashlamichhane10?source=rss-92d3b6df1568------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*i2Z10QMvMsP2XXOT</url>
            <title>Stories by Omprakashlamichhane on Medium</title>
            <link>https://medium.com/@omprakashlamichhane10?source=rss-92d3b6df1568------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 22:37:19 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@omprakashlamichhane10/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Git for Beginners: A Complete Guide to Version Control]]></title>
            <link>https://medium.com/@omprakashlamichhane10/git-for-beginners-a-complete-guide-to-version-control-2d79a662d688?source=rss-92d3b6df1568------2</link>
            <guid isPermaLink="false">https://medium.com/p/2d79a662d688</guid>
            <dc:creator><![CDATA[Omprakashlamichhane]]></dc:creator>
            <pubDate>Thu, 29 Oct 2026 07:53:52 GMT</pubDate>
            <atom:updated>2026-10-29T07:53:52.858Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>Have you ever changed your code and later wished you could return to an earlier version? Or worked on a project and wanted to track every change you made?</p><p>This is where <strong>Git</strong> becomes useful.</p><p>Git is a free, open-source version control system that helps developers track changes in their code, collaborate with other developers, and manage different versions of a project.</p><p>In this blog, we will explore Git fundamentals, essential commands, branches, commits, and .gitignore with practical examples.</p><h3>1. What Is Git?</h3><p>Git is a distributed version control system. It records changes to files over time so that you can review your project’s history and restore previous versions when needed.</p><h3>Why do developers use Git?</h3><ul><li>Track changes in source code.</li><li>Restore previous versions of a project.</li><li>Work on features using separate branches.</li><li>Collaborate with other developers.</li><li>Maintain a history of commits.</li></ul><h3>2. Git vs. GitHub vs. GitLab</h3><p>These terms are related, but they are not the same.</p><ul><li><strong>Git:</strong> The tool that tracks changes in your project.</li><li><strong>GitHub:</strong> An online platform for hosting Git repositories.</li><li><strong>GitLab:</strong> Another platform for hosting repositories and managing development workflows, CI/CD, and collaboration.</li></ul><p>Git works locally on your computer. GitHub and GitLab can store your repositories remotely.</p><h3>3. Essential Git Commands</h3><p>Here are some commands every beginner should learn.</p><h3>Initialize a repository</h3><pre>git init</pre><p>Creates a new local Git repository in the current directory.</p><h3>Check the status</h3><pre>git status</pre><p>Shows your current branch and the state of your files.</p><h3>Stage changes</h3><pre>git add .</pre><p>Stages changes in the current directory and its subdirectories, subject to Git’s ignore rules.</p><h3>Commit changes</h3><pre>git commit -m &quot;Add homepage&quot;</pre><p>Creates a snapshot of the staged changes.</p><h3>View commit history</h3><pre>git log --oneline</pre><p>Displays a concise list of commits and their short hashes.</p><h3>Connect to a remote repository</h3><pre>git remote add origin &lt;repository-url&gt;</pre><p>Connects your local repository to a remote repository.</p><h3>Push changes</h3><pre>git push -u origin main</pre><p>Uploads your local main branch to the remote repository and sets its upstream tracking branch.</p><h3>4. What Is a Git Commit?</h3><p>A commit is a snapshot of staged changes in your project. Each commit has a unique identifier called a <strong>commit hash</strong>.</p><p>For example:</p><pre>707a0c9 Add login page<br>92aaf42 Create homepage<br>b0abace Initial commit</pre><p>You can inspect a particular commit using:</p><pre>git show 707a0c9</pre><p>To view the full hash of the latest commit:</p><pre>git rev-parse HEAD</pre><p>Commit hashes help you identify specific points in your project’s history.</p><h3>5. What Are Git Branches?</h3><p>A branch is a movable reference to a commit that lets you develop independently from other lines of work.</p><p>For example, you might have:</p><ul><li>main — the primary branch.</li><li>feature-login — a branch for implementing login functionality.</li><li>feature-dashboard — a branch for building a dashboard.</li></ul><p>Useful commands:</p><pre>git branch<br>git branch feature-login<br>git switch feature-login<br>git switch -c feature-dashboard</pre><p>The first command lists local branches. The second creates a branch, the third switches branches, and the fourth creates and switches to a new branch.</p><p>The names main and master are both valid branch names. Neither has a special technical advantage in Git itself.</p><h3>6. What Is Git Stash?</h3><p>Sometimes you need to switch branches before your current work is ready to commit. Git stash temporarily saves your changes so you can return to them later.</p><pre>git stash</pre><p>To see saved stashes:</p><pre>git stash list</pre><p>To restore the latest stash and remove it from the stash list:</p><pre>git stash pop</pre><p>To restore changes while keeping the stash entry:</p><pre>git stash apply</pre><p>If you also need to stash untracked files, use git stash -u.</p><h3>7. What Is .gitignore?</h3><p>The .gitignore file tells Git which matching untracked files and directories to ignore.</p><p>For example, a React project might use:</p><pre>node_modules/<br>dist/<br>.env<br>*.log</pre><p>This helps prevent dependency folders, build output, environment files, and logs from being added accidentally.</p><p><strong>Important:</strong> .gitignore does not automatically stop tracking files that Git already tracks. Also, never commit real passwords or API keys.</p><h3>8. A Simple Git Workflow</h3><p>A typical workflow looks like this:</p><pre># 1. Check the working directory<br>git status</pre><pre># 2. Stage changes<br>git add .</pre><pre># 3. Commit changes<br>git commit -m &quot;Update project&quot;</pre><pre># 4. Upload commits to the remote<br>git push</pre><p>Before pushing, make sure the correct branch is checked out and that your remote repository is configured. Protected branches may require a merge request instead of a direct push.</p><h3>9. Common Git Mistakes Beginners Should Avoid</h3><ol><li>Forgetting to stage changes before committing.</li><li>Confusing git commit with git push.</li><li>Accidentally committing .env files or other secrets.</li><li>Using git push --force without understanding its consequences.</li><li>Forgetting which branch is currently checked out.</li><li>Assuming .gitignore removes files that are already tracked.</li></ol><p>Learning what each command does is more valuable than memorizing commands without understanding them.</p><h3>Conclusion</h3><p>Git is an essential tool for modern software development and DevOps. By learning commits, branches, remote repositories, stash, and .gitignore, beginners can manage projects more safely and collaborate more effectively.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2d79a662d688" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Running WordPress with Docker, Nginx, PHP-FPM, FastCGI, and MySQL: A Beginner’s Journey]]></title>
            <link>https://medium.com/@omprakashlamichhane10/running-wordpress-with-docker-nginx-php-fpm-fastcgi-and-mysql-a-beginners-journey-7fa412a57a45?source=rss-92d3b6df1568------2</link>
            <guid isPermaLink="false">https://medium.com/p/7fa412a57a45</guid>
            <dc:creator><![CDATA[Omprakashlamichhane]]></dc:creator>
            <pubDate>Wed, 07 Oct 2026 17:31:35 GMT</pubDate>
            <atom:updated>2026-10-07T17:31:35.514Z</atom:updated>
            <content:encoded><![CDATA[<p>If you are learning Docker and DevOps, one of the best ways to understand containers is to build something real.</p><p>For me, that project was <strong>running WordPress using Docker with Ubuntu, Nginx, PHP-FPM, FastCGI, and MySQL</strong>.</p><p>At first, everything looked confusing:</p><ul><li>Why does Nginx use port 80?</li><li>Why does PHP-FPM use port 9000?</li><li>Why do we need FastCGI?</li><li>Why doesn’t localhost:8080 work from Windows?</li><li>Why does 192.168.1.157:8080 work?</li><li>Where should the Dockerfile be placed?</li></ul><p>This article explains the complete setup and the lessons learned along the way.</p><h3>1. The Architecture</h3><p>The final architecture looks like this:</p><pre>Windows Browser<br>                          |<br>                          | HTTP<br>                          ↓<br>                 Ubuntu Virtual Machine<br>                    192.168.1.157<br>                          |<br>                    Docker Network<br>                          |<br>                    Nginx Container<br>                       Port 80<br>                          |<br>                       FastCGI<br>                          ↓<br>               WordPress Container<br>                  PHP-FPM :9000<br>                          |<br>                          | MySQL<br>                          ↓<br>                  MySQL Container<br>                     Port 3306</pre><p>There are three main containers:</p><pre>Nginx<br>WordPress + PHP-FPM<br>MySQL</pre><p>Each container has a specific job.</p><h3>2. Why Separate Containers?</h3><p>One of the important Docker concepts I learned is:</p><blockquote><strong><em>One container should generally focus on one main responsibility.</em></strong></blockquote><p>So instead of putting everything into one container:</p><pre>Nginx + PHP + MySQL + WordPress</pre><p>we separate them:</p><pre>Nginx<br>   ↓<br>PHP-FPM<br>   ↓<br>MySQL</pre><p>This makes the system easier to manage, troubleshoot, scale, and update.</p><h3>3. Where Should the Dockerfile Go?</h3><p>Suppose the WordPress files are located here:</p><pre>/var/www/wordpress/</pre><p>Inside that directory we have:</p><pre>wordpress/<br>├── Dockerfile<br>├── docker-compose.yml<br>├── wp-config.php<br>├── index.php<br>├── wp-admin/<br>├── wp-content/<br>└── wp-includes/</pre><p>The Dockerfile can be placed directly inside the WordPress directory.</p><p>Then:</p><pre>cd /var/www/wordpress</pre><p>and build using:</p><pre>docker build -t mywordpress .</pre><p>The . means:</p><blockquote><em>Use the current directory as the Docker build context.</em></blockquote><h3>4. Creating the WordPress PHP-FPM Container</h3><p>Instead of using the official WordPress image, I wanted to understand what is actually happening underneath.</p><p>So I started with Ubuntu:</p><pre>FROM ubuntu:24.04</pre><pre>ENV DEBIAN_FRONTEND=noninteractive</pre><pre>RUN apt-get update &amp;&amp; apt-get install -y \<br>    software-properties-common \<br>    curl \<br>    unzip \<br>    &amp;&amp; add-apt-repository ppa:ondrej/php \<br>    &amp;&amp; apt-get update &amp;&amp; apt-get install -y \<br>    php8.3 \<br>    php8.3-fpm \<br>    php8.3-mysql \<br>    php8.3-xml \<br>    php8.3-gd \<br>    php8.3-zip \<br>    php8.3-soap \<br>    &amp;&amp; rm -rf /var/lib/apt/lists/*</pre><pre>WORKDIR /var/www/wordpress</pre><pre>COPY . /var/www/wordpress</pre><pre>RUN sed -i &#39;s|^listen = .*|listen = 0.0.0.0:9000|&#39; \<br>    /etc/php/8.3/fpm/pool.d/www.conf</pre><pre>RUN chown -R www-data:www-data /var/www/wordpress</pre><pre>EXPOSE 9000</pre><pre>CMD [&quot;php-fpm8.3&quot;, &quot;-F&quot;]</pre><h3>5. Understanding php-fpm</h3><p>This was one of the most important concepts.</p><p>PHP-FPM stands for:</p><blockquote><strong><em>PHP FastCGI Process Manager</em></strong></blockquote><p>PHP-FPM is not a normal web server.</p><p>It processes PHP scripts and communicates with a web server such as Nginx using <strong>FastCGI</strong>.</p><p>The flow is:</p><pre>Browser<br>   ↓ HTTP<br>Nginx<br>   ↓ FastCGI<br>PHP-FPM<br>   ↓<br>index.php</pre><h3>6. Why Port 9000?</h3><p>The PHP-FPM configuration originally used a Unix socket in some setups:</p><pre>/run/php/php8.3-fpm.sock</pre><p>For a multi-container Docker setup, I changed it to TCP port 9000:</p><pre>listen = 0.0.0.0:9000</pre><p>The Dockerfile uses:</p><pre>RUN sed -i &#39;s|^listen = .*|listen = 0.0.0.0:9000|&#39; \<br>    /etc/php/8.3/fpm/pool.d/www.conf</pre><p>This command means:</p><blockquote><em>Find the </em><em>listen = ... line in the PHP-FPM configuration and replace it with </em><em>listen = 0.0.0.0:9000.</em></blockquote><p>Now PHP-FPM listens on:</p><pre>0.0.0.0:9000</pre><p>This allows Nginx in another container to communicate with it.</p><h3>7. Why Nginx Uses Port 80</h3><p>Nginx is the web server.</p><p>HTTP normally uses port 80.</p><p>Our Nginx configuration contains:</p><pre>server {<br>    listen 80;</pre><pre>    root /var/www/wordpress;<br>    index index.php index.html;</pre><pre>    location / {<br>        try_files $uri $uri/ /index.php?$args;<br>    }</pre><pre>    location ~ \.php$ {<br>        include fastcgi_params;</pre><pre>        fastcgi_pass wordpress:9000;</pre><pre>        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;<br>    }<br>}</pre><p>The important line is:</p><pre>fastcgi_pass wordpress:9000;</pre><p>It means:</p><blockquote><em>Send PHP requests to the </em><em>wordpress container on port </em><em>9000.</em></blockquote><h3>8. What Is FastCGI?</h3><p>FastCGI is the communication method between Nginx and PHP-FPM.</p><p>Think of it like this:</p><pre>Nginx:<br>&quot;I received a request for index.php.&quot;</pre><pre>        ↓ FastCGI</pre><pre>PHP-FPM:<br>&quot;I will execute index.php.&quot;</pre><pre>        ↓</pre><pre>WordPress generates the response.</pre><pre>        ↓</pre><pre>PHP-FPM → Nginx → Browser</pre><p>A simple memory trick:</p><pre>80   = Web / HTTP<br>9000 = PHP-FPM / FastCGI<br>3306 = MySQL</pre><h3>9. Docker Compose</h3><p>To connect everything together, I used Docker Compose:</p><pre>services:</pre><pre>  nginx:<br>    image: nginx:alpine<br>    container_name: nginx<br>    ports:<br>      - &quot;8080:80&quot;<br>    volumes:<br>      - .:/var/www/wordpress<br>      - ./web:/etc/nginx/conf.d/default.conf<br>    networks:<br>      - wordpress-net<br>    depends_on:<br>      - wordpress</pre><pre>  wordpress:<br>    build: .<br>    container_name: wordpress<br>    volumes:<br>      - .:/var/www/wordpress<br>    depends_on:<br>      - db<br>    networks:<br>      - wordpress-net</pre><pre>  db:<br>    image: mysql:8.0<br>    container_name: mysql<br>    ports:<br>      - &quot;33060:3306&quot;<br>    environment:<br>      MYSQL_ROOT_PASSWORD: root123<br>      MYSQL_DATABASE: wordpress<br>      MYSQL_USER: wpuser<br>      MYSQL_PASSWORD: password123<br>    networks:<br>      - wordpress-net</pre><pre>networks:<br>  wordpress-net:</pre><h3>10. Understanding 8080:80</h3><p>This syntax confused me initially:</p><pre>ports:<br>  - &quot;8080:80&quot;</pre><p>It means:</p><pre>HOST PORT : CONTAINER PORT</pre><p>Therefore:</p><pre>8080 : 80</pre><p>means:</p><blockquote><em>Port 8080 on the host forwards to port 80 inside the Nginx container.</em></blockquote><p>So:</p><pre>Browser<br>   ↓<br>localhost:8080<br>   ↓<br>Nginx container :80</pre><h3>11. Why PHP-FPM Port 9000 Isn’t Published?</h3><p>You might notice:</p><pre>wordpress<br>9000/tcp</pre><p>instead of:</p><pre>0.0.0.0:9000-&gt;9000/tcp</pre><p>That’s intentional.</p><p>The browser doesn’t need to access PHP-FPM directly.</p><p>Only Nginx needs it:</p><pre>Nginx<br>   ↓<br>wordpress:9000</pre><p>Both containers are connected to:</p><pre>wordpress-net</pre><p>Therefore Nginx can communicate with the WordPress container using:</p><pre>wordpress:9000</pre><p>There is no need to expose port 9000 to Windows.</p><h3>12. WordPress and MySQL</h3><p>Inside wp-config.php, the database configuration is:</p><pre>define( &#39;DB_NAME&#39;, &#39;wordpress&#39; );<br>define( &#39;DB_USER&#39;, &#39;wpuser&#39; );<br>define( &#39;DB_PASSWORD&#39;, &#39;password123&#39; );<br>define( &#39;DB_HOST&#39;, &#39;db&#39; );</pre><p>The important part is:</p><pre>define( &#39;DB_HOST&#39;, &#39;db&#39; );</pre><p>Why db?</p><p>Because db is the Docker Compose service name.</p><p>Docker provides internal DNS, so the WordPress container can find the MySQL container using:</p><pre>db</pre><p>Therefore:</p><pre>WordPress → db:3306</pre><p>Not:</p><pre>WordPress → localhost:3306</pre><p>Inside the WordPress container, localhost means the WordPress container itself.</p><h3>13. Understanding docker ps</h3><p>Running:</p><pre>docker ps</pre><p>gave me something similar to:</p><pre>CONTAINER ID   IMAGE                 COMMAND            STATUS    PORTS<br>8332...        nginx:alpine          ...                Up        0.0.0.0:8080-&gt;80/tcp<br>b6b9...        wordpress-wordpress   php-fpm8.3 -F      Up        9000/tcp<br>51e1...        mysql:8.0             ...                Up        33060-&gt;3306/tcp</pre><p>The important part is:</p><pre>Nginx:<br>8080 → 80</pre><pre>WordPress:<br>9000/tcp</pre><pre>MySQL:<br>33060 → 3306</pre><p>So:</p><pre>Windows :8080<br>       ↓<br>Nginx :80</pre><pre>Nginx → WordPress :9000</pre><pre>WordPress → MySQL :3306</pre><h3>14. The localhost Problem</h3><p>This was one of the most useful lessons.</p><p>Initially, I tried:</p><pre>http://localhost:8080</pre><p>from my Windows browser.</p><p>It didn’t work.</p><p>Why?</p><p>Because Docker was running <strong>inside an Ubuntu VirtualBox VM</strong>.</p><p>So:</p><pre>Windows localhost</pre><p>and:</p><pre>Ubuntu localhost</pre><p>are two different things.</p><p>When I ran this inside Ubuntu:</p><pre>curl -I http://localhost:8080</pre><p>I got:</p><pre>HTTP/1.1 302 Found<br>X-Redirect-By: WordPress<br>Location: http://localhost:8080/wp-admin/install.php</pre><p>That proved WordPress was working.</p><p>But Windows localhost was pointing to Windows itself.</p><h3>15. Finding the Correct IP</h3><p>I checked:</p><pre>ip addr</pre><p>and found:</p><pre>enp0s3:<br>    inet 192.168.1.157/24</pre><p>I had previously been trying:</p><pre>192.168.56.101</pre><p>but that address was not currently assigned to the Ubuntu VM.</p><p>This was an important troubleshooting lesson:</p><blockquote><strong><em>Always check the VM’s current IP instead of assuming an old IP is still valid.</em></strong></blockquote><h3>16. Accessing WordPress from Windows</h3><p>Because Ubuntu’s current IP was:</p><pre>192.168.1.157</pre><p>the correct browser URL became:</p><pre>http://192.168.1.157:8080</pre><p>The complete request path is:</p><pre>Windows Browser<br>       ↓<br>192.168.1.157:8080<br>       ↓<br>Ubuntu VM<br>       ↓<br>Docker Nginx :80<br>       ↓<br>FastCGI<br>       ↓<br>PHP-FPM :9000<br>       ↓<br>WordPress<br>       ↓<br>MySQL :3306</pre><h3>17. A Simple Troubleshooting Checklist</h3><p>When WordPress doesn’t open, don’t immediately change everything.</p><p>Check one layer at a time.</p><h3>Check containers</h3><pre>docker ps</pre><p>All required containers should show:</p><pre>Up</pre><h3>Check Nginx</h3><pre>docker exec nginx nginx -t</pre><p>Expected:</p><pre>syntax is ok<br>test is successful</pre><h3>Check PHP-FPM</h3><pre>docker exec wordpress ps aux | grep php-fpm</pre><h3>Check PHP-FPM port</h3><pre>docker exec wordpress \<br>grep &quot;^listen&quot; /etc/php/8.3/fpm/pool.d/www.conf</pre><p>Expected:</p><pre>listen = 0.0.0.0:9000</pre><h3>Check Docker port</h3><pre>docker port nginx</pre><p>Expected:</p><pre>80/tcp -&gt; 0.0.0.0:8080</pre><h3>Test from Ubuntu</h3><pre>curl -I http://localhost:8080</pre><p>If you see:</p><pre>302 Found<br>X-Redirect-By: WordPress</pre><p>WordPress is responding.</p><h3>Check VM IP</h3><pre>ip addr</pre><p>Then use that IP from Windows:</p><pre>http://YOUR_VM_IP:8080</pre><h3>18. The Biggest Lessons I Learned</h3><p>This project taught me that Docker is not just about writing a Dockerfile.</p><p>I had to understand how different components communicate.</p><p>The key concepts are:</p><h3>Docker</h3><p>Containers isolate applications and allow them to communicate through Docker networks.</p><h3>Nginx</h3><p>Nginx handles HTTP requests.</p><pre>:80</pre><h3>PHP-FPM</h3><p>PHP-FPM executes PHP applications.</p><pre>:9000</pre><h3>FastCGI</h3><p>FastCGI is the communication protocol between Nginx and PHP-FPM.</p><pre>Nginx → FastCGI → PHP-FPM</pre><h3>MySQL</h3><p>MySQL stores WordPress data.</p><pre>:3306</pre><h3>Docker DNS</h3><p>Compose service names can be used as hostnames:</p><pre>wordpress:9000<br>db:3306</pre><h3>VirtualBox Networking</h3><p>The VM has its own IP address.</p><p>Therefore:</p><pre>Windows localhost</pre><p>is not automatically the same as:</p><pre>Ubuntu VM localhost</pre><h3>Final Architecture</h3><p>The entire setup can be remembered with one diagram:</p><pre>INTERNET / BROWSER<br>                           |<br>                           | HTTP<br>                           ↓<br>                Ubuntu VM: 192.168.1.157<br>                           |<br>                           | :8080<br>                           ↓<br>                 ┌──────────────────┐<br>                 │  Nginx Container │<br>                 │      :80         │<br>                 └────────┬─────────┘<br>                          |<br>                       FastCGI<br>                          |<br>                          ↓<br>                 ┌──────────────────┐<br>                 │ WordPress/PHP    │<br>                 │   PHP-FPM :9000  │<br>                 └────────┬─────────┘<br>                          |<br>                       MySQL<br>                          |<br>                          ↓<br>                 ┌──────────────────┐<br>                 │  MySQL Container │<br>                 │      :3306       │<br>                 └──────────────────┘</pre><p>The most useful mnemonic is:</p><pre>80   → Web<br>9000 → PHP<br>3306 → Database</pre><p>And for Docker networking:</p><pre>localhost = myself<br>service-name = another container</pre><p>Once these concepts become clear, Dockerizing WordPress becomes much easier to understand.</p><p>The goal isn’t just to make WordPress run.</p><p>The real goal is to understand <strong>why it runs</strong>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7fa412a57a45" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Linux Error Handling and Redirection: Understanding stderr, stdout, and /dev/null]]></title>
            <link>https://medium.com/@omprakashlamichhane10/linux-error-handling-and-redirection-understanding-stderr-stdout-and-dev-null-6dce5f410f44?source=rss-92d3b6df1568------2</link>
            <guid isPermaLink="false">https://medium.com/p/6dce5f410f44</guid>
            <dc:creator><![CDATA[Omprakashlamichhane]]></dc:creator>
            <pubDate>Thu, 24 Sep 2026 06:33:53 GMT</pubDate>
            <atom:updated>2026-09-24T06:33:53.282Z</atom:updated>
            <content:encoded><![CDATA[<p>When working with Linux from the terminal, commands do not always execute successfully. Sometimes a command produces useful output, while other times it produces an error message.</p><p>During my Linux and DevOps practice, I came across an important concept called <strong>redirection</strong>. One command that especially caught my attention was:</p><pre>2&gt;/dev/null</pre><p>At first, this command looks confusing. But once we understand Linux’s standard input/output streams, it becomes very simple.</p><h3>What Is Redirection in Linux?</h3><p><strong>Redirection</strong> means changing where the input or output of a command goes.</p><p>Normally, when we run a command:</p><pre>ls</pre><p>the output appears directly on the terminal.</p><p>Linux provides three standard streams:</p><p>NumberNameMeaning0stdinStandard input1stdoutStandard output2stderrStandard error</p><p>The most important ones for redirection are:</p><pre>1 → stdout → normal output<br>2 → stderr → error output</pre><h3>1. Understanding stdout</h3><p>stdout means <strong>standard output</strong>.</p><p>For example:</p><pre>ls</pre><p>If the directory contains:</p><pre>file.txt<br>script.sh<br>backup.tar.gz</pre><p>Linux sends this normal output to stdout.</p><p>We can explicitly redirect it to a file:</p><pre>ls &gt; output.txt</pre><p>Now the output does not appear on the terminal.</p><p>Instead, it is saved in:</p><pre>output.txt</pre><p>We can read it using:</p><pre>cat output.txt</pre><h3>Remember</h3><pre>1 = normal output</pre><p>So:</p><pre>ls 1&gt;output.txt</pre><p>and:</p><pre>ls &gt; output.txt</pre><p>are effectively the same for ordinary stdout redirection.</p><h3>2. Understanding stderr</h3><p>stderr means <strong>standard error</strong>.</p><p>Let’s intentionally run a command with an invalid path:</p><pre>ls /abc</pre><p>If /abc does not exist, Linux displays something similar to:</p><pre>ls: cannot access &#39;/abc&#39;: No such file or directory</pre><p>This is not normal output.</p><p>It is an <strong>error message</strong>, so Linux sends it through:</p><pre>stderr</pre><p>And the number for stderr is:</p><pre>2</pre><p>Therefore:</p><pre>2 = stderr</pre><h3>3. Redirecting Errors to a File</h3><p>Instead of displaying the error on the terminal, we can save it into a file.</p><pre>ls /abc 2&gt;error.log</pre><p>Let’s break this down:</p><pre>ls /abc<br>   ↓<br>Run ls on /abc</pre><pre>2<br>↓<br>stderr</pre><pre>&gt;<br>↓<br>redirect</pre><pre>error.log<br>↓<br>destination file</pre><p>The error will be stored in:</p><pre>error.log</pre><p>We can check it with:</p><pre>cat error.log</pre><p>This is very useful when troubleshooting scripts and applications because we can keep the error messages for later investigation.</p><h3>4. What Does /dev/null Mean?</h3><p>Now we reach the important command:</p><pre>2&gt;/dev/null</pre><p>Linux provides a special device called:</p><pre>/dev/null</pre><p>You can think of /dev/null as a <strong>black hole</strong>.</p><p>Anything sent there is discarded.</p><p>For example:</p><pre>echo &quot;Hello&quot; &gt; /dev/null</pre><p>The word Hello will not appear on the terminal.</p><p>It is simply discarded.</p><h3>5. Understanding 2&gt;/dev/null</h3><p>Now let’s combine everything:</p><pre>ls /abc 2&gt;/dev/null</pre><p>Break it into three parts:</p><pre>2<br>↓<br>stderr</pre><pre>&gt;<br>↓<br>redirect</pre><pre>/dev/null<br>↓<br>discard the output</pre><p>Therefore:</p><pre>2&gt;/dev/null</pre><p>means:</p><blockquote><strong><em>Redirect error messages (</em></strong><strong><em>stderr) to </em></strong><strong><em>/dev/null, so they are discarded.</em></strong></blockquote><p>If /abc does not exist:</p><pre>ls /abc</pre><p>may show:</p><pre>ls: cannot access &#39;/abc&#39;: No such file or directory</pre><p>But:</p><pre>ls /abc 2&gt;/dev/null</pre><p>will hide that error.</p><h3>Important</h3><p>2&gt;/dev/null does <strong>not fix the error</strong>.</p><p>It only prevents the error message from being displayed.</p><h3>6. A Practical Example with find</h3><p>One of the most useful examples is:</p><pre>find / -name &quot;*.log&quot;</pre><p>When searching from /, Linux may encounter directories that the current user cannot access.</p><p>You may therefore see many messages such as:</p><pre>find: &#39;/some/directory&#39;: Permission denied</pre><p>If you only want to see the matching files and don’t want permission errors filling your terminal, you can use:</p><pre>find / -name &quot;*.log&quot; 2&gt;/dev/null</pre><p>Here:</p><pre>find / -name &quot;*.log&quot;<br>        ↓<br>search for .log files</pre><pre>2&gt;/dev/null<br>        ↓<br>hide permission/error messages</pre><p>This is a very common Linux technique.</p><h3>7. &gt; vs 2&gt;</h3><p>This difference is extremely important.</p><h3>Normal output</h3><pre>command &gt; output.txt</pre><p>This redirects:</p><pre>stdout → output.txt</pre><h3>Error output</h3><pre>command 2&gt; error.txt</pre><p>This redirects:</p><pre>stderr → error.txt</pre><p>So remember:</p><pre>&gt;   → normal output<br>2&gt;  → error output</pre><h3>8. Redirecting Both Output and Errors</h3><p>Sometimes we want to save <strong>both normal output and error messages</strong>.</p><p>For example:</p><pre>command &gt; output.txt 2&gt;&amp;1</pre><p>This means:</p><pre>stdout → output.txt<br>stderr → stdout</pre><p>Since stdout is already going to output.txt, the error output also ends up in the same file.</p><p>A shorter Bash form is:</p><pre>command &amp;&gt; output.txt</pre><p>For example:</p><pre>ls /home /abc &gt; result.txt 2&gt;&amp;1</pre><p>Both successful output and errors are stored in:</p><pre>result.txt</pre><h3>9. Redirecting Only Errors</h3><p>Suppose we want normal output on the screen but errors saved into a file.</p><p>We can use:</p><pre>command 2&gt;error.log</pre><p>For example:</p><pre>ls /home /abc 2&gt;error.log</pre><p>The existing /home contents are displayed normally.</p><p>The error related to /abc goes into:</p><pre>error.log</pre><p>This is useful for debugging.</p><h3>10. Append Errors Instead of Overwriting</h3><p>The following command:</p><pre>command 2&gt;error.log</pre><p>creates or replaces the file.</p><p>If we want to <strong>append</strong> new errors to the existing file, use:</p><pre>command 2&gt;&gt;error.log</pre><p>Difference:</p><pre>2&gt;   → overwrite<br>2&gt;&gt;  → append</pre><p>For example:</p><pre>ls /abc 2&gt;&gt;error.log</pre><p>The new error is added to the end of error.log.</p><h3>11. Why Is Error Redirection Useful?</h3><p>Error redirection is especially useful when working with:</p><ul><li>Bash scripts</li><li>Cron jobs</li><li>Server administration</li><li>Nginx</li><li>MySQL</li><li>PHP</li><li>Docker</li><li>Deployment scripts</li><li>Backup scripts</li><li>Log management</li><li>DevOps automation</li></ul><p>For example, suppose a script runs every few minutes through cron.</p><p>You may not want every harmless error message to appear in your output.</p><p>You could use:</p><pre>some-command 2&gt;/dev/null</pre><p>However, be careful.</p><p>If you hide every error, you may also hide an important problem.</p><h3>12. Hiding Errors vs Recording Errors</h3><p>There are two different approaches.</p><h3>Hide the error</h3><pre>command 2&gt;/dev/null</pre><p>Useful when the error is expected or irrelevant.</p><h3>Save the error</h3><pre>command 2&gt;error.log</pre><p>Useful when you want to investigate what went wrong.</p><p>For production systems and troubleshooting, <strong>recording errors is often more useful than simply hiding them</strong>.</p><h3>13. Easy Way to Remember Linux Redirection</h3><p>Use this simple memory trick:</p><pre>0 → INPUT<br>1 → OUTPUT<br>2 → ERROR</pre><p>Think:</p><pre>Linux Command<br>             |<br>       ┌─────┴─────┐<br>       ↓           ↓<br>    stdout       stderr<br>      1             2<br>      ↓             ↓<br> normal output   error output</pre><p>And:</p><pre>/dev/null<br>     ↓<br>   BLACK HOLE<br>     ↓<br>   discard</pre><p>Therefore:</p><pre>2&gt;/dev/null</pre><p>becomes:</p><pre>2       → error<br>&gt;       → redirect<br>/dev/null → throw it away</pre><h3>Useful Redirection Cheat Sheet</h3><p>CommandMeaningcommand &gt; fileSave normal outputcommand 1&gt; fileSave stdoutcommand 2&gt; fileSave errorscommand 2&gt;&gt; fileAppend errorscommand &gt; file 2&gt;&amp;1Save stdout + stderrcommand &amp;&gt; fileSave stdout + stderrcommand 2&gt;/dev/nullHide errorscommand &gt; /dev/nullDiscard normal outputcommand &amp;&gt;/dev/nullDiscard normal output and errors</p><h3>Final Thoughts</h3><p>Learning Linux is not only about memorizing commands. It is also about understanding <strong>where the command’s input and output are going</strong>.</p><p>The command:</p><pre>2&gt;/dev/null</pre><p>is a small but powerful example.</p><p>Once we understand:</p><pre>0 = stdin<br>1 = stdout<br>2 = stderr</pre><p>and:</p><pre>/dev/null = discard output</pre><p>the command becomes easy to understand.</p><p>So whenever you see:</p><pre>2&gt;/dev/null</pre><p>remember:</p><blockquote><strong><em>“Send the error somewhere that throws it away.”</em></strong></blockquote><p>This concept becomes especially important as you move from basic Linux commands toward <strong>Bash scripting, cron jobs, server administration, and DevOps automation</strong>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6dce5f410f44" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Configure a Secure SFTP Chroot User on Ubuntu]]></title>
            <link>https://medium.com/@omprakashlamichhane10/how-to-configure-a-secure-sftp-chroot-user-on-ubuntu-64356c3d7e48?source=rss-92d3b6df1568------2</link>
            <guid isPermaLink="false">https://medium.com/p/64356c3d7e48</guid>
            <dc:creator><![CDATA[Omprakashlamichhane]]></dc:creator>
            <pubDate>Wed, 23 Sep 2026 08:00:37 GMT</pubDate>
            <atom:updated>2026-09-23T08:00:37.545Z</atom:updated>
            <content:encoded><![CDATA[<p>When managing Linux servers, sometimes we want a user to upload and download files through <strong>SFTP</strong> without giving that user access to a normal SSH terminal.</p><p>One common solution is <strong>SFTP chroot</strong>.</p><p>In this tutorial, we will create an SFTP user called dogman, place the user in an sftp group, configure SSH to force SFTP access, and use a <strong>bind mount</strong> to expose an existing directory inside the user&#39;s chroot environment.</p><h3>1. Create an SFTP Group</h3><p>First, create a group called sftp:</p><pre>addgroup sftp</pre><p>The purpose of this group is to identify users who should receive the SFTP restrictions.</p><h3>2. Create the dogman User</h3><p>Create the user with a home directory:</p><pre>useradd -m dogman -g www-data</pre><p>This creates:</p><pre>User: dogman<br>Home: /home/dogman<br>Primary group: www-data</pre><p>Because our SSH configuration will use:</p><pre>Match Group sftp</pre><p>we also need to add dogman to the sftp group:</p><pre>usermod -aG sftp dogman</pre><p>We can verify the groups with:</p><pre>groups dogman</pre><h3>3. Set a Password</h3><p>Set the password for dogman:</p><pre>passwd dogman</pre><p>Linux will ask you to enter the password twice.</p><h3>4. Set the User’s Shell</h3><p>Edit the passwd file:</p><pre>vim /etc/passwd</pre><p>Find the dogman entry.</p><p>The last field defines the user’s login shell.</p><p>For example:</p><pre>dogman:x:1001:33::/home/dogman:/bin/bash</pre><p>Here:</p><pre>/home/dogman</pre><p>is the home directory and:</p><pre>/bin/bash</pre><p>is the login shell.</p><h3>5. Set Permissions on the Home Directory</h3><p>Set the permissions:</p><pre>chmod 755 /home/dogman/</pre><p>The directory should also be owned by root because it will be used as the SFTP chroot directory:</p><pre>chown root:root /home/dogman</pre><p>This is an important requirement for SSH chroot.</p><h3>Why root:root?</h3><p>Our SSH configuration will contain:</p><pre>ChrootDirectory /home/%u</pre><p>For the user dogman, %u becomes:</p><pre>/home/dogman</pre><p>Therefore, /home/dogman becomes the chroot directory.</p><p>The chroot directory itself should not be writable by the SFTP user.</p><h3>6. Be Careful With Recursive Ownership</h3><p>A common command is:</p><pre>chown -R dogman:www-data /home/dogman/</pre><p>However, this should <strong>not</strong> be run on the entire chroot directory after:</p><pre>chown root:root /home/dogman</pre><p>Why?</p><p>Because the recursive command would change:</p><pre>/home/dogman</pre><p>from:</p><pre>root:root</pre><p>back to:</p><pre>dogman:www-data</pre><p>That can cause the SSH chroot configuration to fail.</p><p>Instead, writable subdirectories inside the chroot can be owned by dogman.</p><p>For example:</p><pre>chown -R dogman:www-data /home/dogman/some-directory</pre><h3>7. Understanding the Bind Mount</h3><p>Suppose the server already has this directory:</p><pre>/mnt/dogman-uat-nfs/api/asset_migration_source</pre><p>and we want dogman to access it through:</p><pre>/home/dogman/asset_migration_source</pre><p>We can use a bind mount:</p><pre>mount --bind /mnt/dogman-uat-nfs/api/asset_migration_source /home/dogman/asset_migration_source</pre><p>A bind mount does <strong>not copy the files</strong>.</p><p>Instead, it provides another path to the same directory.</p><p>Conceptually:</p><pre>/mnt/dogman-uat-nfs/api/asset_migration_source<br>                    │<br>                    │ mount --bind<br>                    ▼<br>       /home/dogman/asset_migration_source</pre><p>If files already exist in the /mnt directory, they can be accessed through the new path.</p><h3>8. Configure SSH for SFTP</h3><p>Now edit the SSH configuration:</p><pre>vim /etc/ssh/sshd_config</pre><p>Add the SFTP configuration:</p><pre>ChallengeResponseAuthentication yes</pre><pre>Match Group sftp<br>    ForceCommand internal-sftp<br>    PasswordAuthentication yes<br>    ChrootDirectory /home/%u<br>    PermitTTY no<br>    PermitTunnel no<br>    AllowAgentForwarding no<br>    AllowTcpForwarding no<br>    X11Forwarding no</pre><p>Let’s understand the important directives.</p><h3>Match Group sftp</h3><pre>Match Group sftp</pre><p>This applies the following settings to users belonging to the sftp group.</p><p>Since we added:</p><pre>usermod -aG sftp dogman</pre><p>these settings apply to dogman.</p><h3>ForceCommand internal-sftp</h3><pre>ForceCommand internal-sftp</pre><p>This forces the user to use SFTP rather than opening a normal SSH shell.</p><h3>PasswordAuthentication yes</h3><pre>PasswordAuthentication yes</pre><p>Allows password-based authentication for the matched users.</p><h3>ChrootDirectory</h3><pre>ChrootDirectory /home/%u</pre><p>The %u represents the username.</p><p>For dogman:</p><pre>%u = dogman</pre><p>Therefore:</p><pre>/home/%u</pre><p>becomes:</p><pre>/home/dogman</pre><p>The user is therefore restricted to the chroot environment.</p><h3>Disable unnecessary SSH features</h3><pre>PermitTTY no<br>PermitTunnel no<br>AllowAgentForwarding no<br>AllowTcpForwarding no<br>X11Forwarding no</pre><p>These settings prevent the SFTP user from using several normal SSH features.</p><h3>9. Test the SSH Configuration</h3><p>Before restarting SSH, always check the configuration:</p><pre>sshd -t</pre><p>If there is no output, the configuration syntax is valid.</p><p>This is an important step because a configuration error can prevent SSH from restarting correctly.</p><h3>10. Restart the SSH Service</h3><p>After successfully testing the configuration:</p><pre>systemctl restart ssh.service</pre><p>Keep your existing SSH/root session open while testing the new SFTP connection.</p><p>This is a good safety practice because if the SSH configuration has a problem, you still have your existing session available.</p><h3>11. Connect Using SFTP</h3><p>From another terminal or computer:</p><pre>sftp dogman@SERVER_IP</pre><p>For example:</p><pre>sftp dogman@192.168.1.174</pre><p>Enter the password for dogman.</p><p>The user should receive an SFTP session rather than a normal SSH shell.</p><h3>Understanding the Complete Architecture</h3><p>The final setup looks like this:</p><pre>Ubuntu Server<br>                         │<br>                         ▼<br>                    SSH Service<br>                         │<br>                         ▼<br>                  Match Group sftp<br>                         │<br>                         ▼<br>                     dogman<br>                         │<br>                         ▼<br>              ForceCommand internal-sftp<br>                         │<br>                         ▼<br>              ChrootDirectory /home/%u<br>                         │<br>                         ▼<br>                  /home/dogman<br>                         │<br>                         ▼<br>             asset_migration_source<br>                         │<br>                         │ bind mount<br>                         ▼<br> /mnt/dogman-uat-nfs/api/asset_migration_source</pre><p>The key idea is that the user gets <strong>SFTP access inside a restricted environment</strong>, while the bind mount makes an existing directory available from within that environment.</p><h3>Complete Command Flow</h3><p>For reference, the main commands are:</p><pre>addgroup sftp</pre><pre>useradd -m dogman -g www-data</pre><pre>usermod -aG sftp dogman</pre><pre>passwd dogman</pre><pre>vim /etc/passwd</pre><pre>chmod 755 /home/dogman/</pre><pre>chown root:root /home/dogman</pre><pre>mount --bind /mnt/dogman-uat-nfs/api/asset_migration_source /home/dogman/asset_migration_source</pre><pre>vim /etc/ssh/sshd_config</pre><pre>sshd -t</pre><pre>systemctl restart ssh.service</pre><p>Then test:</p><pre>sftp dogman@SERVER_IP</pre><h3>Final Takeaway</h3><p>The setup combines three important Linux concepts:</p><p><strong>1. Linux groups</strong></p><pre>sftp</pre><p>identifies users who should receive SFTP restrictions.</p><p><strong>2. SSH chroot</strong></p><pre>ChrootDirectory /home/%u</pre><p>restricts the user’s filesystem view.</p><p><strong>3. Bind mount</strong></p><pre>mount --bind SOURCE DESTINATION</pre><p>makes an existing directory available at another path without copying its contents.</p><p>Together, these allow an administrator to provide a controlled SFTP environment while still exposing specific server data to the SFTP user.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=64356c3d7e48" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[MariaDB Database, Users, GRANT and Privileges on Ubuntu ]]></title>
            <link>https://medium.com/@omprakashlamichhane10/mariadb-database-users-grant-and-privileges-on-ubuntu-2d3c39014d77?source=rss-92d3b6df1568------2</link>
            <guid isPermaLink="false">https://medium.com/p/2d3c39014d77</guid>
            <dc:creator><![CDATA[Omprakashlamichhane]]></dc:creator>
            <pubDate>Wed, 16 Sep 2026 06:52:01 GMT</pubDate>
            <atom:updated>2026-09-16T06:52:01.081Z</atom:updated>
            <content:encoded><![CDATA[<p>While learning Linux and DevOps, understanding how to create databases, users, and permissions in MariaDB is essential.</p><p>In this practical session, I created a database named birendra, created a user named sakil, and learned how to grant permissions to that user.</p><h3>1. Connect to MariaDB</h3><p>First, connect to MariaDB:</p><pre>mysql</pre><p>After successfully connecting, you will see:</p><pre>MariaDB [(none)]&gt;</pre><h3>2. Create a Database</h3><p>I created a database named birendra:</p><pre>CREATE DATABASE birendra;</pre><p>MariaDB returned:</p><pre>Query OK, 1 row affected</pre><p>To verify it:</p><pre>SHOW DATABASES;</pre><p>The database appeared in the list:</p><pre>+--------------------+<br>| Database           |<br>+--------------------+<br>| birendra           |<br>| information_schema |<br>| mysql              |<br>| performance_schema |<br>| prakash            |<br>| sys                |<br>| wordpress          |<br>+--------------------+</pre><h3>3. Create a Database User</h3><p>Next, I created a user named sakil:</p><pre>CREATE USER &#39;sakil&#39;@&#39;localhost&#39; IDENTIFIED BY &#39;root&#39;;</pre><p>The command successfully created the user.</p><p>Here:</p><pre>sakil       → username<br>localhost   → allowed host<br>root        → password</pre><p>So:</p><pre>&#39;sakil&#39;@&#39;localhost&#39;</pre><p>means the sakil account can authenticate from the local server.</p><h3>4. Grant Privileges to the User</h3><p>Creating a user does <strong>not</strong> automatically give that user access to a database.</p><p>For example, we have:</p><pre>Database → birendra<br>User     → sakil</pre><p>We need to connect them using the GRANT command.</p><p>Use:</p><pre>GRANT ALL PRIVILEGES ON birendra.* TO &#39;sakil&#39;@&#39;localhost&#39;;</pre><p>This gives sakil all privileges on the birendra database.</p><h3>Understanding the command</h3><pre>GRANT ALL PRIVILEGES</pre><p>means we are granting all available privileges.</p><pre>ON birendra.*</pre><p>means all tables inside the birendra database.</p><pre>TO &#39;sakil&#39;@&#39;localhost&#39;</pre><p>specifies the user receiving those privileges.</p><p>So the complete meaning is:</p><blockquote><em>Give the </em><em>sakil user all privileges on all tables inside the </em><em>birendra database.</em></blockquote><h3>5. Check the User’s Privileges</h3><p>After granting permissions, we can check them using:</p><pre>SHOW GRANTS FOR &#39;sakil&#39;@&#39;localhost&#39;;</pre><p>We should see a result similar to:</p><pre>GRANT USAGE ON *.* TO `sakil`@`localhost`<br>GRANT ALL PRIVILEGES ON `birendra`.* TO `sakil`@`localhost`</pre><p>This confirms that the user has permissions on the database.</p><h3>6. Different Types of Privileges</h3><p>Instead of giving all privileges, we can give only specific permissions.</p><p>For example:</p><h3>SELECT</h3><p>Allows the user to read data:</p><pre>GRANT SELECT ON birendra.* TO &#39;sakil&#39;@&#39;localhost&#39;;</pre><h3>INSERT</h3><p>Allows the user to add data:</p><pre>GRANT INSERT ON birendra.* TO &#39;sakil&#39;@&#39;localhost&#39;;</pre><h3>UPDATE</h3><p>Allows the user to modify data:</p><pre>GRANT UPDATE ON birendra.* TO &#39;sakil&#39;@&#39;localhost&#39;;</pre><h3>DELETE</h3><p>Allows the user to delete data:</p><pre>GRANT DELETE ON birendra.* TO &#39;sakil&#39;@&#39;localhost&#39;;</pre><p>We can also combine privileges:</p><pre>GRANT SELECT, INSERT, UPDATE<br>ON birendra.*<br>TO &#39;sakil&#39;@&#39;localhost&#39;;</pre><h3>7. Grant All Privileges</h3><p>For development or testing, we might want the user to have full access to the database:</p><pre>GRANT ALL PRIVILEGES<br>ON birendra.*<br>TO &#39;sakil&#39;@&#39;localhost&#39;;</pre><p>Notice that this is:</p><pre>birendra.*</pre><p>not:</p><pre>*.*</pre><p>birendra.* means:</p><blockquote><em>All tables in the </em><em>birendra database.</em></blockquote><p>Whereas:</p><pre>*.*</pre><p>means:</p><blockquote><em>All databases and all tables.</em></blockquote><h3>8. Grant Global Privileges</h3><p>In my practice, I also used:</p><pre>GRANT ALL PRIVILEGES<br>ON *.*<br>TO &#39;om&#39;@&#39;localhost&#39;<br>WITH GRANT OPTION;</pre><p>This is a much more powerful permission.</p><p>Let’s break it down:</p><pre>*.*</pre><p>means all databases and all tables.</p><pre>&#39;om&#39;@&#39;localhost&#39;</pre><p>is the user receiving the permissions.</p><pre>WITH GRANT OPTION</pre><p>allows that user to grant privileges to other users.</p><p>For example, a user with this privilege could grant permissions to another account.</p><blockquote><em>⚠️ This is a very powerful permission and should be used carefully, especially on production servers.</em></blockquote><h3>9. Check Existing Users</h3><p>To see the users on the MariaDB server:</p><pre>SELECT User, Host FROM mysql.user;</pre><p>My server showed users such as:</p><pre>+-------------+-----------+<br>| User        | Host      |<br>+-------------+-----------+<br>| mariadb.sys | localhost |<br>| mysql       | localhost |<br>| om          | localhost |<br>| root        | localhost |<br>| sakil       | localhost |<br>| wordpress   | localhost |<br>+-------------+-----------+</pre><p>This confirms that sakil was successfully created.</p><h3>10. FLUSH PRIVILEGES</h3><p>A common command you will see in MySQL/MariaDB tutorials is:</p><pre>FLUSH PRIVILEGES;</pre><p>It tells MariaDB to reload privilege information.</p><p>In modern MariaDB, commands such as:</p><pre>CREATE USER</pre><p>and:</p><pre>GRANT</pre><p>already update the privilege system, so manually running FLUSH PRIVILEGES is generally not necessary after these commands.</p><p>However, it is still useful to know the command.</p><p>The correct spelling is:</p><pre>FLUSH PRIVILEGES;</pre><p>Not:</p><pre>FLUSH PRIVELEGES;</pre><h3>11. Complete Workflow</h3><p>The complete process can be summarized as:</p><pre>-- Create database<br>CREATE DATABASE birendra;</pre><pre>-- Create user<br>CREATE USER &#39;sakil&#39;@&#39;localhost&#39;<br>IDENTIFIED BY &#39;root&#39;;</pre><pre>-- Give user access to database<br>GRANT ALL PRIVILEGES<br>ON birendra.*<br>TO &#39;sakil&#39;@&#39;localhost&#39;;</pre><pre>-- Check privileges<br>SHOW GRANTS FOR &#39;sakil&#39;@&#39;localhost&#39;;</pre><pre>-- Check users<br>SELECT User, Host FROM mysql.user;</pre><h3>12. The Big Picture</h3><p>Think about MariaDB permissions like this:</p><pre>MariaDB Server<br>                   │<br>          ┌────────┴────────┐<br>          │                 │<br>      Database            Users<br>      birendra             sakil<br>          │                 │<br>          └────────┬────────┘<br>                   │<br>                 GRANT<br>                   │<br>                   ▼<br>          Database Privileges<br>                   │<br>        ┌──────────┼──────────┐<br>        ▼          ▼          ▼<br>      SELECT     INSERT     UPDATE<br>        │<br>        ▼<br>      DELETE</pre><p>The important concept is:</p><p><strong>Creating a user and giving a user permission are two different things.</strong></p><pre>CREATE USER<br>     ↓<br>User exists<br>     ↓<br>GRANT<br>     ↓<br>User gets permission</pre><h3>Conclusion</h3><p>In this practical MariaDB session, I learned how to:</p><ul><li>Create a database</li><li>Create a database user</li><li>Check existing users</li><li>Grant database privileges</li><li>Check granted privileges</li><li>Understand ALL PRIVILEGES</li><li>Understand WITH GRANT OPTION</li><li>Understand FLUSH PRIVILEGES</li></ul><p>The most important command to remember is:</p><pre>GRANT ALL PRIVILEGES<br>ON birendra.*<br>TO &#39;sakil&#39;@&#39;localhost&#39;;</pre><p>This is the basic pattern:</p><pre>GRANT → WHAT permission?<br>ON    → WHICH database/table?<br>TO    → WHICH user?</pre><p>Once this concept is clear, managing database access on a Linux server becomes much easier.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2d3c39014d77" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Set Up a LAMP Stack on Ubuntu: A Beginner-Friendly DevOps Guide]]></title>
            <link>https://medium.com/@omprakashlamichhane10/how-to-set-up-a-lamp-stack-on-ubuntu-a-beginner-friendly-devops-guide-8453dba6a71f?source=rss-92d3b6df1568------2</link>
            <guid isPermaLink="false">https://medium.com/p/8453dba6a71f</guid>
            <dc:creator><![CDATA[Omprakashlamichhane]]></dc:creator>
            <pubDate>Sun, 13 Sep 2026 07:54:35 GMT</pubDate>
            <atom:updated>2026-09-13T07:54:35.423Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Linux + Apache + MariaDB + PHP.Build Your First Web Server from Scratch</strong></p><p>If you’re starting your journey into <strong>Linux, Web Development, or DevOps</strong>, setting up a LAMP stack is one of the best hands-on projects you can do.</p><p>You will work directly with a Linux server, install a web server, configure PHP, set up a database, manage services, work with ports, and troubleshoot common problems.</p><p>By the end of this tutorial, you will have a working web server capable of running PHP applications and connecting them to a database.</p><p>Let’s build it step by step. 🚀</p><h3>What Is a LAMP Stack?</h3><p><strong>LAMP</strong> is an acronym for four technologies:</p><ul><li><strong>L — Linux</strong></li><li><strong>A — Apache</strong></li><li><strong>M — MySQL/MariaDB</strong></li><li><strong>P — PHP</strong></li></ul><p>Together, these technologies provide a complete environment for running dynamic websites and web applications.</p><p>A simple architecture looks like this:</p><pre>🌐 Browser<br>                        │<br>                        │ HTTP / HTTPS<br>                        ▼<br>                 ┌─────────────┐<br>                 │   Apache    │<br>                 │ Web Server  │<br>                 └──────┬──────┘<br>                        │<br>                        ▼<br>                 ┌─────────────┐<br>                 │     PHP     │<br>                 │  Backend    │<br>                 └──────┬──────┘<br>                        │<br>                        │ SQL<br>                        ▼<br>                 ┌─────────────┐<br>                 │ MariaDB /   │<br>                 │    MySQL    │<br>                 └─────────────┘</pre><h3>What does each component do?</h3><p><strong>Linux</strong> provides the operating system.</p><p><strong>Apache</strong> receives HTTP requests and serves web pages.</p><p><strong>PHP</strong> processes server-side application code.</p><p><strong>MariaDB/MySQL</strong> stores application data.</p><p>For example, imagine a user logs into a website:</p><pre>User<br> │<br> │ email + password<br> ▼<br>Apache<br> │<br> ▼<br>PHP<br> │<br> │ SQL query<br> ▼<br>MariaDB<br> │<br> │ user data<br> ▼<br>PHP<br> │<br> ▼<br>Apache<br> │<br> ▼<br>Browser</pre><p>That’s the basic idea behind a traditional LAMP application.</p><h3>What You Will Learn</h3><p>By following this tutorial, you will learn how to:</p><ul><li>Prepare an Ubuntu server</li><li>Update Ubuntu packages</li><li>Configure UFW firewall</li><li>Install Apache</li><li>Understand Apache’s web directory</li><li>Install PHP</li><li>Test PHP</li><li>Install MariaDB</li><li>Secure MariaDB</li><li>Test the database</li><li>Understand Linux services</li><li>Check listening ports</li><li>Read Apache logs</li><li>Understand how the components communicate</li></ul><h3>Prerequisites</h3><p>Before starting, you should have:</p><ul><li>An Ubuntu server or Ubuntu virtual machine</li><li>A user account with sudo privileges</li><li>Internet connectivity</li><li>Basic Linux terminal knowledge</li><li>SSH access if you’re using a remote server</li></ul><p>If you’re practicing locally, you can also use an Ubuntu VM in VirtualBox.</p><p>For example:</p><pre>Ubuntu VM<br>    │<br>    ├── Apache<br>    ├── PHP<br>    └── MariaDB</pre><h3>Step 1 — Update Your Ubuntu Server</h3><p>Before installing anything, update the package information.</p><p>Run:</p><pre>sudo apt update</pre><p>Then upgrade the installed packages:</p><pre>sudo apt upgrade</pre><p>You can also combine them:</p><pre>sudo apt update &amp;&amp; sudo apt upgrade</pre><h3>What does apt update do?</h3><p>It downloads the latest information about available packages.</p><p>Think of it as:</p><pre>&quot;Ubuntu, tell me what new software updates are available.&quot;</pre><h3>What does apt upgrade do?</h3><p>It installs the available updates.</p><p>So remember:</p><pre>apt update<br>      ↓<br>Check for updates</pre><pre>apt upgrade<br>      ↓<br>Install updates</pre><h3>Step 2 — Configure the Firewall</h3><p>Ubuntu commonly uses <strong>UFW</strong>, which stands for <strong>Uncomplicated Firewall</strong>.</p><p>Before enabling the firewall, we need to allow the ports that our server will use.</p><p>First, allow SSH:</p><pre>sudo ufw allow ssh</pre><p>SSH normally uses:</p><pre>Port 22</pre><p>Next, allow HTTP:</p><pre>sudo ufw allow 80</pre><p>HTTP uses port 80.</p><p>Then allow HTTPS:</p><pre>sudo ufw allow 443</pre><p>HTTPS uses port 443.</p><p>Now enable UFW:</p><pre>sudo ufw enable</pre><p>Check the status:</p><pre>sudo ufw status</pre><p>You should see something similar to:</p><pre>Status: active</pre><pre>To                         Action      From<br>--                         ------      ----<br>22/tcp                     ALLOW       Anywhere<br>80/tcp                     ALLOW       Anywhere<br>443/tcp                    ALLOW       Anywhere</pre><h3>⚠️ Important SSH Warning</h3><p>If you’re working on a remote server, <strong>allow SSH before enabling UFW</strong>.</p><p>Otherwise, you may accidentally block your own SSH connection.</p><p>A safe order is:</p><pre>sudo ufw allow ssh<br>sudo ufw allow 80<br>sudo ufw allow 443<br>sudo ufw enable</pre><h3>Step 3 — Install Apache</h3><p>Now let’s install the <strong>A</strong> in LAMP.</p><p>Run:</p><pre>sudo apt install apache2</pre><p>Ubuntu will download and install Apache and its required dependencies.</p><p>After installation, check the Apache service:</p><pre>sudo systemctl status apache2</pre><p>Look for:</p><pre>Active: active (running)</pre><p>That means Apache is running successfully.</p><h3>Understanding systemctl</h3><p>You will use systemctl a lot as a DevOps engineer.</p><p>For example:</p><pre>sudo systemctl start apache2</pre><p>Starts Apache.</p><pre>sudo systemctl stop apache2</pre><p>Stops Apache.</p><pre>sudo systemctl restart apache2</pre><p>Restarts Apache.</p><pre>sudo systemctl status apache2</pre><p>Checks its current status.</p><p>You can think of it as:</p><pre>start    → turn it on<br>stop     → turn it off<br>restart  → turn it off and on again<br>status   → check what&#39;s happening</pre><h3>Step 4 — Test Apache</h3><p>Find your Ubuntu server’s IP address:</p><pre>ip addr</pre><p>You can also use:</p><pre>hostname -I</pre><p>Suppose your server IP is:</p><pre>192.168.56.101</pre><p>Open your browser and visit:</p><pre>http://192.168.56.101</pre><p>If Apache is working correctly, you should see the <strong>Apache2 Ubuntu Default Page</strong>.</p><p>🎉 Congratulations!</p><p>You have successfully installed a web server.</p><p>Your current architecture is:</p><pre>Linux<br>  │<br>  ▼<br>Apache<br>  │<br>  ▼<br>Browser</pre><p>But we’re not finished yet.</p><h3>Step 5 — Understand Apache’s Web Root</h3><p>Apache commonly serves website files from:</p><pre>/var/www/html</pre><p>Let’s look inside:</p><pre>ls -la /var/www/html</pre><p>You may see:</p><pre>index.html</pre><p>This is the default Apache webpage.</p><p>Try:</p><pre>cd /var/www/html</pre><p>Then:</p><pre>pwd</pre><p>You should get:</p><pre>/var/www/html</pre><p>This is an important directory to remember.</p><p>For a basic Apache setup:</p><pre>/var/www/html<br>       │<br>       ├── index.html<br>       ├── index.php<br>       └── other website files</pre><h3>Step 6 — Install PHP</h3><p>Now we’re ready for the <strong>P</strong> in LAMP.</p><p>Install PHP:</p><pre>sudo apt install php libapache2-mod-php php-mysql</pre><p>Three important packages here are:</p><h3>php</h3><p>The PHP language itself.</p><h3>libapache2-mod-php</h3><p>Allows Apache to process PHP files.</p><h3>php-mysql</h3><p>Allows PHP applications to communicate with MySQL/MariaDB.</p><p>The relationship looks like this:</p><pre>Apache<br>   │<br>   │ PHP request<br>   ▼<br>PHP<br>   │<br>   │ Database request<br>   ▼<br>MariaDB</pre><h3>Step 7 — Check the PHP Version</h3><p>Run:</p><pre>php --version</pre><p>You should see something similar to:</p><pre>PHP 8.x.x</pre><p>The exact version depends on your Ubuntu release and configured repositories.</p><h3>Why shouldn’t we blindly use PHP 7.4?</h3><p>You may find older tutorials that contain commands such as:</p><pre>sudo apt install php7.4</pre><p>PHP 7.4 is an old, end-of-life PHP release.</p><p>For a new installation, it’s better to use the PHP version provided by your current Ubuntu repositories unless your project specifically requires an older version.</p><h3>Step 8 — Restart Apache</h3><p>After installing PHP, restart Apache:</p><pre>sudo systemctl restart apache2</pre><p>Then verify:</p><pre>sudo systemctl status apache2</pre><p>You should see:</p><pre>Active: active (running)</pre><h3>Step 9 — Create a PHP Test Page</h3><p>Let’s verify that Apache can actually execute PHP.</p><p>Move into the web directory:</p><pre>cd /var/www/html</pre><p>Create a PHP file:</p><pre>sudo nano info.php</pre><p>Add:</p><pre>&lt;?php<br>phpinfo();<br>?&gt;</pre><p>Save the file.</p><p>Now open:</p><pre>http://YOUR_SERVER_IP/info.php</pre><p>For example:</p><pre>http://192.168.56.101/info.php</pre><p>If everything is working, you’ll see a PHP information page.</p><p>It contains information about:</p><ul><li>PHP version</li><li>Enabled modules</li><li>Configuration</li><li>Server information</li><li>Environment variables</li><li>PHP settings</li></ul><p>This confirms:</p><pre>Apache ✅<br>PHP    ✅</pre><h3>Step 10 — Remove the PHP Info Page</h3><p>The phpinfo() page is useful for testing, but it shouldn&#39;t normally remain publicly accessible.</p><p>Remove it:</p><pre>sudo rm /var/www/html/info.php</pre><p>Verify:</p><pre>ls -la /var/www/html</pre><p>The test file should be gone.</p><h3>Step 11 — Install MariaDB</h3><p>Now we need the <strong>M</strong> in LAMP.</p><p>We can use MariaDB as our database server.</p><p>Install:</p><pre>sudo apt install mariadb-server mariadb-client</pre><p>Once installation finishes, check the service:</p><pre>sudo systemctl status mariadb</pre><p>Look for:</p><pre>Active: active (running)</pre><p>If you see that, MariaDB is running successfully.</p><h3>MySQL vs MariaDB</h3><p>You might be wondering:</p><blockquote><em>“Why are we using MariaDB instead of MySQL?”</em></blockquote><p>MariaDB is a MySQL-compatible relational database system and is widely used on Linux systems.</p><p>The basic idea is the same:</p><pre>PHP<br> │<br> │ SQL<br> ▼<br>Database<br> │<br> ▼<br>MariaDB / MySQL</pre><p>For learning the LAMP architecture, either can be used.</p><h3>Step 12 — Secure MariaDB</h3><p>A fresh database installation should be reviewed and secured.</p><p>Run:</p><pre>sudo mysql_secure_installation</pre><p>The exact questions depend on the MariaDB version.</p><p>The process can help you remove unnecessary/default access such as:</p><ul><li>Anonymous users</li><li>Test databases</li><li>Remote root access</li></ul><p>It also reloads privilege information.</p><h3>Don’t blindly follow old tutorials</h3><p>Older tutorials sometimes say:</p><blockquote><em>“Press Enter for the current root password and then create a new root password.”</em></blockquote><p>Modern Ubuntu/MariaDB installations can use <strong>Unix socket authentication</strong> for the database root account.</p><p>So instead of assuming the authentication method, first test:</p><pre>sudo mariadb</pre><p>If you successfully enter:</p><pre>MariaDB [(none)]&gt;</pre><p>then you can administer MariaDB using your Linux sudo privileges.</p><p>To exit:</p><pre>exit;</pre><h3>Step 13 — Test the Database</h3><p>Let’s enter MariaDB:</p><pre>sudo mariadb</pre><p>Now run:</p><pre>SHOW DATABASES;</pre><p>You should see databases similar to:</p><pre>information_schema<br>mysql<br>performance_schema<br>sys</pre><p>These are system databases.</p><p>To exit:</p><pre>exit;</pre><h3>Step 14 — Understand the LAMP Architecture</h3><p>At this point, our complete stack looks like this:</p><pre>🌐 Browser<br>                     │<br>                     │ HTTP<br>                     ▼<br>              ┌──────────────┐<br>              │    Apache    │<br>              │ Web Server   │<br>              └──────┬───────┘<br>                     │<br>                     │ PHP<br>                     ▼<br>              ┌──────────────┐<br>              │     PHP      │<br>              │ Application  │<br>              └──────┬───────┘<br>                     │<br>                     │ SQL<br>                     ▼<br>              ┌──────────────┐<br>              │   MariaDB    │<br>              │   Database   │<br>              └──────────────┘</pre><p>Let’s imagine a login request.</p><p>The user enters:</p><pre>Email: om@example.com<br>Password: ********</pre><p>The request goes:</p><pre>Browser<br>   ↓<br>Apache<br>   ↓<br>PHP<br>   ↓<br>MariaDB<br>   ↓<br>Check user<br>   ↓<br>PHP<br>   ↓<br>Apache<br>   ↓<br>Browser</pre><p>This is the basic request flow of many server-side applications.</p><h3>Step 15 — Check All Services</h3><p>Now let’s check everything we’ve installed.</p><h3>Check Apache</h3><pre>sudo systemctl status apache2</pre><h3>Check MariaDB</h3><pre>sudo systemctl status mariadb</pre><h3>Check PHP</h3><pre>php --version</pre><h3>Check firewall</h3><pre>sudo ufw status</pre><p>Your basic environment should now look like:</p><pre>Linux             ✅<br>Apache            ✅<br>PHP               ✅<br>MariaDB           ✅<br>Firewall          ✅</pre><p>🎉 Your LAMP stack is ready!</p><h3>Step 16 — Check Which Ports Are Listening</h3><p>As a DevOps learner, you should understand ports.</p><p>Run:</p><pre>sudo ss -tulpn</pre><p>You may see Apache listening on:</p><pre>:80</pre><p>MariaDB commonly uses:</p><pre>:3306</pre><p>SSH commonly uses:</p><pre>:22</pre><p>So the simplified picture is:</p><pre>SSH       → 22<br>HTTP      → 80<br>HTTPS     → 443<br>MariaDB   → 3306</pre><h3>Important security concept</h3><p>You usually don’t need to expose every service to the internet.</p><p>For example:</p><pre>Internet<br>   │<br>   ├── 80  → Apache<br>   └── 443 → Apache</pre><pre>SSH<br>   │<br>   └── 22 → Administration</pre><pre>MariaDB<br>   │<br>   └── 3306 → Ideally private/internal</pre><p>A database usually shouldn’t be publicly accessible unless there’s a specific reason and proper security controls.</p><h3>Step 17 — Learn Where Apache Logs Are Stored</h3><p>Logs are extremely important in DevOps.</p><p>Apache logs are commonly located under:</p><pre>/var/log/apache2/</pre><p>List them:</p><pre>ls -la /var/log/apache2/</pre><p>You will commonly find:</p><pre>access.log<br>error.log</pre><h3>Access log</h3><p>Shows incoming requests:</p><pre>sudo tail -f /var/log/apache2/access.log</pre><h3>Error log</h3><p>Shows Apache errors:</p><pre>sudo tail -f /var/log/apache2/error.log</pre><p>The -f option means:</p><blockquote><em>Follow the file as new lines are added.</em></blockquote><p>This is very useful when troubleshooting a website.</p><h3>Common Problems and Solutions</h3><h3>Problem 1: Apache won’t start</h3><p>Check:</p><pre>sudo systemctl status apache2</pre><p>Then check the configuration:</p><pre>sudo apache2ctl configtest</pre><p>If everything is correct, you’ll see:</p><pre>Syntax OK</pre><h3>Problem 2: Port 80 is already in use</h3><p>Check:</p><pre>sudo ss -tulpn | grep :80</pre><p>You might discover another service, such as Nginx, already using port 80.</p><p>For example:</p><pre>nginx<br>   ↓<br>port 80</pre><p>Then Apache cannot also bind to port 80.</p><p>This is a common issue when learning both Nginx and Apache.</p><h3>Problem 3: PHP File Downloads Instead of Running</h3><p>If your browser downloads:</p><pre>info.php</pre><p>instead of displaying PHP output, Apache may not be configured to process PHP correctly.</p><p>First check:</p><pre>php --version</pre><p>Then:</p><pre>sudo systemctl restart apache2</pre><p>Check that the Apache PHP module/package is installed:</p><pre>dpkg -l | grep libapache2-mod-php</pre><h3>Problem 4: Cannot Access the Website</h3><p>First check Apache:</p><pre>sudo systemctl status apache2</pre><p>Then check the firewall:</p><pre>sudo ufw status</pre><p>Then check port 80:</p><pre>sudo ss -tulpn | grep :80</pre><p>Finally check Apache’s error log:</p><pre>sudo tail -f /var/log/apache2/error.log</pre><p>A good DevOps troubleshooting mindset is:</p><pre>Is the service running?<br>        ↓<br>Is the port listening?<br>        ↓<br>Is the firewall allowing it?<br>        ↓<br>Is the application working?<br>        ↓<br>What do the logs say?</pre><h3>What I Learned From This Project</h3><p>Setting up a LAMP stack isn’t just about installing four packages.</p><p>It teaches several important DevOps concepts.</p><h3>1. Package Management</h3><p>We used:</p><pre>apt</pre><p>to install and update software.</p><h3>2. Service Management</h3><p>We used:</p><pre>systemctl</pre><p>to manage Apache and MariaDB.</p><h3>3. Networking</h3><p>We learned about:</p><pre>22 → SSH<br>80 → HTTP<br>443 → HTTPS<br>3306 → MariaDB/MySQL</pre><h3>4. Firewall</h3><p>We used:</p><pre>ufw</pre><p>to control incoming connections.</p><h3>5. Logs</h3><p>We learned where Apache logs are stored and how to monitor them.</p><h3>6. Web Server Architecture</h3><p>We learned how:</p><pre>Browser<br>   ↓<br>Apache<br>   ↓<br>PHP<br>   ↓<br>MariaDB</pre><p>work together.</p><h3>What’s Next?</h3><p>If you’re learning DevOps, LAMP should not be the final destination.</p><p>It should be one of your foundations.</p><p>A good learning path is:</p><pre>Linux<br>               ↓<br>           Networking<br>               ↓<br>              SSH<br>               ↓<br>         Apache / Nginx<br>               ↓<br>             LAMP<br>               ↓<br>          Git &amp; GitHub<br>               ↓<br>             Docker<br>               ↓<br>        Docker Compose<br>               ↓<br>             CI/CD<br>               ↓<br>       Reverse Proxy<br>               ↓<br>             Cloud<br>               ↓<br>          Kubernetes</pre><p>And because Docker is an important part of modern DevOps, the next interesting challenge is to take the LAMP stack you’ve just built and containerize it.</p><p>Instead of:</p><pre>Ubuntu<br> ├── Apache<br> ├── PHP<br> └── MariaDB</pre><p>you can build:</p><pre>Docker Host<br>     │<br>     ├── Apache + PHP Container<br>     │<br>     └── MariaDB Container</pre><p>That is where Linux fundamentals start connecting directly with modern DevOps practices.</p><h3>Final Thoughts</h3><p>Setting up a LAMP stack is one of those projects that looks simple at first but teaches you a lot.</p><p>You don’t just install Apache, PHP, and MariaDB.</p><p>You learn how a server works.</p><p>You learn how services run.</p><p>You learn how ports work.</p><p>You learn how firewalls control traffic.</p><p>You learn where logs are stored.</p><p>And most importantly, you begin to understand how a request travels from a user’s browser to a server and eventually to a database.</p><p>The commands may look simple:</p><pre>sudo apt update<br>sudo apt install apache2<br>sudo apt install php<br>sudo apt install mariadb-server</pre><p>But behind these commands is an entire web-server architecture.</p><p><strong>#Linux #DevOps #LAMP #Apache #PHP #MariaDB #Ubuntu #WebServer #LinuxAdministration #DevOpsLearning #Backend #Docker</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8453dba6a71f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Deploy a Node.js Application on Ubuntu Using PM2 and Nginx — A Complete Step-by-Step Guide]]></title>
            <link>https://medium.com/@omprakashlamichhane10/how-to-deploy-a-node-js-application-on-ubuntu-using-pm2-and-nginx-a-complete-step-by-step-guide-7ffa1e59181b?source=rss-92d3b6df1568------2</link>
            <guid isPermaLink="false">https://medium.com/p/7ffa1e59181b</guid>
            <dc:creator><![CDATA[Omprakashlamichhane]]></dc:creator>
            <pubDate>Sat, 01 Aug 2026 17:02:59 GMT</pubDate>
            <atom:updated>2026-08-01T17:02:59.442Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>Deploying a Node.js application is an essential skill for every backend developer and DevOps engineer. Running an application with node app.js is fine for development, but it is not suitable for production because the application stops when the terminal closes or the server restarts.</p><p>In this guide, you’ll learn how to deploy a Node.js application on an Ubuntu server using <strong>PM2</strong> as the process manager and <strong>Nginx</strong> as the reverse proxy.</p><p>By the end of this tutorial, your application will:</p><ul><li>Run continuously in the background.</li><li>Restart automatically if it crashes.</li><li>Start automatically after a server reboot.</li><li>Be accessible through Nginx on port 80.</li></ul><h3>Prerequisites</h3><p>Before starting, make sure you have:</p><ul><li>Ubuntu Server (20.04/22.04/24.04)</li><li>Node.js installed</li><li>npm installed</li><li>Git installed</li><li>A Node.js project</li><li>A user with sudo privileges</li></ul><h3>Step 1: Update the Server</h3><p>Update your package list and installed packages.</p><pre>sudo apt update<br>sudo apt upgrade -y</pre><h3>Step 2: Install Node.js and npm</h3><p>Install Node.js and npm.</p><pre>sudo apt install nodejs npm -y</pre><p>Verify the installation.</p><pre>node -v<br>npm -v</pre><p>Example:</p><pre>v22.x.x<br>10.x.x</pre><h3>Step 3: Install Git</h3><pre>sudo apt install git -y</pre><p>Verify:</p><pre>git --version</pre><h3>Step 4: Clone Your Project</h3><p>Clone your repository.</p><pre>git clone https://github.com/your-username/NodeJS-Portfolio-Website.git</pre><p>Move into the project.</p><pre>cd NodeJS-Portfolio-Website</pre><h3>Step 5: Install Project Dependencies</h3><p>Install all required packages.</p><pre>npm install</pre><p>This command reads the package.json file and installs all dependencies.</p><h3>Step 6: Run the Application</h3><p>Start the application manually.</p><pre>node app.js</pre><p>If everything is working correctly, open:</p><pre>http://localhost:3000</pre><p>If you receive an error like:</p><pre>Error: listen EADDRINUSE: address already in use :::3000</pre><p>It means another application is already using port <strong>3000</strong>.</p><p>Check which process is using the port.</p><pre>sudo lsof -i :3000</pre><p>Kill the process.</p><pre>sudo kill -9 PID</pre><p>Or change your application’s port to another value, such as <strong>3001</strong>.</p><h3>Step 7: Install PM2</h3><p>PM2 keeps Node.js applications running in the background and automatically restarts them after crashes or server reboots.</p><p>Install PM2 globally.</p><pre>sudo npm install -g pm2</pre><p>Verify installation.</p><pre>pm2 -v</pre><h3>Step 8: Start the Application with PM2</h3><p>Navigate to the project directory.</p><pre>cd ~/NodeJS-Portfolio-Website</pre><p>Start the application.</p><pre>pm2 start app.js --name portfolio</pre><p>Check running processes.</p><pre>pm2 status</pre><p>View logs.</p><pre>pm2 logs portfolio</pre><p>Restart the application.</p><pre>pm2 restart portfolio</pre><p>Stop the application.</p><pre>pm2 stop portfolio</pre><p>Delete the application.</p><pre>pm2 delete portfolio</pre><h3>Step 9: Configure PM2 to Start After Reboot</h3><p>Generate the startup script.</p><pre>pm2 startup</pre><p>PM2 will display a command beginning with sudo. Copy and execute that command.</p><p>Save the current process list.</p><pre>pm2 save</pre><p>Now your application will automatically start after every reboot.</p><h3>Step 10: Install Nginx</h3><p>Install Nginx.</p><pre>sudo apt install nginx -y</pre><p>Enable the service.</p><pre>sudo systemctl enable nginx<br>sudo systemctl start nginx</pre><p>Check its status.</p><pre>sudo systemctl status nginx</pre><h3>Step 11: Configure Nginx as a Reverse Proxy</h3><p>Create a new configuration file.</p><pre>sudo nano /etc/nginx/sites-available/portfolio</pre><p>Paste the following configuration (replace 3000 with your application&#39;s port if necessary):</p><pre>server {<br>    listen 80;<br>    server_name YOUR_SERVER_IP_OR_DOMAIN;</pre><pre>    location / {<br>        proxy_pass <a href="http://localhost:3000;">http://localhost:3000;</a><br>        proxy_http_version 1.1;</pre><pre>        proxy_set_header Upgrade $http_upgrade;<br>        proxy_set_header Connection &quot;upgrade&quot;;<br>        proxy_set_header Host $host;<br>        proxy_cache_bypass $http_upgrade;<br>    }<br>}</pre><p>Enable the site.</p><pre>sudo ln -s /etc/nginx/sites-available/portfolio /etc/nginx/sites-enabled/</pre><p>Test the configuration.</p><pre>sudo nginx -t</pre><p>Reload Nginx.</p><pre>sudo systemctl reload nginx</pre><h3>Step 12: Configure the Firewall</h3><p>Allow HTTP traffic.</p><pre>sudo ufw allow &#39;Nginx Full&#39;</pre><p>Verify firewall rules.</p><pre>sudo ufw status</pre><h3>Step 13: Test the Deployment</h3><p>Find your server IP.</p><pre>hostname -I</pre><p>Open a browser and visit:</p><pre>http://YOUR_SERVER_IP</pre><p>If you have configured a domain, visit:</p><pre>http://your-domain.com</pre><p>Your Node.js application should now be accessible through Nginx.</p><h3>Useful PM2 Commands</h3><p>Check status:</p><pre>pm2 status</pre><p>View logs:</p><pre>pm2 logs</pre><p>Restart:</p><pre>pm2 restart portfolio</pre><p>Stop:</p><pre>pm2 stop portfolio</pre><p>Delete:</p><pre>pm2 delete portfolio</pre><p>Monitor CPU and memory:</p><pre>pm2 monit</pre><h3>Common Errors and Solutions</h3><h3>Error: EADDRINUSE</h3><p>Cause: Another process is already using the application’s port.</p><p>Solution:</p><pre>sudo lsof -i :3000<br>sudo kill -9 PID</pre><p>Or change the application’s port.</p><h3>PM2 Error: Script not found</h3><p>Cause: Running the command outside the project directory.</p><p>Solution:</p><pre>cd ~/NodeJS-Portfolio-Website<br>pm2 start app.js --name portfolio</pre><h3>Nginx Configuration Test Failed</h3><p>Run:</p><pre>sudo nginx -t</pre><p>Correct the configuration file before reloading Nginx.</p><h3>Conclusion</h3><p>Deploying a Node.js application with <strong>PM2</strong> and <strong>Nginx</strong> creates a reliable production setup. PM2 ensures your application stays online and automatically recovers from failures, while Nginx acts as a reverse proxy that efficiently handles incoming HTTP requests.</p><p>This deployment approach is widely used in production environments and is an excellent foundation for learning more advanced DevOps tools such as Docker, Jenkins, GitHub Actions, Kubernetes, and cloud platforms like AWS or Azure.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7ffa1e59181b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to View MySQL Users and Their Hosts in Linux (A Beginner’s Guide)]]></title>
            <link>https://medium.com/@omprakashlamichhane10/how-to-view-mysql-users-and-their-hosts-in-linux-a-beginners-guide-17d5124967fe?source=rss-92d3b6df1568------2</link>
            <guid isPermaLink="false">https://medium.com/p/17d5124967fe</guid>
            <dc:creator><![CDATA[Omprakashlamichhane]]></dc:creator>
            <pubDate>Tue, 28 Jul 2026 17:18:47 GMT</pubDate>
            <atom:updated>2026-07-28T17:18:47.051Z</atom:updated>
            <content:encoded><![CDATA[<p>Managing users is one of the most important tasks in MySQL administration. Whether you’re a beginner learning databases or a DevOps engineer managing production servers, knowing how to list MySQL users and understand where they can connect from is essential.</p><p>In this guide, you’ll learn how to view all MySQL users, filter users by host, inspect permissions, and understand the significance of the host column.</p><h3>Why Check MySQL Users?</h3><p>Every MySQL user account consists of two parts:</p><ul><li><strong>Username</strong></li><li><strong>Host</strong></li></ul><p>For example:</p><pre>&#39;admin&#39;@&#39;localhost&#39;</pre><p>Here:</p><ul><li>admin is the username.</li><li>localhost specifies the machine from which the user is allowed to connect.</li></ul><p>Knowing this information helps you:</p><ul><li>Audit database access.</li><li>Troubleshoot login issues.</li><li>Verify application accounts.</li><li>Improve database security.</li><li>Manage user permissions.</li></ul><h3>Step 1: Log in to MySQL</h3><p>On Ubuntu, you can log in as the root user with:</p><pre>sudo mysql</pre><p>If you’re using password authentication:</p><pre>mysql -u root -p</pre><p>After logging in, you’ll see the MySQL prompt:</p><pre>mysql&gt;</pre><h3>Step 2: View All MySQL Users</h3><p>Run the following SQL command:</p><pre>SELECT user, host<br>FROM mysql.user;</pre><p>Example output:</p><p>UserHostrootlocalhostadminlocalhostmysql.syslocalhostmysql.sessionlocalhost</p><p>This query lists every MySQL account along with the host from which it is allowed to connect.</p><h3>Understanding the host Column</h3><p>The host value determines where a user is allowed to connect from.</p><h3>localhost</h3><pre>admin@localhost</pre><p>The user can connect <strong>only from the same machine</strong> where MySQL is running.</p><p>This is the most secure option for local applications.</p><h3>% (Wildcard)</h3><pre>admin@%</pre><p>The % symbol means the user can connect from <strong>any host</strong>, provided the MySQL server and firewall allow it.</p><p>This is useful for remote applications but should be used carefully because it increases the attack surface.</p><h3>Specific IP Address</h3><pre>admin@192.168.1.100</pre><p>The user can connect <strong>only</strong> from the specified IP address.</p><p>This is often used in production environments for better security.</p><h3>View Only Localhost Users</h3><p>If you want to display only users that can connect from the local machine:</p><pre>SELECT user<br>FROM mysql.user<br>WHERE host = &#39;localhost&#39;;</pre><p>Example output:</p><p>Userrootadminmysql.sys</p><h3>Find a Specific User</h3><p>To check whether a particular user exists:</p><pre>SELECT user, host<br>FROM mysql.user<br>WHERE user = &#39;admin&#39;;</pre><p>Example output:</p><p>UserHostadminlocalhost</p><p>This is useful when verifying that a user account has been created successfully.</p><h3>View User Privileges</h3><p>To see the permissions granted to a user:</p><pre>SHOW GRANTS FOR &#39;admin&#39;@&#39;localhost&#39;;</pre><p>Example output:</p><pre>GRANT ALL PRIVILEGES ON `college`.* TO &#39;admin&#39;@&#39;localhost&#39;;</pre><p>This shows exactly what the user is allowed to do.</p><h3>Create a New User</h3><p>If you don’t have a user yet, create one:</p><pre>CREATE USER &#39;admin&#39;@&#39;localhost&#39;<br>IDENTIFIED BY &#39;StrongPassword123!&#39;;</pre><p>Grant access to a database:</p><pre>GRANT ALL PRIVILEGES<br>ON college.*<br>TO &#39;admin&#39;@&#39;localhost&#39;;</pre><p>Apply the changes:</p><pre>FLUSH PRIVILEGES;</pre><p>Now you can verify the new account:</p><pre>SELECT user, host<br>FROM mysql.user;</pre><h3>Common Commands for User Management</h3><p>CommandDescriptionSELECT user, host FROM mysql.user;List all MySQL usersSHOW GRANTS FOR &#39;user&#39;@&#39;host&#39;;Display user privilegesCREATE USER ...Create a new userGRANT ...Grant permissionsFLUSH PRIVILEGES;Reload privilege tablesDROP USER ...Remove a user</p><h3>Best Practices</h3><ul><li>Create separate users for each application.</li><li>Avoid using the root account in production applications.</li><li>Grant only the permissions users need.</li><li>Prefer localhost when remote access isn&#39;t required.</li><li>Use strong, unique passwords.</li><li>Regularly review and remove unused accounts.</li></ul><h3>Conclusion</h3><p>Understanding how to view MySQL users is a fundamental database administration skill. By listing users, checking their hosts, and reviewing their privileges, you can manage access more securely and troubleshoot authentication issues more effectively.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=17d5124967fe" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Day 18 of devops| MySQL on Linux for DevOps Beginners: From Installation to User Management]]></title>
            <link>https://medium.com/@omprakashlamichhane10/day-18-of-devops-mysql-on-linux-for-devops-beginners-from-installation-to-user-management-1413106008df?source=rss-92d3b6df1568------2</link>
            <guid isPermaLink="false">https://medium.com/p/1413106008df</guid>
            <dc:creator><![CDATA[Omprakashlamichhane]]></dc:creator>
            <pubDate>Tue, 28 Jul 2026 17:07:11 GMT</pubDate>
            <atom:updated>2026-07-28T17:07:11.302Z</atom:updated>
            <content:encoded><![CDATA[<p>Databases are a core component of modern infrastructure. Whether you’re deploying a Laravel application, a Node.js API, a Django service, or a WordPress website, chances are you’ll need a database server.</p><p>For DevOps engineers, knowing how to install, configure, secure, and manage MySQL is an essential skill. In this guide, you’ll learn how to install MySQL on Ubuntu, manage its service with systemd, create databases, manage users, and assign permissions.</p><h3>What is MySQL?</h3><p>MySQL is an open-source Relational Database Management System (RDBMS) that stores data in tables. Applications communicate with MySQL using Structured Query Language (SQL).</p><p>Common use cases include:</p><ul><li>Web applications</li><li>REST APIs</li><li>E-commerce platforms</li><li>Content Management Systems</li><li>Analytics dashboards</li><li>Internal enterprise applications</li></ul><h3>Prerequisites</h3><p>Before installing MySQL, ensure you have:</p><ul><li>Ubuntu Linux server</li><li>A user with sudo privileges</li><li>Internet connectivity</li><li>Terminal access</li></ul><h3>Step 1: Update the Package Index</h3><p>Always refresh the package list before installing software.</p><pre>sudo apt update<br>sudo apt upgrade -y</pre><p><strong>Why?</strong></p><ul><li>Downloads the latest package information.</li><li>Installs available security updates.</li><li>Prevents installation issues caused by outdated package indexes.</li></ul><h3>Step 2: Install MySQL Server</h3><p>Install the MySQL server package.</p><pre>sudo apt install mysql-server -y</pre><p>The -y option automatically answers <strong>Yes</strong> to installation prompts.</p><p>Verify the installation:</p><pre>mysql --version</pre><p>Example output:</p><pre>mysql  Ver 8.0.xx for Linux on x86_64</pre><h3>Step 3: Manage the MySQL Service</h3><p>On Ubuntu, MySQL is managed by systemd.</p><p>Check its status:</p><pre>sudo systemctl status mysql</pre><p>Start the service:</p><pre>sudo systemctl start mysql</pre><p>Stop the service:</p><pre>sudo systemctl stop mysql</pre><p>Restart the service:</p><pre>sudo systemctl restart mysql</pre><p>Enable MySQL to start automatically when the server boots:</p><pre>sudo systemctl enable mysql</pre><p>Reload configuration without fully restarting:</p><pre>sudo systemctl reload mysql</pre><h3>Step 4: Secure the Installation</h3><p>Run MySQL’s built-in security script.</p><pre>sudo mysql_secure_installation</pre><p>This helps you:</p><ul><li>Remove anonymous users</li><li>Disable remote root login</li><li>Remove the test database</li><li>Reload privilege tables</li><li>Configure authentication and password policies (depending on version)</li></ul><p>Securing a fresh installation reduces unnecessary security risks.</p><h3>Step 5: Connect to MySQL</h3><p>Ubuntu commonly uses socket authentication for the root account:</p><pre>sudo mysql</pre><p>If you’ve configured password authentication:</p><pre>mysql -u root -p</pre><p>Exit the MySQL shell:</p><pre>EXIT;</pre><h3>Step 6: Explore Existing Databases</h3><p>Display all databases:</p><pre>SHOW DATABASES;</pre><p>Typical system databases include:</p><ul><li>information_schema</li><li>mysql</li><li>performance_schema</li><li>sys</li></ul><p>These are used internally by MySQL.</p><h3>Step 7: Create Your First Database</h3><p>Create a database named college:</p><pre>CREATE DATABASE college;</pre><p>Verify:</p><pre>SHOW DATABASES;</pre><p>Switch to it:</p><pre>USE college;</pre><h3>Step 8: Create a Table</h3><pre>CREATE TABLE students (<br>    id INT AUTO_INCREMENT PRIMARY KEY,<br>    name VARCHAR(100),<br>    email VARCHAR(100),<br>    age INT<br>);</pre><p>Check available tables:</p><pre>SHOW TABLES;</pre><p>View the table structure:</p><pre>DESC students;</pre><h3>Step 9: Insert Data</h3><pre>INSERT INTO students (name, email, age)<br>VALUES<br>(&#39;Om&#39;, &#39;om@example.com&#39;, 22),<br>(&#39;Sita&#39;, &#39;sita@example.com&#39;, 20);</pre><h3>Step 10: Retrieve Data</h3><p>Display all records:</p><pre>SELECT * FROM students;</pre><p>Retrieve selected columns:</p><pre>SELECT name, age FROM students;</pre><h3>Step 11: Update Data</h3><pre>UPDATE students<br>SET age = 23<br>WHERE id = 1;</pre><p>Always use a WHERE clause unless you intend to update every row.</p><h3>Step 12: Delete Data</h3><p>Delete a specific record:</p><pre>DELETE FROM students<br>WHERE id = 2;</pre><p>Delete all records while keeping the table:</p><pre>DELETE FROM students;</pre><h3>Step 13: Create a New MySQL User</h3><p>Instead of using the root account for applications, create dedicated users.</p><pre>CREATE USER &#39;admin&#39;@&#39;localhost&#39;<br>IDENTIFIED BY &#39;StrongPassword123!&#39;;</pre><p>Let’s break it down:</p><ul><li>CREATE USER — Creates a new MySQL account.</li><li>&#39;admin&#39; — Username.</li><li>&#39;localhost&#39; — Allows connections only from the same machine.</li><li>IDENTIFIED BY — Sets the password.</li></ul><h3>Understanding &#39;localhost&#39;</h3><pre>&#39;admin&#39;@&#39;localhost&#39;</pre><p>This account can connect only from the server running MySQL.</p><p>If you want to allow remote connections (only if necessary and secured), you can specify another host or use %:</p><pre>CREATE USER &#39;admin&#39;@&#39;%&#39;<br>IDENTIFIED BY &#39;StrongPassword123!&#39;;</pre><p>% acts as a wildcard, allowing connections from any host that meets your server&#39;s access rules.</p><h3>Step 14: Grant Database Permissions</h3><p>A newly created user has no privileges.</p><p>Grant full access to the college database:</p><pre>GRANT ALL PRIVILEGES<br>ON college.*<br>TO &#39;admin&#39;@&#39;localhost&#39;;</pre><p>Meaning:</p><ul><li>ALL PRIVILEGES — Full access.</li><li>college.* — Every table in the college database.</li><li>admin@localhost — The user receiving the permissions.</li></ul><h3>Step 15: Reload Privileges</h3><p>Apply permission changes immediately:</p><pre>FLUSH PRIVILEGES;</pre><h3>Step 16: View Existing Users</h3><pre>SELECT user, host<br>FROM mysql.user;</pre><p>Example:</p><p>UserHostrootlocalhostadminlocalhostmysql.syslocalhost</p><h3>Step 17: Back Up a Database</h3><p>Create a backup:</p><pre>mysqldump -u root -p college &gt; college_backup.sql</pre><p>Restore the backup:</p><pre>mysql -u root -p college &lt; college_backup.sql</pre><p>Backups are essential for disaster recovery and routine maintenance.</p><h3>Step 18: Check the Listening Port</h3><p>MySQL listens on port <strong>3306</strong> by default.</p><p>Verify it:</p><pre>sudo ss -tulnp | grep 3306</pre><h3>Step 19: Check Running Processes</h3><pre>ps aux | grep mysql</pre><p>This confirms that the MySQL process is active.</p><h3>Step 20: Troubleshooting</h3><p>If the service won’t start:</p><pre>sudo systemctl status mysql</pre><p>View detailed logs:</p><pre>sudo journalctl -u mysql</pre><p>Check the MySQL error log (location may vary by distribution):</p><pre>sudo cat /var/log/mysql/error.log</pre><h3>DevOps Best Practices</h3><ul><li>Keep MySQL updated with security patches.</li><li>Use dedicated database users instead of root.</li><li>Grant only the minimum required privileges.</li><li>Automate backups using cron jobs.</li><li>Monitor disk usage and database health.</li><li>Secure remote access with firewalls and strong authentication.</li><li>Store credentials securely using environment variables or a secrets manager.</li><li>Regularly test backup restoration procedures.</li></ul><h3>Summary</h3><p>In this guide, you learned how to:</p><ul><li>Install MySQL on Ubuntu</li><li>Manage the MySQL service using systemctl</li><li>Secure a new installation</li><li>Connect to the MySQL server</li><li>Create databases and tables</li><li>Perform basic CRUD operations</li><li>Create database users</li><li>Grant privileges</li><li>Back up and restore databases</li><li>Troubleshoot common issues</li><li>Apply DevOps best practices for database management</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1413106008df" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering Linux Basics: Package, Service, Process, and Memory Management on Ubuntu]]></title>
            <link>https://medium.com/@omprakashlamichhane10/mastering-linux-basics-package-service-process-and-memory-management-on-ubuntu-0541f588a136?source=rss-92d3b6df1568------2</link>
            <guid isPermaLink="false">https://medium.com/p/0541f588a136</guid>
            <dc:creator><![CDATA[Omprakashlamichhane]]></dc:creator>
            <pubDate>Thu, 23 Jul 2026 04:20:58 GMT</pubDate>
            <atom:updated>2026-07-23T04:20:58.180Z</atom:updated>
            <content:encoded><![CDATA[<p>If you’re learning Linux, preparing for DevOps interviews, or managing Ubuntu servers, you’ll quickly discover that a handful of commands are used every day. Whether you’re installing software, checking service health, monitoring system resources, or troubleshooting issues, understanding these core commands is essential.</p><p>In this article, we’ll use <strong>Nginx</strong>, a popular web server, as an example to explore the fundamentals of package management, service management, process monitoring, and memory usage on Ubuntu.</p><h3>1. Managing Software with APT</h3><p>Ubuntu uses <strong>APT (Advanced Package Tool)</strong> to install and manage software packages from its official repositories.</p><h3>Update the Package Index</h3><p>Before installing any software, it’s good practice to update the package index.</p><pre>sudo apt update</pre><p>This command refreshes the local package database, ensuring your system knows about the latest versions of available packages.</p><h3>Install Nginx</h3><p>To install the Nginx web server:</p><pre>sudo apt install nginx</pre><p>If you want to skip the confirmation prompt during installation, use:</p><pre>sudo apt install nginx -y</pre><p>The -y flag automatically answers <strong>Yes</strong> to all prompts, making it useful in scripts or automated deployments.</p><h3>View Package Information</h3><p>To see detailed information about the installed package:</p><pre>apt show nginx</pre><p>This displays useful details such as the package version, dependencies, maintainer, installation size, and a brief description.</p><h3>Check the Installed Version</h3><p>To verify the installed version of Nginx:</p><pre>nginx -v</pre><p>For more detailed build information, including compiled modules and OpenSSL version:</p><pre>nginx -V</pre><h3>Remove Nginx</h3><p>If you no longer need the package:</p><pre>sudo apt remove nginx</pre><p>This removes the software but leaves configuration files behind.</p><p>For a complete removal, including configuration files:</p><pre>sudo apt purge nginx</pre><h3>Clean Up Unused Packages</h3><p>After removing software, Ubuntu may have unnecessary dependencies left behind.</p><p>Clean them up using:</p><pre>sudo apt autoremove</pre><p>This helps keep your system clean and saves disk space.</p><h3>2. Managing Services with Systemd</h3><p>Once software is installed, it usually runs as a <strong>service</strong>. Ubuntu uses <strong>systemd</strong> to control these background services.</p><h3>Check Service Status</h3><pre>systemctl status nginx</pre><p>This command tells you whether the service is:</p><ul><li>Active</li><li>Inactive</li><li>Failed</li></ul><p>It also shows recent log entries and the service’s Process ID (PID).</p><h3>Start and Stop Services</h3><p>Start Nginx:</p><pre>sudo systemctl start nginx</pre><p>Stop Nginx:</p><pre>sudo systemctl stop nginx</pre><p>These commands are commonly used during maintenance or troubleshooting.</p><h3>Restart a Service</h3><pre>sudo systemctl restart nginx</pre><p>Restarting completely stops and starts the service again, making it useful after configuration changes.</p><h3>Reload Configuration</h3><pre>sudo systemctl reload nginx</pre><p>Reloading applies configuration changes <strong>without interrupting active connections</strong>, making it the preferred option whenever possible.</p><h3>Enable or Disable Auto Start</h3><p>Enable Nginx to start automatically whenever the system boots:</p><pre>sudo systemctl enable nginx</pre><p>Disable automatic startup:</p><pre>sudo systemctl disable nginx</pre><h3>3. Understanding Linux Processes</h3><p>Every running application in Linux is a <strong>process</strong>. Knowing how to inspect and manage processes is an important troubleshooting skill.</p><h3>View Running Processes</h3><pre>ps</pre><p>Displays processes running in the current terminal session.</p><h3>View All Processes</h3><pre>ps aux</pre><p>Shows every running process on the system along with information such as:</p><ul><li>Username</li><li>Process ID (PID)</li><li>CPU usage</li><li>Memory usage</li><li>Command</li></ul><h3>Monitor Processes in Real Time</h3><pre>top</pre><p>The top command provides a live dashboard showing:</p><ul><li>CPU usage</li><li>Memory usage</li><li>Running processes</li><li>System load</li></ul><p>Press <strong>q</strong> to exit.</p><p>Find Nginx Processes</p><pre>ps -ef | grep nginx</pre><p>This combines two commands:</p><ul><li>ps -ef lists all running processes.</li><li>grep nginx filters the output to show only Nginx-related processes.</li></ul><h3>Find Process IDs</h3><pre>pidof nginx</pre><p>Returns the Process ID (PID) of every running Nginx process.</p><p>Example:</p><pre>1524 1525</pre><h3>Terminate a Process</h3><p>To gracefully stop a process:</p><pre>sudo kill &lt;PID&gt;</pre><p>For example:</p><pre>sudo kill 1524</pre><p>If the process refuses to stop, you can forcefully terminate it:</p><pre>sudo kill -9 &lt;PID&gt;</pre><p>Although effective, kill -9 should only be used as a last resort because it doesn&#39;t allow the application to clean up before exiting.</p><h3>4. Monitoring Memory and System Resources</h3><p>Keeping an eye on memory usage helps you identify performance bottlenecks before they affect your applications.</p><h3>Check Available Memory</h3><p>Human-readable output:</p><pre>free -h</pre><p>Memory in megabytes:</p><pre>free -m</pre><p>Memory in gigabytes:</p><pre>free -g</pre><p>These commands display:</p><ul><li>Total memory</li><li>Used memory</li><li>Free memory</li><li>Buffers and cache</li><li>Swap usage</li><li>Find Memory-Intensive Processes</li></ul><pre>ps aux --sort=-%mem</pre><p>This sorts running processes by memory consumption, placing the highest memory users at the top.</p><p>It’s one of the quickest ways to identify applications consuming excessive RAM.</p><h3>View Service Logs</h3><pre>journalctl -u nginx</pre><p>Systemd stores logs for every service. This command displays the logs for the Nginx service, making it useful when troubleshooting startup failures, crashes, or configuration errors.</p><p>To watch logs in real time:</p><pre>journalctl -u nginx -f</pre><h3>Important Nginx Directories</h3><p>Understanding where Nginx stores its configuration and logs makes administration much easier.</p><p>DirectoryPurpose/etc/nginx/Main configuration directory/etc/nginx/nginx.confPrimary Nginx configuration file/etc/nginx/sites-available/Available virtual host configurations/etc/nginx/sites-enabled/Enabled virtual host configurations/var/log/nginx/access.logRecords incoming HTTP requests/var/log/nginx/error.logStores server errors and troubleshooting information</p><h3>Quick Command Reference</h3><p>TaskCommandUpdate package indexsudo apt updateInstall Nginxsudo apt install nginxRemove Nginxsudo apt remove nginxPurge Nginxsudo apt purge nginxRemove unused packagessudo apt autoremoveCheck service statussystemctl status nginxStart servicesudo systemctl start nginxStop servicesudo systemctl stop nginxRestart servicesudo systemctl restart nginxReload servicesudo systemctl reload nginxEnable servicesudo systemctl enable nginxDisable servicesudo systemctl disable nginxView processesps auxReal-time monitoringtopFind Nginx processesps -ef | grep nginxFind Nginx PIDpidof nginxKill processsudo kill &lt;PID&gt;Force kill processsudo kill -9 &lt;PID&gt;Check memoryfree -hTop memory consumersps aux --sort=-%memView logsjournalctl -u nginx</p><h3>Conclusion</h3><p>Linux administration doesn’t have to be overwhelming. By mastering a small set of commands, you can confidently install software, manage services, inspect running processes, monitor memory usage, and troubleshoot common server issues.</p><p>These commands are used daily by Linux administrators, DevOps engineers, cloud professionals, and backend developers. The best way to learn them is through hands-on practice — install Ubuntu in a virtual machine, deploy Nginx, and experiment with each command until it becomes second nature.</p><p>The Linux command line may seem intimidating at first, but with consistent practice, it becomes one of the most powerful tools in your technical skill set.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0541f588a136" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>