megacolorboy

Abdush Shakoor's Weblog

Writings, experiments & ideas.

Trying out the Redragon K552 Kumara RGB Mechanical Keyboard

My experiences using a mechanical keyboard for the first time.

Redragon K552 Kumara RGB Keyboard

Yes, I finally did it and bought myself a mechanical keyboard after tirelessly scrolling through Amazon and YouTube for a good keyboard that doesn't hurt my pocket in the long run.

What does it feel like?

Got it delivered yesterday and as I unboxed it, I noticed that the build quality is strong and it's quite a heavy keyboard that has around 18 RGB modes to spice things up a bit.

I got the one with the Outemu Red Switches (More like a Cherry MX Red clones) and since it's a linear switch, the typing experience is buttery smooth and not at all noisy. This should be good for typing in office environments or gamers who like to be fast while playing their favorite games.

Currently, I have one issue with it i.e. that keyboard is a bit high and it kind of tires my wrists after typing for longer sessions but I guess, it can be fixed with a wrist rest (Maybe, a nice wooden one 👀).

On my first try, the keys seemed a bit fast for me as I'm not really used to typing on linear switches, let alone, on a mechanical keyboard. But as of writing this article, I got my speed back up and I have been able to achieve around 75-80WPM.

Conclusion

Apart from that, I'm quite happy about this purchase and would definitely hope that it lasts longer until I get another mechanical keyboard.

If you are looking to buy this keyboard, I'd recommend you to give a shot and see it for yourself because I feel that every programmer deserves to type on a good keyboard.

Stay tuned for more content.

Learning C# 10 and .NET Core 6

Getting back into the old roots again.

To those who haven't been following me a lot, I used to build games on Unity 3D and build desktop applications on .NET and C# during my university days.

Ever since I discovered PHP and Laravel, I never went back to .NET and now after taking a look at the Fortune benchmarks for .NET Core 6 vs Laravel, I decided to take some time out to learn it again.

I started two weeks ago and the learning curve seemed quite familiar due to previous development experiences. I don't know if it's me but I felt like Laravel might have borrowed a few concepts from .NET Core Framework but hey, everyone needs some sort of inspiration, right?

Unlike .NET, Laravel is usually and still is a "batteries included" type of framework and that helps you get the job done. However, from what I have researched, applications built on .NET seems to be more performant than applications built on Laravel.

So, what's the current progress?

Well, I haven't touched the ASP.MVC part yet as I'm geting myself familiar with the coding conventions, static typing (yes, it does take sometime to get used to) by writing some test console-based applications and solving Project Euler problems.

Hopefully, I'll be able to share about what I have learnt using the framework on this blog by either building new applications or rewriting some of my Laravel projects.

Stay tuned for more!

Temporarily disable IPV6 protocol on Ubuntu

Few days ago, I resolved an issue that I faced on an Ubuntu server that was related to SMTP not working, as a result, the server was always throwing a 504 Gateway Timeout error.

During troubleshooting, I found out that telnet smtp.office365.com 587 was not giving any response and thought that the port was blocked on the client's network but no, it wasn't.

I did a little digging and learnt that it could be due to the fact that SMTP traffic over IPV6 might be blocked on the client's network.

So, I tried executing the following commands to disable IPV6 temporarily:

sudo sysctl -w net.ipv6.conf.all.disable_ipv6=1
sudo sysctl -w net.ipv6.conf.default.disable_ipv6=1

And voila, the mails were going and SMTP traffic was working over IPV4.

If you want to enable it again, try the following:

sudo sysctl -w net.ipv6.conf.all.disable_ipv6=0
sudo sysctl -w net.ipv6.conf.default.disable_ipv6=0

Hope you found this tip useful!

View list of services in Linux

If you wanted to see a list of services available on your Linux server/desktop, try the following command:

systemctl list-unit-files --type=service

Upon executing this command, you'll be able to see a list of services along with their statuses i.e whether the service is enabled or disabled.

This can come in handy if you want to know the status of a specific service like nginx:

systemctl list-unit-files --type=service | grep "nginx"

