Renewing DHCP Lease from Ubuntu 24.04 Server

Just found out that Ubuntu 24.04 server doesn’t use dhclient anymore and uses dhcpcd instead for obtaining dhcp address leases.

To renew your dhcp address, do the following:

sudo dhcpcd -k
sudo dhcpcd

That’s it, Enjoy!

Sources:

https://askubuntu.com/questions/1511816/how-to-renew-ip-address-with-ubuntu-24-04

Posted in Linux | Tagged , , , | Leave a comment

Docker file & compose for phpBB3

I needed a local instance to play around with phpBB, which I couldn’t find recent docker files for, so I just created my own. The below are the docker-compose.yml and Dockerfile for the latest version of phpBB as of now; 3.3.14.

Note: Make sure to change the variables inside the environment section in the docker-compose.yml file before installation.

Dockerfile

# Use the official PHP image with Apache
FROM php:8.2-apache 

# Install required PHP extensions and dependencies
RUN apt-get update && apt-get install -y \
    wget \
    mariadb-client \
    unzip \
    && docker-php-ext-install mysqli pdo pdo_mysql \
    && docker-php-ext-enable mysqli pdo pdo_mysql \
    && apt-get clean && rm -rf /var/lib/apt/lists/*

# Enable Apache modules
RUN a2enmod rewrite

# Set working directory
WORKDIR /var/www/html

# Download and extract phpBB
RUN wget https://download.phpbb.com/pub/release/3.3/3.3.14/phpBB-3.3.14.zip && \
    unzip phpBB-3.3.14.zip && \
    mv phpBB3 phpbb && \
    rm -rf phpBB-3.3.14.zip

# Set permissions
RUN chown -R www-data:www-data /var/www/html/phpbb && \
    chmod -R 755 /var/www/html/phpbb

# Expose Apache port
EXPOSE 80

CMD ["apache2-foreground"]

docker-compose.yml

services:
  phpbb:
    build: .
    container_name: phpbb
    restart: unless-stopped
    ports:
      - "8080:80"
    volumes:
      - phpbb-data:/var/www/html/phpbb
    depends_on:
      - mariadb
    environment:
      - MYSQL_HOST=mymariadb_host
      - MYSQL_USER=myphpbb_mymariadb_user
      - MYSQL_PASSWORD=MySuperStrongPassword12345
      - MYSQL_DATABASE=myphpbb_db

  mariadb:
    image: mariadb:10.11
    container_name: phpbb-mariadb
    restart: unless-stopped
    environment:
      MYSQL_ROOT_PASSWORD: rootpassword
      MYSQL_DATABASE: myphpbb_db
      MYSQL_USER: myphpbb_mymariadb_user
      MYSQL_PASSWORD: MySuperStrongPassword12345
    volumes:
      - db-data:/var/lib/mysql

volumes:
  phpbb-data:
  db-data:

Let’s get to action!

  • To build and start: docker-compose up -d --build
  • Access the installation at http://localhost:8080/phpbb/install and enter the parameters inside the first environment section in the docker-compose.yml file
  • After installation is complete from the above link, you have to run docker exec -it phpbb rm -rf /var/www/html/phpbb/install
  • To wipe it and start all over: docker-compose down -v

I’ve made these file also available on my GitHub repo here: https://github.com/ahmedatawfik/usefulscripts/tree/main/docker/phpBB

That’s it, Enjoy!

References:

Posted in docker, Linux | Tagged , , , , , | 2 Comments

If WSLg apps show a black screen!

You might have rendering issues with WSLg apps, especially in case you are using an Intel graphics card, like this:

In that case, just configure an environment variable named LIBGL_ALWAYS_SOFTWARE and set it to 1. To persist it, add this line inside /etc/profile:

export LIBGL_ALWAYS_SOFTWARE=1

Just restart (using wsl --shutdown for example).

Note: This will disable GPU acceleration for those GUI apps, which I don’t really care about in this case!

Tested on Windows 11 Pro host with Ubuntu 24.04 WSL guest.

That’s it, Enjoy!

Sources:

Posted in Linux | Tagged , , , | Leave a comment

Simple Python Script to Communicate with ChatGPT API

I wrote a simple python script that allows you to communicate with the ChatGPT API, the workflow is as straight-forward as this:

  • You read the prompt from a file
  • Send the prompt to the model of your choice
  • Receive the response and write it to a file

Prerequisites:

  • Python (obviously :D), I used Python 3.12
  • The openai python bindings (pip install openai)
  • OpenAI subscription with at least a few cents there!

Limitations:

  • Only single prompt and response
  • No exception handling, too lazy to write it now!

Here is the code in its simplest form: https://github.com/ahmedatawfik/usefulscripts/blob/main/chatgptcomm.py

import openai

# This is a dummy key, replace with your actual OpenAI API key
openai.api_key = "9i-wmcxtsO-VuDJlPsbRlR9sqWfdLphxFEedbFIyw3MFHlcbtcTapxj6v4CfwmEtarZQWJ0ieEJXSCBHOEM5LP6m-Kd1KVfvuOKPBP8MAeVlvXQsudk8"

# Function to read the prompt from prompt.txt
def read_prompt_from_file(file_path):
    with open(file_path, 'r', encoding='utf-8') as file:
        prompt = file.read()
    return prompt

# Function to write the response to response.txt
def write_response_to_file(file_path, response):
    with open(file_path, 'w', encoding='utf-8') as file:
        file.write(response)

# Function to get response from ChatGPT
def get_chatgpt_response(prompt):
    response = openai.chat.completions.create(
        model="gpt-4o",
        messages=[
            {"role": "system", "content": "You are a helpful assistant who provides cool answers!"},
            {"role": "user", "content": prompt}
        ]
    )
    return response.choices[0].message.content.strip()

# Main function to read, get response, and write
def main():
    prompt = read_prompt_from_file(r"/home/user/prompt.txt")
    response = get_chatgpt_response(prompt)
    write_response_to_file(r"/home/user/response.txt", response)
    print("Response has been written to response.txt")

if __name__ == "__main__":
    main()

That’s it, Enjoy!

Sources:

Posted in python | Tagged , , , | Leave a comment

List all files and first level directories arranged by size on Linux

du -sh * | sort -hr

Where:

  • du -sh: Shows the sizes of files and directories in a human-readable format
  • sort -hr: Sorts the output by size in human format, with the largest items at the top.

Sample:

That’s it, Enjoy!

Posted in Linux | Tagged , | Leave a comment