Yii3 - How to start

Comparing #62 with #63

Revision #63 was created by rackycz rackycz on Aug 30, 2026, 9:15:16 AM.

update

Content

[...]
.. and follow the **docker** instructions in the documentation.

If you don't have Docker, I recommend installing the **latest** version of Docker Desktop:
- https://docs.docker.com/get-started/introduction/get-docker-desktop/

In this text I am mainly working with API endpoints, but UI will be presented later as well.
 
 
## Running the demo application

You may be surprised that docker-compose.yml is missing in the root. Instead the "make up", "make stop" and "make down" commands are prepared.
[...]
If you type "docker ps" into your host console, you should see 3 running containers: yii3web_php, yii3web_adminer, yii3web_db.

The web will be, from now on, available on URL http://localhost:9080 which is more handy than just ":80" I think.
(
 
 
> 
Later you may runuse 4 different projects at the same time and all cannot run on port 80). Yes, you can technically remove those public (exposed) ports completely and use Caddy for routing, but it is level 2. This approach can be used on production

## Enabling MariaDB (MySQL) and migrations
[...]
```

> To run composer (or any other command inside your dockerized yii3 application) you have 4 options:
 
- Make:
 
The best solution is to prepend the composer commands with "make".
 
 
 
> Other solutions:
 
> 
 
> - If you have Composer running locally, you can call these commands directly on your computer. (I do not recommend)
 
> 
 
> - You can SSH into your docker container and call it there as Composer is installed inside.
 
> In that case:
 
>   - Find the name of the PHP container by typing "docker ps"
 
>   - Call
commands, you can use the "make command". Just prepend the composer commands with "make".
 
> Or you can use "docker exec -it {container_name} /bin/bash" to enter the container and you can freely use any commands
 
> Or type
"docker exec -it {containerN_name} /bin/bash"
 
>   - Now you are in the console of your php server and you can run composer.
 
> 
 
> - If you are using PhpStorm, find the small icon "Services" in the left lower corner (looks ca like a cog wheel), find item "Docker-compose: app-api", inside click the "app" service, then "yii3web_php" container and then hit the button "terminal" on the righthand side
composer install" to directly call composer.

### **Setting up composer packages**
[...]
## Reading data from DB

In Yii we were always using ActiveRecord and its models, but in Yii3 the package
iwas not ready yetwhen I created this page. The solution iwas to use existing class `Yiisoft\Db\Query\Query`. (ActiveRecord will be shown later below.)

Open class `src/Api/IndexAction.php` and modify it a little to return all users via your REST API. You have more options:
[...]
## php.ini

You can do the same as above (chapter about xDebug) with `php.ini` for example to set the timezone
:. I recommend only using UTC in PHP and DB. Only if user needs to display the datetime in their timezone, concert it in the UI. 

```
[Date]
date.timezone = "UTC"
```
[...]