- Saved searches
- Use saved searches to filter your results more quickly
- License
- yiisoft/yii2-docker
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.md
- About
- Installation ¶
- Installing using Composer ¶
- Install from an Archive File ¶
- Preparing application ¶
- Installing using Vagrant ¶
- Manual for Linux/Unix users ¶
- Manual for Windows users ¶
- Installing using Docker ¶
- Yii and Docker ¶
- Requirements ¶
- Installation ¶
- Resources ¶
- Usage ¶
- Advanced topics ¶
- Yii framework tests ¶
- Database administration tools ¶
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
Official Docker images suitable for Yii 2.0
License
yiisoft/yii2-docker
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.md
This is the repo of the official Yii 2.0 Framework image on DockerHub for PHP.
These Docker images are built on top of the official PHP Docker image, they contain additional PHP extensions required to run Yii 2.0 framework, but no code of the framework itself. The Dockerfile (s) of this repository are designed to build from different PHP-versions by using build arguments.
Available versions for yiisoftware/yii2-php
The following images are built on a weekly basis for arm64 and amd64. For regular commits on master we only build images for amd64 suffixed with -latest / -latest-min .
8.2-apache-min, 8.2-fpm-min, 8.2-fpm-nginx-min 8.1-apache-min, 8.1-fpm-min, 8.1-fpm-nginx-min 8.0-apache-min, 8.0-fpm-min, 8.0-fpm-nginx-min
8.2-apache, 8.2-fpm, 8.2-fpm-nginx 8.1-apache, 8.1-fpm, 8.1-fpm-nginx 8.0-apache, 8.0-fpm, 8.0-fpm-nginx
Deprecated or EOL versions
Adjust the versions in .env if you want to build a specific version.
Note: Please make sure to use a matching combination of DOCKERFILE_FLAVOUR and PHP_BASE_IMAGE_VERSION
- PHP_ENABLE_XDEBUG whether to load an enable Xdebug, defaults to 0 (false) not available in -min images
- PHP_USER_ID (Debian only) user ID, when running commands as webserver ( www-data ), see also #15
docker-compose run --rm php php /tests/requirements.php
To enable Xdebug, set PHP_ENABLE_XDEBUG=1 in .env file
Xdebug is configured to call ip xdebug.remote_host on 9005 port (not use standard port to avoid conflicts), so you have to configure your IDE to receive connections from that ip.
More information can be found in the docs folder.
- We do not officially support Alpine images, due to numerous issues with PHP requirements and because framework tests are not passing.
- Depending on the (Debian) base-image (usually PHP <7.4) you might need to set X_LEGACY_GD_LIB=1
- test
About
Official Docker images suitable for Yii 2.0
Installation ¶
The minimum requirement by this project template is that your Web server supports PHP 5.6.0.
Installing using Composer ¶
If you do not have Composer, follow the instructions in the Installing Yii section of the definitive guide to install it.
With Composer installed, you can then install the application using the following commands:
composer create-project --prefer-dist yiisoft/yii2-app-advanced yii-application
The command installs the advanced application in a directory named yii-application . You can choose a different directory name if you want.
It uses asset-packagist for managing bower and npm package dependencies through Composer. Also you can use asset-plugin, as in earlier versions, but it works slowly.
Install from an Archive File ¶
Extract the archive file downloaded from yiiframework.com to a directory named advanced that is directly under the Web root.
Then follow the instructions given in the next subsection.
Preparing application ¶
After you install the application, you have to conduct the following steps to initialize the installed application. You only need to do these once for all.
- Open a console terminal, execute the init command and select dev as environment.
/path/to/php-bin/php /path/to/yii-application/init
/path/to/php-bin/php /path/to/yii-application/init --env=Development --overwrite=All --delete=All
- for frontend /path/to/yii-application/frontend/web/ and using the URL http://frontend.test/
- for backend /path/to/yii-application/backend/web/ and using the URL http://backend.test/
For Apache it could be the following:
ServerName frontend.test DocumentRoot "/path/to/yii-application/frontend/web/" # use mod_rewrite for pretty URL support RewriteEngine on # If a directory or a file exists, use the request directly RewriteCond % !-f RewriteCond % !-d # Otherwise forward the request to index.php RewriteRule . index.php # use index.php as index file DirectoryIndex index.php # . other settings. # Apache 2.4 Require all granted ## Apache 2.2 # Order allow,deny # Allow from all ServerName backend.test DocumentRoot "/path/to/yii-application/backend/web/" # use mod_rewrite for pretty URL support RewriteEngine on # If a directory or a file exists, use the request directly RewriteCond % !-f RewriteCond % !-d # Otherwise forward the request to index.php RewriteRule . index.php # use index.php as index file DirectoryIndex index.php # . other settings. # Apache 2.4 Require all granted ## Apache 2.2 # Order allow,deny # Allow from all
server < charset utf-8; client_max_body_size 128M; listen 80; ## listen for ipv4 #listen [::]:80 default_server ipv6only=on; ## listen for ipv6 server_name frontend.test; root /path/to/yii-application/frontend/web/; index index.php; access_log /path/to/yii-application/log/frontend-access.log; error_log /path/to/yii-application/log/frontend-error.log; location / < # Redirect everything that isn't a real file to index.php try_files $uri $uri/ /index.php$is_args$args; > # uncomment to avoid processing of calls to non-existing static files by Yii #location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ # try_files $uri =404; #> #error_page 404 /404.html; # deny accessing php files for the /assets directory location ~ ^/assets/.*\.php$ < deny all; > location ~ \.php$ < include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_pass 127.0.0.1:9000; #fastcgi_pass unix:/var/run/php5-fpm.sock; try_files $uri =404; > location ~* /\. < deny all; > > server < charset utf-8; client_max_body_size 128M; listen 80; ## listen for ipv4 #listen [::]:80 default_server ipv6only=on; ## listen for ipv6 server_name backend.test; root /path/to/yii-application/backend/web/; index index.php; access_log /path/to/yii-application/log/backend-access.log; error_log /path/to/yii-application/log/backend-error.log; location / < # Redirect everything that isn't a real file to index.php try_files $uri $uri/ /index.php$is_args$args; > # uncomment to avoid processing of calls to non-existing static files by Yii #location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ # try_files $uri =404; #> #error_page 404 /404.html; # deny accessing php files for the /assets directory location ~ ^/assets/.*\.php$ < deny all; > location ~ \.php$ < include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_pass 127.0.0.1:9000; #fastcgi_pass unix:/var/run/php5-fpm.sock; try_files $uri =404; > location ~* /\. < deny all; > >
127.0.0.1 frontend.test 127.0.0.1 backend.test
Thank you for registration. Please check your inbox for verification email.
- delete soft line breaks ‘=’ and newlines to create a single line with the line below
- change ‘=3D’ to ‘=’
- On Mac / Linux, convert \r\n to \n — MIME CRLF line breaks are «real» and should be preserved.
Paste this URL into a browser tab to complete the User creation. You will be presented with the message: Your email has been confirmed!
Note: if you want to run advanced template on a single domain so / is frontend and /admin is backend, refer to Using advanced project template at shared hosting.
Installing using Vagrant ¶
This way is the easiest but long (~20 min).
This installation way doesn’t require pre-installed software (such as web-server, PHP, MySQL etc.) — just do next steps!
Manual for Linux/Unix users ¶
git clone https://github.com/yiisoft/yii2-app-advanced.git cd yii2-app-advanced/vagrant/config cp vagrant-local.example.yml vagrant-local.yml
That’s all. You just need to wait for completion! After that you can access project locally by URLs:
Manual for Windows users ¶
- Install VirtualBox
- Install Vagrant
- Reboot
- Create GitHub personal API token
- Prepare project:
- download repo yii2-app-advanced
- unzip it
- go into directory yii2-app-advanced-master/vagrant/config
- copy vagrant-local.example.yml to vagrant-local.yml
- Place your GitHub personal API token to vagrant-local.yml
- Open terminal ( cmd.exe ), change directory to project root and run command:
That’s all. You just need to wait for completion! After that you can access project locally by URLs:
Installing using Docker ¶
Install the application dependencies
docker-compose run --rm backend composer install
Initialize the application by running the init command within a container
docker-compose run --rm backend php /app/init
Adjust the components[‘db’] configuration in common/config/main-local.php accordingly.
'dsn' => 'mysql:host=mysql;dbname=yii2advanced', 'username' => 'yii2advanced', 'password' => 'secret',
Docker networking creates a DNS entry for the host mysql available from your backend and frontend containers.
If you want to use another database, such a Postgres, uncomment the corresponding section in docker-compose.yml and update your database connection.
'dsn' => 'pgsql:host=pgsql;dbname=yii2advanced',
For more information about Docker setup please visit the guide.
docker-compose run --rm backend yii migrate
Access it in your browser by opening
Yii and Docker ¶
For development and deployments Yii applications can be run as Docker containers. A container is like a lightweight isolated virtual machine that maps its services to host’s ports, i.e. a webserver in a container on port 80 is available on port 8888 on your (local)host.
Containers can solve many issues such as having identical software versions at developer’s computer and the server, fast deployments or simulating multi-server architecture while developing.
You can read more about Docker containers on docker.com.
Requirements ¶
Visit the download page to get the Docker tooling.
Installation ¶
After installation, you should be able to run docker ps and see an output similar to
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
This means your Docker daemon is up and running.
Additionally, run docker-compose version , your output should look like this
docker-compose version 1.20.0, build unknown docker-py version: 3.1.3 CPython version: 3.6.4 OpenSSL version: OpenSSL 1.1.0g 2 Nov 2017
With Compose you can configure manage all services required for your application, such as databases and caching.
Resources ¶
- PHP-base images for Yii can be found at yii2-docker
- Docker support for yii2-app-basic
- Docker support for yii2-app-advanced is in development
Usage ¶
Basic commands for Docker are
to start all services in your stack, in the background
to view logs for all services, continuously
to stop all services in your stack, gracefully
to stop all services in your stack, immediately
to stop and remove all services, be aware of data loss when not using host-volumes
To run commands in a container
docker-compose run --rm php composer install
runs composer installation in a new container
docker-compose exec php bash
executes a bash in a running php service
Advanced topics ¶
Yii framework tests ¶
You can run the dockerized framework tests for Yii itself as described here.
Database administration tools ¶
When running MySQL as ( mysql ), you can add phpMyAdmin container to your stack like the following:
phpmyadmin: image: phpmyadmin/phpmyadmin ports: - '8888:80' environment: - PMA_ARBITRARY=1 - PMA_HOST=mysql depends_on: - mysql
Found a typo or you think this page needs improvement?
Edit it on github !