Amazon Linux 2 with WordPress, PHP 8, MySQL 8 and Node.js (in progress)

Exciting voyage began on TU 2021-02-16.  After months of  WordPress (WP) warning about outdated PHP version, it was time to open a new Amazon Linux 2 instance and install all the latest gadgets.

This major upgrade triggered many errors and problems. I needed a place to store and accumulate the information on resolving the issues one-by-one. The main purpose of this article is to capture all the errors and stumbling blocks encountered along the way, so that we can preproduce all the steps  in a quick succession.

Let’s start with an approximate table of content.

Table of content

 – launching a new Amazon Linux 2 instance with 30 GB volume
– allocate new new IP address
– set new DNS entries with my domain provider
– configure puTTY, WinSCP and establishing connection
– set a proper time zone
– install Apache 2.4 and rename default group and user
– set new user and group rights to a default www directory
–  install PHP 8.0
 – Edit config.inc.php
– install MySQL 8.0 Community Server
– set new root password
– install phpMyAdmin
–  my.cnf to fix “binary logging” error
– create MySQL user with new password requirements
– restore MySQL databases from other instance
– copy existing sites from Amazon Linux 1
– install and configure a fresh copy on WP
– edit httpd.conf, httpd-le-ssl.conf and ssl.conf with nano
– install free self-signed certificate
– edit localhost.crt and localhost.key and test
– install certbot and real 90-days certificate
– install node.js
– install PM2 to run node.js server
– run node.js  server reboot (using PM2 restart)

The biggest time and effort were spent not in installing, but in adopting the existing code for new requirements.

Troubleshooting pure PHP site

Troubleshooting WordPress site

Troubleshooting Node.js with Jade (Pug) site

PHP8  no longer supports function get_magic_quotes_gpc():

‘Call to undefined function get_magic_quotes_gpc()’

After fixing PHP code due to magic quotes error, PHP sites appers to work connect to DB OK and perform as expected.

This was the first site to start working on new Amazon Linux 2.

WordPress 5.6 on PNP 8.0 – enable debug in wp-config.php to catch the errors.

Plugin ‘EG-series’ crushes the site trying to call create function:
depreciated create_function()

Next big problem in comment-template.php
Fatal error: Uncaught ValueError: Unknown format specifier “”” in line 2668

Problem is in child theme file comments.php where I formatting submit buttons.

Do not start troubleshooting with free SSL.  Install and configure ‘letsencrypt’ certificate first.

One of the major modules – jade – got renamed into ‘pug‘ and rule for string interpolation changed:
massive coding efforts required to accommodate new requirements in every view.

MySQL no longer supports basic authentication by default.  You either (1) need to allow basic authentication or (2) rewrite your MySQL connector.

 

     
     
     
     
     
     
     

 

Pending tasks

– automate Letsencrypt certbot to renew certificates
– automate DB backup with scheduler
– when everything ready – migrate all latest PROD DB one more time
– repoint DNS records to new Linux 2 server
– delete old Amazon Linux 1 instance
– free old allocated IP address
– 
– 

– 
– 
– 
– 
– 
– 

Node.js – code changes and server restarts

If you make code changes in *.js files, you need to restart the server.  If you make changes in your *pug views – no restart is needed. Changes are available immediately after pressing the save button.

Node.js and MySQL – handle blank dates

You need to catch and handle blank date, by converting it into a null value:

if(fieldValues['adEffectiveDate'] == '') fieldValues['adEffectiveDate'] = null;

MySQL backup with scheduled scripts

When you create scripts with mysqldump and save the file as your_script.sh make sure to modify permissions at allow EXECUTE, and not only read and write. Here is example how to use 

mysqldump -y -u yourDBuser -pYourDBPassword yourDBname > /home/ec2-user/YourDir/yourDBname`expr substr $(date +%d) 2 1`.sql

This script will create a backup copy of your database with a name yourDBname + one number character from current date.  For example, if you run backup on 27-th, your backup file will be called yourDBname7.sql 

 

Work with crontab to schedule tasks

–010– set default editor to nano – export EDITOR=nano

–020– edit scheduled jobs with
crontab -e
For some reason, command above creates a file in a random location with a random fila name: /tmp/crontab.CqmlUl and then deletes it upon exit. Instead,  I used direct edit command:
sudo nano /etc/crontab

030– list your scheduled jobs with crontab -l

–040– restart the scheduler
sudo systemctl restart crond

Spacing when you include a pug VIEW

Your VIEW include directive should observe proper left spacing tabulation so that it will be included in proper HTML element from main VIEW.

 

 

– 

 

 

(Visited 487 times, 1 visits today)

Be the first to comment

Your question, correction or clarification Ваш вопрос, поправка или уточнение