v0.1.73
- PHP 8.5 - A
Dockerfileis available in this repo if you cannot install PHP 8.5 - composer - (not needed if you use the container)
- Node.js version 24 - Use your linux distribution repository or fnm
- Pnpm version 10 - Use pnpm official installation script for posix systems
You can check working installation with
php -vandcomposer -v.
# Clone or download the repository
# move into project repository
cd ex-php
# Install dependencies (only if you have php 8.5 and node 24)
composer install
pnpm i # Npm has nothing to do with php, but we will need it to run testsIf you do not want to, or cannot, install PHP 8.5 on your system, this
repo has a simple Dockerfile with right PHP version. You can use it to run any PHP commands :
# FISRT, you need to build the docker image
docker build -t ex-php .
# Install PHP dependencies with PHP into the container
docker run -it --rm -v $(pwd):/app ex-php sh -c "composer install && pnpm install"
# Run the php server in the container
docker run -it --rm -p 8000:8000 -v $(pwd):/app ex-php
# Run the automatic test with pest
docker run -it --rm -v $(pwd):/app ex-php ./vendor/bin/pest
# If you want, you can use PHPstan to help catch errors with linting
docker run -it --rm -v $(pwd):/app ex-php sh -c "vendor/bin/phpstan"You still need to have node 24 and pnpm installed on your host machine to run the tests.
Minimalist PHP exercise to discover the syntax.
To launch the tests, you can use
./vendor/bin/pestcommand
PHP is well known for its ability to generate web pages (It was originally created for that purpose).
The following exercises will help you to understand how to generate web pages with PHP.
To test your php web pages, you need to run the PHP web server with the Dockerfile or with php -S localhost:8000 -t public/ if you use PHP on your host machine.
Once the server is running, you can open your browser and go to localhost to see your web pages.
To test if your pages work, use playwright tests : You need to start playwright docker container first. You can run them from the playwright ui (Playwright automatically start php dev server).
- Get current time
- Query parameters
- Forms
- Create todo's and write them to database
- Display a list of todo's from database
- Delete à todo in database
You can easily run the playwright server on a docker container :
docker run --rm --network host --init -it mcr.microsoft.com/playwright:v1.57.0-noble /bin/sh -c "cd /home/pwuser && npx -y playwright@1.57.0 run-server --port 8080"This will start a docker container with the playwright server and all the browsers binary and libraries.
Then, when running your playwright tests, just add an environment variable with the server location :
PW_TEST_CONNECT_WS_ENDPOINT=ws://localhost:8080/ pnpm exec playwright test
# Or with UI
PW_TEST_CONNECT_WS_ENDPOINT=ws://localhost:8080/ pnpm exec playwright test --ui-port=9090With this setup, the test logic will run on the host, but the browsers will remain in the container.
More information here.