-
Notifications
You must be signed in to change notification settings - Fork 8
Install Symfony with Dockerizer
Maksym Zaporozhets edited this page Jun 15, 2023
·
1 revision
The below information is relevant to any other application or framework, not only Symfony or PHP-based ones.
The instruction below describes installing an application inside the running Docker container. Only in this case you will get the correct dependencies tree and software checks. Installing the application on the host machine does not work as you may have different PHP (or other software) versions on the host and inside the container, various libraries, environment variables, etc.
Since the project must be initialized inside the running container, you must first create and spin up the environment:
- Create a project directory
- Generate composition with the Dockerizer tool or use another way to generate and run the environment
- Enter the PHP (or another container)
- Create some empty directory
- Run
composer:create-project
(or another relevant command to initialize your project) - Move files to the project root directory or other directory you need;
- Adjust web root and re-run composition if required.
Below is an example of installing a Symfony web application.
cd ${DOCKERIZER_PROJECTS_ROOT_DIR}
mkdir symfony_demo
cd ./symfony_demo/
# We need a running environment to initialize the project. Let's create it with Dockerizer!
# Apache logs are stored to the `<project_root>/var/log/` directory inside the container.
# Web root for symfony app is `<project_root>/public/`. Check you app or framework documentation for details.
mkdir -p ./var/log/ ./public/
php "${DOCKERIZER_PROJECTS_ROOT_DIR}dockerizer_for_php/bin/dockerizer" \
composition:build-from-template \
--template='generic_php_apache_app' \
--required-services='php_8_1_apache' \
--optional-services='mysql_8_0_persistent' \
--domains='symfony-demo.local www.symfony-demo.local' \
--with-web_root='public'
# Let's run composition
cd .dockerizer/symfony-demo.local-prod/
docker-compose -f docker-compose.yaml -f docker-compose-dev-tools.yaml up -d --force-recreate
# And enter the PHP container
docker exec -it symfony-demo.local-prod bash
# We're now in the `/var/www/html` directory inside the PHP container, which is the WORKDIR for the `php_8_1_apache` service.
# Product root already container `.dockerizer/`, `var/log/` and `public/` directories.
# We can either temporary remove them or install the app into some other directory.
# I prefer the second option. It is more complex but is much, much safer for a number of reasons.
# Thus, let's install the app to the `/var/www/html/my_project_directory` directory.
composer create-project symfony/skeleton:"6.1.*" my_project_directory
# Move files to the project root directory or other directory you need...
cp -r ./my_project_directory/var/ ./
rm -rf ./my_project_directory/var/
mv -f ./my_project_directory/* ./
# Move hidden files as well...
mv -f ./my_project_directory/.* ./
rm -rf ./my_project_directory/
# Add web skeleton packages...
composer require webapp
# Add basic .htaccess file...
echo 'RewriteEngine ON
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/1$ [NC,L,QSA]' > ./public/.htaccess
Open URL: https://symfony-demo.local/ and check the Symfony welcome page!
- docker:mysql:connect
- docker:mysql:export-db
- docker:mysql:import-db
- docker:mysql:upload-to-aws
- docker:mysql:generate-metadata
- docker:mysql:reconstruct-db
- docker:mysql:test-metadata
- magento:setup
- magento:reinstall
- magento:test-module-install
- magento:test-templates
- magento:test-dockerfiles
- MacOS and Docker Desktop support
- Bash aliases
- Install Symfony with Dockerizer
- Running-apps-with-existing-Docker-compositions
- Limitations
- Building MySQL images with DB: how it works
- Configure AWS Lambda
- Gitlab pipeline to build images
- Managing AWS S3 access
- Using AWS credentials with Dockerizer
- Access management cheat-sheet
- FAQ