Run multiple PHP versions of Applications in the docker

Step 1: Project Structure

Create a directory structure that separates each Laravel application:

laravel-docker/
│
├── app1/                     # Laravel App 1 using PHP 7.4
│   ├── laravel/              # Laravel application files
│
├── app2/                     # Laravel App 2 using PHP 8.0
│   ├── laravel/              # Laravel application files
│
├── app3/                     # Laravel App 3 using PHP 8.1
│   ├── laravel/              # Laravel application files
│
├── docker/
│   ├── php7.4/               # PHP 7.4 Docker configuration
│   │   └── Dockerfile
│   │
│   ├── php8.0/               # PHP 8.0 Docker configuration
│   │   └── Dockerfile
│   │
│   ├── php8.1/               # PHP 8.1 Docker configuration
│   │   └── Dockerfile
│
└── docker-compose.yml        # Docker Compose configuration file

Step 2: Install Nginx on Your Host Machine

Install Nginx on your local machine using the appropriate command based on your operating system:

  • Ubuntu/Debian: sudo apt update sudo apt install nginx
  • CentOS/RHEL: sudo yum install epel-release sudo yum install nginx
  • MacOS (Homebrew): brew install nginx

Step 3: Configure Nginx

Edit the Nginx configuration file to connect with PHP running inside Docker containers. Create a server block in Nginx to point to the Dockerized PHP service.

Nginx Configuration (/etc/nginx/sites-available/laravel):

# Configuration for App 1 using PHP 7.4
server {
    listen 80;
    server_name app1.localhost;
    root /path/to/app1/laravel/public;

    index index.php index.html index.htm;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_pass 127.0.0.1:9001;  # PHP 7.4
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

    location ~ /\.ht {
        deny all;
    }
}

# Configuration for App 2 using PHP 8.0
server {
    listen 80;
    server_name app2.localhost;
    root /path/to/app2/laravel/public;

    index index.php index.html index.htm;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_pass 127.0.0.1:9002;  # PHP 8.0
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

    location ~ /\.ht {
        deny all;
    }
}

# Configuration for App 3 using PHP 8.1
server {
    listen 80;
    server_name app3.localhost;
    root /path/to/app3/laravel/public;

    index index.php index.html index.htm;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_pass 127.0.0.1:9003;  # PHP 8.1
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

    location ~ /\.ht {
        deny all;
    }
}

Enable the configuration:

sudo ln -s /etc/nginx/sites-available/laravel /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx

Step 4: Create a Separate Docker Compose File for MySQL

Create a docker-compose.db.yml file dedicated to MySQL.

docker-compose.db.yml (For MySQL Service)

version: '3.8'

services:
  # MySQL Service (shared by all apps)
  mysql:
    image: mysql:5.7
    container_name: mysql
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: laravel
      MYSQL_USER: laravel
      MYSQL_PASSWORD: secret
    volumes:
      - db_data:/var/lib/mysql
    ports:
      - "3306:3306" # Expose MySQL port for connections from apps

volumes:
  db_data:

Step 5: Configure Individual Docker Compose Files for Each App

Modify the docker-compose files for each application to remove the MySQL service and connect them to the shared MySQL container.

docker-compose.app1.yml (For App 1 – PHP 7.4)

version: '3.8'

services:
  # PHP 7.4 Service for App 1
  php7.4:
    build:
      context: ./docker/php7.4
    container_name: php7.4
    volumes:
      - ./app1/laravel:/var/www/html
    ports:
      - "9001:9000" # Mapping port for PHP 7.4
    depends_on:
      - mysql # Ensure the PHP service waits for MySQL to be ready
    networks:
      - shared-network

networks:
  shared-network:
    external: true

docker-compose.app2.yml (For App 2 – PHP 8.0)

version: '3.8'

services:
  # PHP 8.0 Service for App 2
  php8.0:
    build:
      context: ./docker/php8.0
    container_name: php8.0
    volumes:
      - ./app2/laravel:/var/www/html
    ports:
      - "9002:9000" # Mapping port for PHP 8.0
    depends_on:
      - mysql # Ensure the PHP service waits for MySQL to be ready
    networks:
      - shared-network

networks:
  shared-network:
    external: true

docker-compose.app3.yml (For App 3 – PHP 8.1)

version: '3.8'

services:
  # PHP 8.1 Service for App 3
  php8.1:
    build:
      context: ./docker/php8.1
    container_name: php8.1
    volumes:
      - ./app3/laravel:/var/www/html
    ports:
      - "9003:9000" # Mapping port for PHP 8.1
    depends_on:
      - mysql # Ensure the PHP service waits for MySQL to be ready
    networks:
      - shared-network

networks:
  shared-network:
    external: true

Step 6: Create the Shared Network

To allow the services in different Docker Compose files to communicate, create an external Docker network named shared-network. This network will connect the MySQL container with the PHP containers across different Compose files.

Create the shared network using the following command:

docker network create shared-network

Step 7: Update Laravel Environment Configuration

In each Laravel application’s .env file, configure the database connection to use the shared MySQL service. Set the DB_HOST to mysql (the name of the MySQL service as defined in docker-compose.db.yml).