Hope you found this tip useful.

Containerize your Laravel application for Development

A short tutorial on how to containerize your Laravel application and use it for testing and development purposes.

Since I started exploring Docker containers during my spare time, I learnt how to containerize a Laravel application using Docker Compose.

In this guide, I'll show you how to containerize your application and by the end of this tutorial, you'll have your application running on four separate service containers:

  • App service running php7.4-fpm.
  • A database service running mysql-80.
  • An NGINX service.
  • A phpMyAdmin service for you to view and manage your database.

Prerequisites

  • You need to have Docker and Docker Compose installed on your system
  • A non-root user with sudo privileges (If you are using any UNIX-based environment).
  • An existing working Laravel project.

I tried this on my personal laptop that runs on Fedora Workstation 36 and hopefully, it should work on Windows and macOS as well. If you are a Windows user, I would recommend you to try WSL2 with Ubuntu installed in it.

Configure your app service

First, you need to create a Dockerfile for your app service in your project's root directory:

touch Dockerfile
vim Dockerfile

In this tutorial, I'll be using PHP7.4 but you can use any version that you need. Here you go:

FROM php:7.4-fpm

# Arguments defined in docker-compose.yml
ARG user
ARG uid 

# Install system dependencies
RUN apt-get update && apt-get install -y \
    git \
    curl \
    libpng-dev \
    libonig-dev \
    libxml2-dev \
    zip \
    unzip

# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*

# Install PHP extensions
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd

# Get latest Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

# Create system user to run Composer and Artisan Commands
RUN useradd -G www-data,root -u $uid -d /home/$user $user
RUN mkdir -p /home/$user/.composer && \
    chown -R $user:$user /home/$user

# Set working directory
WORKDIR /var/www

USER $user

So, what's happening in the configuration above is that, it pulls a PHP7.4-FPM image from Docker Hub. Next, it'll define the user of the service and install all the necessary dependencies that are given above and set the working directory to /var/www/. The last step will change to the newly created user, which would make sure that you are using the service as a normal user.

Again, if you are a bit playful, try configuring it to however you want it and see if it works.

Set up NGINX and MySQL

I have been following some tutorials and I liked the idea of creating dedicated directories to organize your files related to configuring each service container.

Create a directory named .docker in your project's root directory:

mkdir -p .docker

NGINX

Go to .docker directory and create nginx directory:

mkdir -p nginx

Now let's set up the NGINX service by creating a .conf file:

touch myservice.conf

Now, copy the following configuration to your .conf file:

server {
    listen 80;
    index index.php index.html;
    error_log  /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;
    root /var/www/public;
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass app:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
    location / {
        try_files $uri $uri/ /index.php?$query_string;
        gzip_static on;
    }
}

MySQL

Since this is a Laravel application, you can skip this step by running migrations and seeding your database or you can try creating a directory inside the .docker folder to store your MySQL related configuration:

mkdir -p mysql

Once created, create a file named init_db.sql that would contain your entire database dump to be seeded once you run your docker service.

Set up multiple containers using Docker Compose

This the configuration I have used to create four separate services, please take a look and feel free to modify it based on your requirements.

In this configuration, all services will share a bridge network named yourapp which is defined at the bottom of this configuration.

Here is the configuration:

version: '3.8'
services:
  # PHP Service
  app:
    build:
      args:
        user: username
        uid: 1000
      context: ./
      dockerfile: Dockerfile
    image: yourapp 
    container_name: yourapp-app
    restart: unless-stopped
    working_dir: /var/www/
    volumes:
      - ./:/var/www
    networks:
      - yourapp

  # MySQL Service
  db: 
    image: mysql:8.0
    container_name: yourapp-db
    restart: unless-stopped
    environment:
      MYSQL_DATABASE: ${DB_DATABASE}
      MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
      MYSQL_PASSWORD: ${DB_PASSWORD}
      MYSQL_USER: ${DB_USERNAME}
      SERVICE_TAGS: dev 
      SERVICE_NAME: mysql
    volumes:
      - ./.docker/mysql:/docker-entrypoint-initdb.d
    healthcheck:
      test: mysqladmin ping -h 127.0.0.1 -u ${DB_USERNAME} --password=${DB_PASSWORD}
      interval: 5s
      retries: 10
    networks:
      - yourapp

  # NGINX Service
  nginx:
    image: nginx:alpine
    container_name: yourapp-nginx
    restart: unless-stopped
    ports:
      - 8000:80
    volumes:
      - ./:/var/www
      - ./.docker/nginx:/etc/nginx/conf.d/
    networks:
      - yourapp

  # phpMyAdmin service
  phpmyadmin:
    image: phpmyadmin/phpmyadmin:5
    ports:
      - 8080:80
    environment:
      PMA_HOST: db
    depends_on:
      db: 
        condition: service_healthy
    networks:
      - yourapp

