11. Aug 2022 |

Weird stuff in Laravel

Laravel migrations run in the alphabetical order of their file name

“General error: 1005 Can’t create table [..] Foreign key constraint is incorrectly formed”

This happened when the migration of my in-between table ran before the table its FKs were linked to. First I thought I can not use Laravel’s foreign key constraints but at some point I figured it out. Renaming the migration file helped.

3. Aug 2022 |

Laravel and php notes

Updated Laravel 8 to 9. Had to install php 8.0 with extensions (below) and switch php version.

Installing php. apt installs php to /etc/php

Find ini file – php -i | grep php.ini or php --ini

Install dependencies

sudo apt install php8.0-curl php8.0-xml php8.0-mbstring php8.0-mysql php8.0-intl – installs two extensions.

Call to undefined function… See if all necessary extensions are installed

21. Jul 2022 |

Eestiblogid.eu uuendus

Kirjutasin eestiblogid.eu lehe ümber Laraveli raamistikule. Kasutajaliidese jaoks hetkel kasutusel blade mallid (hea mugav kasutada). Väga suurt äriloogikat ei teinud aga vähemalt viewmodelid püüdsin ikka kasutusele võtta.

Reader (ehk see tükk, mis blogisid loeb) on Laravelist eraldi. Endiselt lihtsakoeline php rakendus (index.php, functions.php ja kaks mudelit) aga püüdsin valmisteeke kasutada seekord. Kasutusele said võetud laminas/laminas-feed, laminas/laminas-http, doctrine/dbal (docs). DI implementeerimisest (php-di abil) kahjuks jõud üle ei käinud. Eesmärk olnuks andmebaasiühenduste kasutust viisakamaks muuta 🙂

Asub Zone serveris, minu muude asjade hulgas. Laraveli deployment sinna on väga mugav. Pmst repo fetch ja pull privaatses kaustas. Rakenduse kiirus on päris normaalne. Andmebaas on hetkel veel arendusserveris (pisike Hetzneri VPS) aga tõstan vasti Zonesse ringi.

Andmebaasi kolimisel Zone’sse läksid tähed katki.

Andmebaasi kolimisel tekkis selline viga (mida arenduskeskkonnas ei esinenud). Esialgu oli vaja kohendada Doctrine‘i ja lisada selle konfiguratsiooni charset (mille valik vajas natuke otsimist, kasutusele läks utf8mb4). Selle tulemusel sai andmebaasi kirjutamise esmapilgul korda. Seejärel läks katki Laravel. Põhjuseks see, et andmebaasitabelite collation ei olnud see, mida Laravel (enda konfuguratsioonis) kasutab. Tabeli collation’i muutmisel läks Laravel ka korda. Arendamise ajal (kuna arenduskeskkonna baasis vigu ei esinenud) ei osanud nendele asjadele tähelepanu pöörata.

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
28. Jun 2022 |

WordPress plugins

These are the plugins I install with clean install, just one command using wp cli.

Classic editors for widgets and posts (because Guttenberg is awful). One plugin against spam, plugin for opening external links in new window and Yoast SEO (because AIOSEO is garbage). You probably don’t need anything else in the beginning.

In the end I enable auto updates.

wp plugin install classic-widgets classic-editor antispam-bee open-external-links-in-a-new-window wordpress-seo --activate && wp plugin auto-updates enable --all

26. May 2022 |

Docker, Linux, user

Täielik segadus 🙂 Selleks, et Linuxis saaks Dockeriga lokaalselt php arendust teha, siis peab Docker, host ja PHP õigused paika sättima.

Digital Oceani õpetus täpselt olemas.

To run docker command without sudo, you need to add your user (who has root privileges) to docker group. (ref).

See current user: echo ${UID}

Official doc: Post-installation steps for Linux

You need to run your application as the same uid inside the container as you do on the host to get file ownership to match. (ref)

Something about application and root here.

Digital Ocean tutorial – WordPress with docker compose.
Probably the thing you are looking for – Docker in Development – Docker and File Permissions

22. Feb 2022 |

Magento REST API – Specified request cannot be processed and Class does not exist

Class \Vendor\ModuleName\Api\TestInterface does not exist

During development move things from local-src + symlink to app/code/{vendor}/{modulename} so that namespace and folder structure could match.

If you are using interfaces in your module then this is also true that you need to use full path reference in PHPdoc instead of use import and reference.

Both worked for me

Specified request cannot be processed

rest/V1/test/ – V in version needs to be capital letter (also in webapi.xml).

And just useful tip that you can extract interface out of existing class.

8. Feb 2022 |

How to install Magento on local nginx

Not a tutorial but notes for myself

Creating vitual host (tutorial), user rights in /var/www/ (rights to group, user to group) and here even better guidance.

Before Magento I usually set up default WordPress installation first to test if php works well, database is ok and nginx has started.

Useful command: sudo mv wordpress/* /var/www/html – how to move content of whole directory somewhere

Order of Magento installation

As it is in the documentation. But you can be sure something goes wrong.

  1. Composer create-project to get the metapackage: composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition magento/
  2. Permissions, also sudo chown -R rbrt:www-data .  It is occasionally needed later too.
  3. php bin/magento install... (this is very long command you can find here)*
  4. If you need then you can also install sample data: php bin/magento sampledata:deploy (takes very long time) and you may also need to run php bin/magento catalog:images:resize to get the images shown in the store.

Clean Magento install with sample data is 1.4 GB, 109 thousand files (so creating and deleting may take long time), 410 database tables. For comparison, clean WordPress is just 12 tables.

*For this step you need ElasticSearch running. sudo systemctl start elasticsearchInstructions can be found here on Digital Ocean website.

Nginx conf

/etc/nginx/ -> nginx.conf

Restart: sudo systemctl reload nginx

Get ownership
sudo chown -R robert /var/www/html
Give ownership back to the webserver system user www-data.
sudo chown -R www-data:www-data /var/www/html

Conf

Create .conf to /etc/nginx/sites-available

Symlink conf to sites-enabled

sudo ln -s /etc/nginx/sites-available/abc.conf /etc/nginx/sites-enabled/

Symlinked conf updates itself automatically

Add custom domain to hosts file

sudo code /etc/hosts --user-data-dir

Rights

This did not work well…

First, you should ensure that your username is included in www-data group. If not, you can add your username as www-data group
sudo adduser $USER www-data
After that, you should change the ownership of /var/www to your username
sudo chown $USER:www-data -R /var/www

Set file permissions before Magento installation

https://devdocs.magento.com/guides/v2.4/install-gde/composer.html#set-file-permissions – but I am not shure what the before means.

Disable 2FA

php bin/magento module:disable Magento_TwoFactorAuth

Because otherwise you can not log into admin (because mail server does not work)

Post installation commands

php bin/magento setup:di:compile
php bin/magento indexer:reindex or php bin/magento indexer:status
php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy -f
php bin/magento deploy:mode:set developer
php bin/magento cache:clean
php bin/magento cache:flush
php bin/magento module:disable Magento_Csp
php bin/magento module:disable Magento_TwoFactorAuth