12. Oct 2022 |

php versions

As I use composer packages more and more I need to switch between php versions used in terminal. Some notes here for myself.

  • How to install and remove php
  • which php – where php is installed
  • php -v – which php is currently in use in terminal
  • ls -la /usr/bin/php* – which php versions are installed in the system

Install php on Ubuntu

sudo update-alternatives --config php – see options and switch between versions.

For installation I took commands from this instruction.

sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php

Install php7.4 with few common PHP modules (also Digital Ocean post)

sudo apt-get install -y php7.4 php7.4-cli php7.4-json php7.4-common php7.4-mysql php7.4-zip php7.4-gd php7.4-mbstring php7.4-curl php7.4-xml php7.4-bcmath

Digital Ocean gives following suggestions for packages:

sudo apt-get install -y php8.1 php8.1-cli php8.1-common php8.1-mysql php8.1-zip php8.1-gd php8.1-mbstring php8.1-curl php8.1-xml php8.1-bcmath

For uninstalling just use:

sudo apt remove php7.4 etc or the php -m to list all loaded PHP modules.

sudo apt autoremove

Composer broke down

StackOverflow solution and install composer the old way.

7. Jul 2022 |

Composer notes

composer init – to create composer.json (not needed if you just run composer require {package}

composer dump-autoload – to regenerate namespaces in dependencies list (if composer.json is modified)

composer dump-autoload -o – generates optimised autoloading. Not actually needed in development.

Working with composer

Commit composer.lock but run composer update locally, composer install on server (ref).

composer outdated – checks if all packages are up to date
composer update – updates (installs) all outdated packages based on packagist.org.
composer install – installs packages based on composer.lock file

Version notation – Caret, Tilde, or Asterisk?

PHP version

Changing php version in Zone.

  • mkdir -p ~/bin && ln -sf /usr/bin/php74-cli ~/bin/php
  • mkdir -p ~/bin && ln -sf /usr/bin/php80-cli ~/bin/php
6. Jan 2021 |

8/100 – composer, twig

Recommend:

Issues with guides. When installing twig then phpStorm cried that I have old version of composer. OK, sudo apt-get remove composer (because suggested composer self-update does not work) and sudo apt-get composer and the result is that I still have old one 😂 Then I followed the composer installation guide and when trying to make it global it gives me wrong path in the guide. Correct one would be /usr/bin/composer and debugging it took me quite a while.

As you can see I have been messing around with the birthday reminder app.

Listened: Matt Mullenweg: Collaboration Is Key – the founder of WordPress on Knowledge Project podcast

Discovered: “Officials are investigating whether the company, founded by three Russian engineers in the Czech Republic with research labs in Russia…” is a way to describe JetBrains in The New York Times.