networks:
  yourapp:
    driver: bridge

Configure your application

Open your current .env file of your laravel project and just add the necessary database configuration:

DB_HOST=yourapp-db
DB_PORT=3306
DB_DATABASE=your_database_name
DB_USERNAME=your_database_user_name
DB_PASSWORD=your_database_password

Build the application image

After you are done with configuring, run the following command to build your application image:

docker-compose build yourapp

Depending on your network speed, it might take a few minutes to build your image.

Run the application

Once the build is complete, execute the following command:

docker-compose up -d

The following command will run your containers in the background. To display your information about the state of your docker services:

docker-compose ps

Install your application's dependencies:

docker-compose exec yourapp rm -rf vendor composer.lock
docker-compose exec yourapp composer install

And then run the following commands to run your Laravel application:

docker-compose exec yourapp php artisan key:generate
docker-compose exec yourapp php artisan config:clear
docker-compose exec yourapp php artisan cache:clear
docker-compose exec yourapp php artisan view:clear
docker-compose exec yourapp php artisan route:clear
docker-compose exec yourapp php artisan storage:link 

Now, you can go to your browser, type your http://localhost:8000 to access your application.

Conclusion

If you've come to this part, give yourself a pat in the back!

From now onwards, you don't really need to install and set up a local web server and database to run and test your application.

Furthermore, you'll be having a disposable environment in your hand, which means you can easily replicate and distribute it to other developers in your team, so that no one says "It works on my machine and not on yours!"

Hope you liked this tutorial!

8th October 2022 — Blogmarks

Install Docker on Fedora 35/36

Recently, I started to play around with Docker and I thought of installing on my personal laptop which runs Fedora 36 workstation.

If you have Fedora and want to know how to install it, here it is:

Install Docker Engine

First, add the official Docker repositories to your Fedora OS:

sudo dnf install dnf-plugins-core -y
sudo dnf config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo

Then, you can run the following command to install Docker and it's dependencies:

sudo dnf install docker-ce docker-ce-cli containerd.io

During installation, you'll be prompted to import the GPG key in order to install Docker on your system. So, press Y to proceed with the installation.

Next, enable and start the docker service:

sudo systemctl enable docker
sudo systemctl start docker

That's it you are done. You can try running the following command to see if it's installed properly on your system:

sudo docker run hello-world

If it works fine, you should be seeing a "Hello from Docker!" message which means that the installation appears to be working fine.

Hope you found this tutorial useful!

Resolve permission error while SSH-ing to AWS EC2 instance from a Linux machine

If you are someone who's trying to access a AWS EC2 instance via SSH using a private key from a linux machine, you might have or will come across this error:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0644 for 'your-aws-private-key.pem' are too open.
It is recommended that your private key files are NOT accessible by others.
This private key will be ignored.
bad permissions: ignore key: your-aws-private-key.pem
Permission denied (publickey).

Why am I getting this?

From what I have read, EC2 instances will simply not accept a private key that are publicly visible to others especially if it's somewhere stored in your Desktop or Downloads folder.

So basically, your private key should be accessible to others.

Oh, how can I fix it?

It's pretty straightforward, you just have to make sure that the private key is read-only like this:

chmod 400 your-aws-private-key.pem

After that, try connecting again and it should work fine!

Hope you found this tip useful!