12. May 2022 |

FacetWP reindex products automatically (simple solution with wp-cli + cron)

FacetWP had introduced WP-CLI interface which I was very much looking for. Just run wp facetwp index and reindex for the entire site will be created.

I just had a moment in one of my online stores where I saw that the index was last built 8 months ago. Now can add this line to WP All Import bash script and index will be built quickly every time. Or run it once day for example together with daily backup. I find it very convenient.

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

6. Feb 2022 |

Eestiblogid.eu – my hobby project

To improve my coding skills in a safe environment I should start working more on the hobby project eestiblogid.eu. I currently has ~150 weekly users so if I mess something up it should not be huge problem 🙂

Currently it is just 2 small services which I call Reader and Writer.

Reader is a small independent PHP application which basically reads the given list of XML files (RSS feeds) every hour and checks if there is anything new. If there is something new then entry is made to the database. Rules for detecting “new” are very primitive. Therefore, quite often you can see duplicate posts. Reader will probably stay as it is. I should just make the code cleaner from time to time, implement some logging etc.

Writer is also a small php application (using Twig for templating and Bootstrap for styling) to generate views for the front end and reading data from database.

There is no admin panel at the moment. I go straight to the database to edit things (remove, deactivate, delete etc).

Up next

What I would like to do now is to prepare REST endpoints for the front end. Probably it will be php backend built with Laravel or Lumen using their Eloquent ORM.

Front end should be built with React together with admin views for myself (using JWT for authentication).

I try to keep you informed of the progress under this eestiblogid.eu tag.

Update 09.03.22

It has been less than a month. I have not done anything (too busy with my internship). But, meanwhile, Lumen has become extinct (not being developed any further) and I am most probably considering GraphQL (with Lighthouse) insead of REST. So probably it is good that I have not done much.

14. Jan 2022 |

Solution: Composer dependencies require a PHP version…

I tried to initiate new Laravel project and ran into an error. I have been using php 8.0.2 but Magento needed 7.4 so I switched to 7.4 and now I am having this issue with Composer 🙂

Your Composer dependencies require a PHP version “>= 8.0.2”. You are running 7.4.27.

PHP Fatal error: Composer detected issues in your platform: Your Composer dependencies require a PHP version “>= 8.0.2”. You are running 7.4.27. in C:\Users\john\AppData\Roaming\Composer\vendor\composer\platform_check.php on line 24

How to get the value of PHP_VERSION_ID

In terminal run php -a and then var_dump(PHP_VERSION_ID);  You should see the id. To exit you can use ctrl+c.

How to solve it

Open the platform_check.php file and update the PHP_VERSION_ID to what you currently have.

Not sure if it is the best practice but it works.

14. Jan 2022 |

IADB IT-sĂŒsteemide arendus – 5. semestri lĂ”pp

LÔputöö ja ettevÔttepraktika on veel jÀÀnud.

5. semester on nĂŒĂŒd lĂ”ppenud. Tundub uskumatu aga kooli lĂ”petamiseks on teha veel ainult EttevĂ”ttepraktika (ICY0017, 24 EAP) ja lĂ”putöö (6 EAP). Praktikakohta mul veel ei ole nagu siit vĂ”ib nĂ€ha aga otsin.

Sel semestril sai tehtud 7 ainet. 4 neist kohustuslikud, 3 valikained. Kokku 36 EAPd. AlljÀrgnevalt tehtud ained arvestuse saamise jÀrjekorras.

Valikust vĂ”ib aru saada, et valikuga on tegelikult ĂŒsna kitsas kĂ€es ja arvestades minu huvisid – teha valmis midagi tehnilist, praktilist ja töötavat – on vaba ja valikainete osas… no ei olegi ju midagi.

AlljĂ€rgnevalt kasutan aegajalt sĂ”na “moodulisse”, mis tĂ€hendab, et Ă”ppekava on jaotatud mooduliteks. Kooli lĂ”petamiseks peab saama kĂ”ikides moodulites nĂ”utud punktid tĂ€is ja siis validki lihtsalt midagi, mis seal moodulis on parajasti pakkumisel.

FĂŒĂŒsika mittefĂŒĂŒsikutele (NSO0160, 3 EAP, kohustuslik)

