Start simple

Get started with PHP

The Drawstring Canister comes with multiple strap and handle options to adapt throughout your day. Shoulder sling it, backpack it, or handy carry it.

1. Install Docker on your development environment

Docker allows cross platform development and has an easy to use CLI. It is available for Mac, Windows and Linux.

# go to https://www.docker.com/get-started/ and follow the instructions

2. Install PHP

PHP has many versions, Macbooks have PHP preinstalled, but usually this is an older version. Use the latest stable version with a Docker Image and set a local alias to quickly access PHP in the Terminal.

alias php="docker run --rm --interactive --tty --volume $PWD:/app -w /app php:8.2-cli php"

3. Install Composer

Composer is the package manager of PHP. It allows you to install and manage dependencies of your PHP projects.

docker pull composer/composer 
docker run 
--rm -it -"$(pwd):/app" composer/composer install 

# create a new folder for your project
mkdir php-example
cd php
-example

# install your first package
composer require phpoffice/phpword

4. Create your first programm

In this program we create a Word document with program code and store it on your computer.

require __DIR__ "/vendor/autoload.php";
                    
$phpWord = new \PhpOffice\PhpWord\PhpWord();


$section $phpWord->addSection();
$section->addText(
'"Learn from yesterday, live for today, hope for tomorrow. '
'The important thing is not to stop questioning." '
'(Albert Einstein)'
);
$objWriter \PhpOffice\PhpWord\IOFactory::createWriter($phpWord'Word2007');
$objWriter->save('helloWorld.docx');

4. Run your program

Run your program to create your first Word Document

php example.php