Example .env Configuration for Each App:

DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=laravel
DB_PASSWORD=secret

Step 8: Start the MySQL Container

First, bring up the MySQL service using its separate Docker Compose file:

docker-compose -f docker-compose.db.yml up -d

Step 9: Start Each Application

Start each Laravel application using its respective Docker Compose file:

  1. Start App 1 (PHP 7.4):docker-compose -f docker-compose.app1.yml up -d
  2. Start App 2 (PHP 8.0):docker-compose -f docker-compose.app2.yml up -d
  3. Start App 3 (PHP 8.1):docker-compose -f docker-compose.app3.yml up -d

Access Your Applications

Summary

This setup effectively decouples the MySQL service into a separate container while allowing multiple Laravel applications to connect seamlessly. It simplifies database management and provides a scalable architecture where you can adjust each Laravel environment independently without affecting the shared database service. Let me know if you need further adjustments or assistance!

Google offers 100+ free courses for programming. Here are my top 10.



1. Crash Course on Python:
https://lnkd.in/gCUuqF-r

2. Introduction to Git and GitHub:
https://lnkd.in/g5hYh26Q

3. Troubleshooting and Debugging Techniques:
https://lnkd.in/g7RhuGg6

4. Tools of the Trade – Linux and SQL:
https://lnkd.in/gK-RD9Bd

5. Master Data Structures and Algorithms:
https://lnkd.in/gncfrj8u

6. Android Development for Beginners:
https://lnkd.in/gWT5nVNq

7. Firebase in a weekend:
https://lnkd.in/gw86vaei

8. Machine Learning Crash Course:
https://lnkd.in/gTX-AG28

9. Foundations of Cybersecurity:
https://lnkd.in/gVndvGgn

10. Introduction to Generative AI:
https://lnkd.in/gWuebErQ

Digital Marketing

Digital Marketing Agency: What Makes Them Effective?

Digital marketing agencies play a big part in helping particular brands and businesses make their mark online. Without the help of digital marketing, it would be delicate for a business to achieve its full potential- in terms of client reach, applicability in assiduity, and branding.

Brands don’t grow overnight. They bear marketing and advertising to establish their presence in the assiduity.


Growing Your Brand with Effective Digital Marketing Agencies

analogous to traditional marketing strategies resulting from juggernauts from digital agencies can be dramatic. Blogging can bring in 67 further leads compared to brands that choose not to do so. Conversion rates are also advanced through online marketing sweats compared to traditional advertising juggernauts.


Effective Digital Marketing Agencies are Adaptive

utmost brands invest in digital marketing agencies looking for immediate results. After all, they’re paying for similar services to upgrade their lead generation and brand recognition. still, a truly effective digital marketing agency doesn’t only deliver quickly, they can also deliver consequently indeed during changes in the marketing context.
A responsible agency will incontinently acclimate their marketing juggernauts and inform their guests during significant changes in the digital marketing climate. They continuously test their own hypotheticals and give high value to their guests, helping them get ahead of the competition.

Search Engine OPtimization

Search Engine Optimization Guide

though, the first time, If you have SEO on your mind and are looking for an SEO professional also it’s important to assure that you get the correct result. Like any service inquiry, you should

a) communicate easily what you need and

b) assure that you understand what services are being offered, and what the awaited results are going to be for the price.

In short, you should make sure that both parties have the same expectations.” Website top of Google” is a vague comment to be made by either yourself or your supplier.” To rank on the first page of the Google quest results for( phrase X)” is much better it’s really clear and can form an excellent point for the SEO work about to be accepted. But you need to be careful then too if your implicit SEO professional thresholds making guarantees about Google rankings, also that isn’t good. Google itself states that no one can guarantee rankings in the Google search results. relating the keywords for which you want your website to rank in the Google search results is essential and this list should be agreed upon by both parties. It’s easier to get a website to rank well on Google for further specific, targeted phrases(e.g.” SEO sun seacoast”) than further general phrases( similar to” SEO”). In addition to this, there are a number of specialized aspects of your website that make your website more” friendly” to Google, and easier for your SEO supplier to optimize. These are things that should be discussed and understood foregoing to getting started with the search engine optimization of your website. Then is what I recommend you consider and discuss with prospective SEO suppliers, during those vital discussion stages.

Web Design

Website Designer and Web Developer – The Difference

Suppose you want a new website, you search the Internet and you find the terms Website developer and Web designer being used, is there any difference between these two places or is it one in the same thing.

Let’s look a little deeper into the 2 tasks and examine what approach to the Website structure Process they take.


A Website Designers Approach
A Website Designer communicates the visual aspect of what may be needed by a customer in a visually attractive way by making use his creativity and expertise. In simple terms, he’s capable to turn words into a graphical model doing so in a creative and skillful manner.

To help him do this, he’ll make use of certain software s and tools similar to Adobe Photoshop, Illustrator and InDesign. still, he doesn’t do this in an arbitrary erratic way, he follows a set of Design Principles so to get the best results possible.

In principle, every website design always has a heading, a body, and a footer. This is the beginning structure of every website. The Website Designer will design images( or acquire them) and text and arrange this in a creative manner, always keeping in mind the stated objective.