ÕppejĂ”ud emeriitprofessor Sirje Keevallik. Arvestuse saamiseks on vaja teha kaks kontrolltööd, mille tulemuste summa annaks > 50%. Kontrolltööd sisaldavad (vĂ€hem) ĂŒlesannete lahendamist ja (rohkem) teooriat. Kuigi fĂŒĂŒsika vĂ”ib tunduda hirmutav, siis tegelikult ei ole seda ainet pĂ”hjust karta.

Kui kontrolltööd ebaÔnnestuvad, siis oli lisaks veel eksami vÔimalus.

Veebihalduskeskkonnad (ICD0020, 6 EAP, valikaine)

Kuna mul oli vaja valikainete moodulisse millegi eest 6 EAP saada, siis sĂŒgissemestrit arvestades olin kahe vahel – inglise keel vĂ”i see aine. JĂ€in selle juurde.

ÕppejĂ”ud Meelis Antoi, kes ĂŒhtlasi on IADB Ă”ppekava programmijuht. Minu jaoks oli see ilmselt kĂ”ige lihtsam aine seni. Sisuks oli teha localhostis ĂŒhesuguse vĂ€limusega veebileht Drupalis, Joomlas ja WordPressis. SeejĂ€rel anti kooli poolt igale tudengile ĂŒks VPS, kuhu oli installitud Debian 9 ning omaltpoolt oli vaja installida php, mysql, apache ja enda localhostis valmistatud WordPressi leht sinna ĂŒmber tĂ”sta. PĂ€rast “lĂ€bijalutuse” formaadis tööde ettenĂ€itamist  oligi arvestus kĂ€es.

VPSi andmine kooli poolt oli muidugi tore ĂŒllatus. Ma arvan, et mingi pisikese Ubuntuga purgi, mis oleks avalik, vĂ”iks kĂ”ik tudengid 1. semestri esimesel pĂ€eval saada endale haldamiseks 🙂

Automaattestimine (ICD0004, 3 EAP, programmerimise moodul)

Arvestatud sain 9. detsembril. Tegemis on valikainega programmeerimise moodulis. ÕppejĂ”ud German Mumma. VĂ€ga kasulik aine ja hea Ă”ppejĂ”ud, nii et kindlasti soovitan. Töökeel on Java ning Ă”ppetöö vĂ€ga praktiline – ehk korrektsel viisil testide kirjutamine + giti korrektne kasutamine. Teemadeks TDD, unit testing, integration testing, UI testing (Selenide). Testmise Ă”ppimiseks kasutasime Restful-booker API, OpenWeatherMap API, The Internet UI vaateid.

Koormustestimist ja performance testimist kahjuks ainesse ei mahtunud aga see huvitanuks mind ka.

Pisut raskemaks muutis aine asjaolu, et mul on Maveniga vĂ€he kokkupuudet (nt konfi kirjutamine ja sĂ”ltuvuste valimine/haldamine) ja Javat seni ĂŒldse suhteliselt vĂ€he kirjutanud aga sai hakkama ikka. Toetava ainena MĂ€rt Kalmo ainele oli sellest kindlasti palju abi.

Keskkonnakaitse ja sÀÀstev areng (YTG0060, 3 EAP, kohustuslik)

ÕppejĂ”ud Üllar Rammul. See on Ă”ppekavas kohustuslik aine, mis on erialast tĂ”esti tĂ€iesti eemal (ei ole kuidagi IT) aga sellegipoolest ma arvan, et see on tĂ€iesti Ă”ige aine tĂ€iesti Ă”igel kohal. Lisaks suurepĂ€rane Ă”ppejĂ”ud ja vĂ€ga hĂ€sti lĂ€bi viidud kursus.

Lai silmaring on hea ja see on puhtalt silmaringi aine.

Programmeerimine C# keeles (ICD0008, 6 EAP, kohustuslik)

ÕppejĂ”ud Andres KĂ€ver. Arvestatud 22. detsembril. MillegipĂ€rast on see jĂ€tkuvalt vĂ€ga krĂ”be aine, kuigi C# olen praeguseks juba pĂ€ris palju kirjutanud. Ma ei ole lĂ”puni aru saanud, mis selle aine nii keeruliseks teeb, et nii vĂ€he inimesi (41%) selle aine sooritatud saab.

KĂ”ik, mida oli vaja teha aine lĂ€bimiseks, on siin lehel kirjas: 5 kodutööd ja eksam (1h teooriat, kuni 11h ĂŒlesande jaoks).

