Docker Installation of Symfony: Quick Guide to Setting Up a Development Environment
Symfony is a popular PHP framework that provides a fast, reliable and scalable way to Build web applications. With the popularity of Symfony, many developers hope to quickly build a Symfony development environment. In this article, we will introduce how to use Docker to quickly install Symfony and provide specific code examples.
Prerequisites:
Before you begin, you need to install Docker and Docker Compose. You can download and install them from the official website. Please refer to the official documentation for the specific installation process.
docker run --rm -v $(pwd):/app composer create-project symfony/website-skeleton myproject
This command will use Composer to create a Symfony project named "myproject".
version: '3.7' services: webserver: image: nginx:alpine ports: - 80:80 volumes: - ./myproject/public:/var/www/html depends_on: - php php: build: context: . dockerfile: Dockerfile volumes: - ./myproject:/var/www/html
This configuration file defines two Docker services: webserver and php. The webserver service uses the Nginx image, maps port 80 of the host to port 80 of the container, and mounts the public folder of the Symfony project to the /var/www/html directory of the container. The php service will use the Dockerfile we will create later.
FROM php:7.4-fpm RUN apt-get update && apt-get install -y git unzip libpq-dev RUN docker-php-ext-install pdo pdo_pgsql WORKDIR /var/www/html CMD ["php-fpm"] EXPOSE 9000
This Dockerfile defines the image required for our php service and installs some commonly used software packages and extensions.
docker-compose up -d
This command will be based on docker-compose Configuration in .yml file to build and start Docker containers. Please make sure you have run this command in the root directory of your Symfony project.
docker exec -it myproject_php_1 composer require symfony/orm-pack docker exec -it myproject_php_1 composer require symfony/maker-bundle --dev
This command will install these components and extensions in the running php container.
Summary:
By using Docker, you can quickly and easily build a Symfony development environment. Through the above steps, we created a Docker container containing the Symfony project and related services. You can further customize this environment according to your project needs and easily share it with team members.
I hope this article can help you quickly set up a Symfony development environment and speed up your development process. I wish you success in developing web applications using the Symfony framework!
The above is the detailed content of Docker installation of Symfony: Quick guide to setting up a development environment. For more information, please follow other related articles on the PHP Chinese website!