To setup PHP in Docker, you can follow the steps below:
- Create a Dockerfile in your project directory:
lessCopy codeFROM php:7.4-apache
COPY . /var/www/html/
This Dockerfile uses the official PHP image with Apache and copies your project files to the container.
- Build the Docker image:
perlCopy codedocker build -t my-php-app .
This command builds a Docker image using the Dockerfile in the current directory and tags it with the name “my-php-app”.
- Run the Docker container:
arduinoCopy codedocker run -p 80:80 my-php-app
This command starts a Docker container based on the “my-php-app” image and maps port 80 on the host to port 80 in the container.
You can now access your PHP application by visiting http://localhost/ in your web browser.
Note: You may need to install additional PHP extensions in your Dockerfile depending on your application’s requirements.