Veebirakendused Java baasil (ICD0011, 6 EAP, kohustuslik)

ÕppejĂ”ud MĂ€rt Kalmo. Arvestatud 7. jaanuaril. Õppeaine sisuks on Java vĂ”imalusi ja tehnoloogiaid kasutades pisikeste back-end funktsionaalsuste teostamine. Rakenduseks oli pisike mĂ”ne tabeliga andmebaas, millega sai API endpointide kaudu suhelda. Front-endi ei teinud. Tehnoloogiad millega tutvuti: Servlet, Jdbc, PostgreSql, HsqlDb, Gradle, Spring Core,  Spring Mvc, JSR 303, JPA, Spring Security.

Mulle vĂ€ga meeldib MĂ€rt Kalmo Ă”petamise stiil ja Ă”ppetöö korraldus: loeng → praktiline harjutus → iseseisev hindeline ĂŒlesanne (koos avatud testidega, mida saab lahendamise ajal kasutada) → vajadusel praktikum/konsultatsioon, kui iseseisva tööga kuskil tĂ”rkeid tekib.

Samuti meeldib mulle vĂ€ga tema lĂ€henemine selles osas, et tĂ€htis ei ole, et sa oskad mingit asja mingit moodi teha, vaid et sa saad aru (ja oskad selgitada), miks mingit asja ĂŒht vĂ”i teist viisi tehakse (vĂ”i ei ole hea mĂ”te teha). EesmĂ€rk on saada aru, mis on mingi asja mĂ”te. Kui see lĂ€henemine sobib, siis tema ained tĂ”enĂ€oliselt meeldivad.

Aga… edasises elus ĂŒldiselt on selle tulemusena raskem, kui saad aru, kui vĂ€he inimesed ĂŒldiselt nii mĂ”tlevad – et miks nad mingeid asju teevad vĂ”i mis on nende asjade tegemise mĂ”te 🙂

ICY0012 InfosĂŒsteemide analĂŒĂŒs ja projekteerimine (6 EAP, toetav)

Kuna toetavate ainete moodulisse oli millegi eest 6 EAP vaja saada, siis jĂ€in selle aine juurde. Marko soovitas ka seda ainet. ÕppejĂ”ud on hinnatud Ă”ppejĂ”ud NadeĆŸda “Nadya” Furs, keda vĂ€ga palju kiidetakse. Semestri jooksul oli vaja esitleda kaks grupitööd – ĂŒks traditsioonilise ja teine agiilse osa kohta – ja see oligi kĂ”ik. Aine teemades oli pĂ€ris suur ĂŒlekate Paul Leisi “Tarkvaratehnika” ainega, mida vĂ”tsin 4. semestril.

8. Jan 2022 |

How to prepare for the TestDome php assessment – my mistakes and tips

3rd year IT student in search of an internship

5th semester at school is pretty much over by now. Only one small assignment to do on upcoming Tuesday Thursday. Hopefully, I will write about the semester at some point.

On Monday I am going to do PHP tests for the internship that I applied for. I am preparing for it at the moment by solving Testdome PHP exercises and PHP interview questions. If I succeed it would be a huge step for me to become a sufficient Magento developer one day.

Continue reading “How to prepare for the TestDome php assessment – my mistakes and tips”

19. Nov 2021 |

Does PHP Loop Through the Whole Array to Find a Specific Element?

Same question here but I find its answer a bit misleading. My answer would be YES. You need to loop through the whole array to find a specific element and the worst case complexity is O(n). Unless:

  • you use associative array and ask the element by its key. Then the search takes constant time O(1).
  • you ask element by its index (you know where the element is and you go there directly). Then the search takes constant time O(1).
8. Oct 2021 |

PostgreSQL create db and user

I need it quite often during development (mainly school work) that I need to create new database together with new user that can only use this specific database. Here are three simple commands that do just that.

CREATE DATABASE robert_db;
CREATE USER robert WITH ENCRYPTED PASSWORD 'x1y2z3';
GRANT ALL PRIVILEGES ON DATABASE robert_db TO robert;

In development I usually keep db name and user name the same so that I have less variables to remember.

10. Sep 2021 |

Tee endale vanast arvutist server

Kui ma oleksin teadnud, et enda serveri tegemine on nii lihtne, siis ilmselt oleksin seda teinud juba varem.

