John Davidson

Use docker for different PHP versions in separate directories

0 comments
Message:


I Dedicated Server on Godaddy.com which give me access to both WHM & cPanel let's say i created an account for domain example.com in this domain there is two directories Attendance which contain CodeIgniter required php 7.2 & Prize which contain Laravel required php 8.1. Can i use Docker to setup those directories properly and assign php version to each one ?



My Answer:
and cPanel. Here is how you can use Docker to run different PHP versions in separate directories on your dedicated server:

1. Install Docker on your server by following the official Docker installation guide for your operating system.

2. Create a new directory for each PHP version you want to run. For example, you can create directories named php7.2, php7.3, php7.4, etc.

3. Inside each directory, create a Dockerfile with the following content:


FROM php:7.2


Replace `7.2` with the desired PHP version for that directory.

4. Build the Docker image by running the following command inside each directory:


docker build -t php7.2 .


Replace `php7.2` with a unique name for each PHP version.

5. Run the Docker container for each PHP version by running the following command inside each directory:


docker run -d --name php7.2 -p 8000:80 php7.2


Replace `php7.2` with the name of the Docker image you built in step 4.

6. Access the PHP version running in each directory by visiting `http://your-server-ip:8000` in your web browser. Replace `your-server-ip` with the IP address of your server.

By following these steps, you can run different PHP versions in separate directories on your dedicated server using Docker. This allows you to easily switch between PHP versions for different projects without affecting other projects running on the server.

Rate this post

4 of 5 based on 4681 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us