Otsides kohta, kust enda arenduse asjadeks pisike VPS vÔtta, jÔudsin selleni, et tegin (esialgu) enda vanast riiulis seisvast Dell XPS13 lÀpakast Linuxi serveri. 2011 mudel, i5-2467M, 4GB RAM, 512 SSD (dual masin boot, millest osa on Win7 all). See seisab ka serverina 99% ajast ilma koormuseta.

NĂŒĂŒd mĂ”tlen, et peaks vĂ”ibolla lĂ€paka Raspberry Pi 4B‘ga asendama (komplekt lĂ€heks kuskil 145 eurot). Kui kellegi on pakkuda, siis anna mĂ€rku 🙂 Update: Hetkel tundub hea mĂ”te, et ma sellega ei kiirustanud. ARM protsessoril ei tööta Docker normaalselt (viide) nii et kui ĂŒldse, siis pigem mĂ”ni Inteliga NUC vĂ”i mini-PC (nt IBMi ThinkCentre).

Mul on kodus kĂ”ige tavalisem Elisa 50/10 internet ja meeldivaks ĂŒllatuseks on kĂ”ik public IP pordid lahti. Public IP’le pĂ€ringuid tehes saan enda serverile ligi. Jah, see on aeglane 😀 Kui Zone annab VPSile 1 Gbit/s sisenev ja 100 Mbit/s vĂ€ljuv liiklus, siis minu puhul on need hetkel vastavalt 20x ja 10x pisemad. Aga andmebaasipĂ€ringuteks piisab kĂŒll.

Kuna mul zone.ee’s on ka mĂ”ne domeenid registreeritud, siis tegin ĂŒhele neist A-kirje ja nii ei pea ma enda IP’d meeles pidama. Kuna IP ei ole staatiline, siis IP muutumisel, piisab A-kirje uuendamisest.

Mis mul seal on

OperatsioonisĂŒsteemina on serveris Ubuntu Desktop 18.04.5 LTS (sest juba ammu installitud). KĂ”ik asjad, mis serveris jooksevad on Dockeri konteinerina.

Esimene asi, mille tööle pĂŒĂŒdsin saada oli see, et IP’le pĂ€ringu tehes avaneks kĂ”ige tavalisem nginx (hÀÀldatakse nagu “engine X”) Welcome Page. Piisas sellest, kui:

  • Docker on installitud (snap install docker vĂ”i snap remove docker eemaldamiseks)
  • nginxi kontener kĂ€ivitada docker run --name nginx_container --rm -d -p 8080:80 nginx (viide). –rm tĂ€hendab, et kui teed docker stop containerId, siis konteiner kustutatakse Ă€ra.
  • Ruuteris teha port forward sisse tuleva public IP port 80 mappida sisemises vĂ”rgus oleva seadme (ehk siis laptopi) IP porti 80. Minu puhul oli vaja mappimine teha Elisa antud Technicolori ruuteris (kuhu server-lĂ€pakas on kaabliga ĂŒhendatud). See on kĂ”ige lihtsam setup.

SeejĂ€rel installisin (kĂ”ik eraldi dockeri konteinerid) MariaDB, phpMyAdmin (selle MariaDB kĂŒlge) ja Microsoft SQL Serveri.

Millest on abi

tracert that.ee – nĂ€ed, kust seadmetest su liiklus lĂ€bi lĂ€heb ja kuhu ta jĂ”uab.

Turvalisus

Selle koha peal ma olen kÔige tuhmim hetkel ja mul ei ole head ettekujutust, missugused ohud mind varitsevad.

  • Ufw (Uncomplicated Firewall) panin peale
  • Sisse saab ainult SSHga, parooliga sisselogimise keerasin kinni

Kasulikud Dockeri kÀsud

Dockeriga toimetamine tahab super useri Ôiguseid. Ehk siis sudo su.

sudo snap install docker – installib Dockeri
sudo snap remove docker – eemaldab Dockeri
sudo docker ps -a – nĂ€itab kĂ”iki konteinereid ja nende infot
sudo docker start <containerId> – kĂ€ivitab konteineri
sudo docker stop <containerId> – peatab konteineri
sudo docker rm <containerId> – kustutab konteineri

sudo docker image list – nĂ€itab arvutis olevate image’te nimekirja
sudo docker image rm <imageId> – kustutab image

Kui mingi asjaga tekib raskuseid, siis Google otsing ja Digital Oceani juhendid aitavad enamasti alati.