HOWTO: fix your wordpress install after a system update – main page shows only php code

Background: we had a very big disconnection and the local WP installation didn’t come back after all the other systems came back. I have access to the website (so the apache2 service is running) but the main site as well as the admin site show only php text code. I tried rebooting the computer (a virtual machine) without luck. A very simple solution this one has. As usual, the solution is in StackOverflow.

sudo apt install php7.0 libapache2-mod-php7.0 
php7.0-mysql php7.0-curl php7.0-json

I restart then my apache2 and my website comes back. Fiu! Have a nice weeked, or see you tomorrow for the Mars discussion post…

A LimeSurvey in a docker: make it a quick and dirty

You may need to ask your colleagues about something at one point, I’m sure about it. But I’m sure about also that you don’t have time, neither hardware, to program an entire survey or to install the software in a specific server. Since I’m lazy also, as you know, I looked for a docker solution until I found one that does the job. The basic principles of a lime survey you get on this post. This will work if your docker station has a mysql database – you will be asked to connect to the database. If you don’t have, or you don’t want to use it, we need a compose with a mysql docker.

It is worth to mention all the docker images I found. I hope it saves you googling time! 😁😁. So here you have the crramirez limesurvey image, with a pseudo-docker compose. And here you have the martialblog limesurvey, with a lot of possible customisations. Me, I’m a simple person. I don’t want to play with customisation, I want to download a compose file and get the thing working out of the box. This goal you can achieve with the acspri limesurvey. In short (or TLTR) 😁😁😁: make a folder and copy this into a docker-compose.yml file.

version: '2'
services:
limesurvey:
image: acspri/limesurvey
ports:
- 8082:80
environment:
LIMESURVEY_DB_PASSWORD: example
LIMESURVEY_ADMIN_USER: admin
LIMESURVEY_ADMIN_PASSWORD: password
LIMESURVEY_ADMIN_NAME: Lime Administrator
LIMESURVEY_ADMIN_EMAIL: lime@lime.lime
volumes:
- ./plugins:/var/www/html/plugins
- ./upload:/var/www/html/upload
- ./config:/var/www/html/application/config
mysql:
image: mariadb
environment:
MYSQL_ROOT_PASSWORD: example

As usual, careful with the formattingΒ if you cut’n’paste from above. Once you have this file in a folder in the computer with dockers up and running, just type

docker-compose up -d

And access to:

Frontend (what you send to the people)

http://localhost:8082/

Backend (to create the survey)

http://localhost:8082/index.php/admin

I’m not going to dig more, since now it’s time to write the survey. Don’t forget to check how to configure the default answers and how to export the results. If anyone is interested, that is not always the case 😩😩😩.

MYSQL tips & tricks – output format and where clausules

By default when you run a mysl query you get a table as an output, with its header and so on. This is not wanted if we want to get the output stored in a bash variable, for example. Here you have the StackOVerflow post over the formatting issue. Or maybe you want to display all the results without the table? How about only the result? Let’s give some examples.

useremail=$(mysql --silent --batch -N -u $USERNAME -p$PASSWORD 
-D $DATABASE -e "SELECT email FROM mytable WHERE
concept= \"$myconcept\" ");

The above command, on the proper bash script, will print me the email colum values from the table mytable of those entries with colum concept matching the value $myconcept. A sample output, for two matches, will look like this:

pepito@domain.org
jorgito@domain.org

Of course, this all will depend on what is stored on mytable. You see where am I going, right? πŸ˜‰πŸ˜‰. Just in case, here I refresh you how to use the Mysql where with examples. PD: Yeah, I cleaning my notes. Finally πŸ˜”.

MySQL shell-script management & notes

I’m a shell guy, maybe because I miss the sea 😁😁. So whatever I can script I script. Now that I work with databases I’m scripting the data checks, access and similar. All big project starts with google always, and here you have my curated results:

MySQL: Run Query from Bash Script or Linux Command Line. A good start. The angular stone will be this line:

$ mysql -u USER -pPASSWORD -D DATABASE -e "SQL_QUERY"

where everything in capital letters can be a shell variable. Let’s make it more secure.

How to check if a table exists in a MySQL database? As usual, with an IF block. Adapted from that post, in pseudocode, the shell iffs would look like this:

### Check if DATABASE exists
if [[ $(mysql -u $USER -p$PASSWORD -e "$SQL_EXISTS" $DATABASE) ]]
then
echo " Table exists ..."
### Check if DATABASE has records
if [[ $(mysql -u $USER -p$PASSWORD -e "$SQL_IS_EMPTY" $DATABASE) ]]
then
echo " Table has records ..."

And here another StackOverflow post on the same line. Now we know we have a database or a table. Do we know if an element exist on it? Howtogeek can tell us how. From the post I will keep these lines that we can use to check if the element with id=1 has the specific value. I copy it:

field=$(mysql -u root -BNe 'USE test; 
SELECT label FROM test WHERE id=1')
if [ $field == 'TEST' ]; then
//do stuff
fi

Go to the post for more details. Wrapping up, let’s check the whole table for an element, also in pseudocode

ENTRY="mysearchedvalue";
QUERY="USE "$DATABASE"; SELECT columname FROM "$TABLE;
COLUMN=$(mysql -u $USERNAME -p$PASSWORD -BNe "$QUERY")
for field in $COLUMN; do
if [ $field == $ENTRY ]; then
echo " Entry " $field " found"
else
echo " Entry " $field " missing..."
fi
done

The above loop can probably be done in another hundred ways, but I think you get the message. If not check this post : loop through MySQL in bash. Happy coding, have a nice weekend! ❀️❀️

Cannot edit phpMyAdmin Table Cells

Image taken from the solution here.

A very stupid one, but again, it’s my blog. I remember it was possible to do online edition of a table created on phyMyAdmin. Of course I tend to inherit tables, or even already configured instances, so I didn’t know how to do it – until today. In short, you can create a table very easily in phpMyAdmin, and insert and delete columns of it, but if you want to modify it the table must have an unique ID column configured as PRIMARY with A_I (Auto Increment) flag. The name is not important…

This is the post that explains the solution. Yah, databases are fun! 😁😁😁

Install phpMyAdmin on CentOS 7.X

The login page. Image credit here.

What can I say? You should know how to do this already, but the result of what I did was incomplete. Remembering it:

yum install phpMyAdmin. It will install the skeleton that you later want to use. Of couse the localhost/phpmyadmin page is not available afterwards.

yum install php. In case you didn’t do it already.

vi /etc/httpd/conf.d/phpMyAdmin.conf. To adjust the permissions. More specifically on it, all the Order Deny,Allow, that should have under the Allow from all. Be aware that it may be more than one.

systemctl restart httpd. Now we can see the phpMyAdmin page, but we can’t log in as root. We need a password. For that, we need to interact with mysql. Things I’ve tried (unsucessfully):

 ## > mysql -u root -p
Enter password:Β 
ERROR 2002 (HY000):
Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
## > mysql -u root -p password
Enter password:Β 
ERROR 2002 (HY000):
Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
Β ## > mysql -u root
ERROR 2002 (HY000):
Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

Maybe there’s something missing? Indeed.

systemctl status mariadb gives a Unit mariadb.service could not be found.I install it yum install mariadb-server and start it systemctl start mariadb. Yeah. 😁. To my readers, of course the other sysadmin didn’t think the daemon and the package were needed πŸ˜‰. Now it looks better:

## > mysql -u root
Welcome to the MariaDB monitor.
Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.68-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle,
MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help.
Type '\c' to clear the current input statement.
MariaDB [(none)]> exit
Bye

But still I can’t login. I try starting the database in safe mode and different tricks that I don’t want to write down because they didn’t work. The solution to the problem I found here: how to set change and recover a mysql password. We forgot to set the root password! This is the fix:

## > mysqladmin -u root password NEWPASSWORD
## > mysql -u root -p
Enter password:Β 

After typing NEWPASSWORD I’m in. The same goes for the phpMyadmin web… Victory!

ERROR: MediaWiki not showing up after a reboot, skin missing

The missing skin message

I like the motto If something works don’t touch it. Unfortunately in the era of CI/CD we need to touch it, and sometimes we even need to reboot it. This is what happened to me. There’s this nice MediaWiki 1.31 install that has been running since years in my team not as a docker or a fancy VM but as a real web server, with its httpd and mariadb services. I run weekly backups but I don’t update it precisely because I was afraid of it. For a reason. After a stupid power cut, when I managed to have the web server back online, I found out that the httpd and mariadb service were running but the MediaWiki was showing a Blank Page. As written on the link before, I go to my /var/www/html/ to edit the LocalSettings.php. Right at the top I copy:

error_reporting( E_ALL );
ini_set( 'display_errors', 1 );

and do systemctl restart httpd. The error instead of the Blank Page reads like this:

Fatal error: Uncaught Exception: /var/www/html/skins/MonoBook/skin.json 
does not exist! in /var/www/html/

and similar. I do check and for some weird reason (update? the other sysadmin?) the skin folder is gone. I then try to disable the skins by modifying the LocalSettings.php and restating the httpd. It works somehow. I get the wiki content unskinned, with an error on the top like this:

The wrong skin message

What to do now? I went for downloading the whole wiki zip again (the same version), copying the skins folder, uncommenting the LocalSettings.php and restating the httpd. And the wiki is back. What to do next? An invisible migration to a more reliable setup, maybe a kubernetes pod. We’ll see if I have time. Or mood. Or actually, both πŸ˜‰.

C++ interaction with database

I’m sorry but my muse seems to be missing again. And my dreams, although interesting, are not clear enough to write about them. So how about in the meantime learning a little bit more of C++? For example, have you ever wonder how it is possible to record the output of your C++ data into a database? Before we start, let me just say that I don’t think mixing up languages is a good idea. If you know mysql is for databases, python is for data, and C++ is for…objects, why don’t you write a pipeline from one to the other, instead of a language salad? So you don’t need to be an expert on everything, just on the component you handle. Anyway, here’s what I found.

The best tutorial that worked out of the box is this one of tutorialpoint. With small examples, you will learn that to handle a database you need first to connect to the database, then you need to create a table. After that, you must insert some data, that you can select afterwards if you want to print it or something. All of the examples worked on my test machine with CentOS 7.X, and mariadb up and running. Do I recommend the method? I’m not so sure. If you are a hardcore C++ you may need it (if you are a hardcore C++ you should not read this) but the code given is completely safe, with error messages and so on, so I will reccommend it. It is all thanks to #include sqlite3.h functions like sqlite3_open and sqlite3_exec that can be explained by themselves.

If you are a windows user (and a C++ user) you may find this other link from geekforgeeks of use. Now there they use another include, #include <SQLAPI.h> that is giving to the sample code a completely different feeling. More sql-oriented, if I can call it like that.

To finish with the tour you have this example from codeguru. Here you see the third player of this game, the #include <mysql.h>. I find this one quite complete, with a C++ class. I didn’t try it, but this is not meaning I can’t comment on it. The functions interfacing with the database are here mysql_real_connect, mysql_use_result, and similar that will also explain themselves by name.

Time to choose. Which one to play with? Do you have a choice? πŸ˜‚πŸ˜‚πŸ˜‚. Yes. You can do it with python…but I will leave that for the next post. Old school I am πŸ˜‰.

phpMyAdmin #2054 – The server requested authentication method unknown to the client – on Big Sur

No, unfortunately this is not an advertisement for a new movie πŸ˜€ πŸ˜€ πŸ˜€

As you know I was playing with MySQL integration on Big Sur. Right now I run Server version: 8.0.22 MySQL Community Server – GPL, that ended up in my system located on /usr/local/mysql/bin/ and I’ve installed on Β /Library/WebServer/Documents the unzipped phpMyAdmin-4.7.6-all-languages. I’m playing safe and not going for the latest phpMyAdmin, but the newest one was showing the error also (I’ve tried). The installation instructions I’ve followed are already linked in my previous post. Surprisingly I get the above error after I finish the somehow dumb installation by going to http://localhost/my-phpMyAdmin/setup.

This is somehow a beginners error. I read and read and read about the solution. This is it:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password
BY 'password';  

My password for this example will be the famous 123456. Don’t try that at home, kids! I log in as root and copy the above line, customized for my password:

user@macbookpro  ~ $ > /usr/local/mysql/bin/mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 24
Server version: 8.0.22 MySQL Community Server - GPL

mysql > ALTER USER 'root'@'localhost' IDENTIFIED WITH 123456 BY 'bestpasswordever';

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 123456 BY 'bestpasswordever'' at line 1

So how do I fix the fix? Calm down, let Google rest a little! Read again the solution. What is it? Yes, did you see it also? Correct! My line is wrong. You should not replace the mysql identificator mysql_native_password with your mysql native password πŸ˜€ πŸ˜€ πŸ˜€ . The correct one to change the login AND the mysql password to ‘bestpasswordever‘ should be:

mysql>  ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'bestpasswordever';
Query OK, 0 rows affected (0.00 sec)

I hope you had fun with my stupid struggle. Lame on you. Shame on me. BTW you can find here the original issue and then picture above.

ERROR! MySQL server PID file could not be found on OSX 11.1 Big Sur

Crazy idea. Why don’t to install phpMyAdmin on my recently updated MacBook pro Big Mac 11.1, I mean, Big Sur? I love databases and I know I can have my phpMySQL it with dockers, but later I’m having issues on Big Mac (once you start calling it that way you never stop) with my docker desktop. I don’t know, it hangs, it doesn’t want to update… disappointed. So I’ve decided to make it for real, so to say. How shall I proceed? I found a tutorial for phpMyAdmin install on Catalina (OSX 10.15), but it looks a little bit raw. I will follow a step-by-step one for Sierra, that works like a charm for a while. The apache build-in seems to still be there on Big Sur:

sudo apachectl start
httpd -v
 Server version: Apache/2.4.46 (Unix)
 Server built:   Nov 23 2020 03:38:13 

We can indeed once it is running see the famous “it works!“. Now I’m not going to repeat the configuration steps on the tutorial above mentioned. Just do it as suggested until the MySQL section. PHP works when I build the test page

<?php phpinfo(); ?>

although a funny message is displayed on the test page: PHP Version 7.3.24-(to be removed in future macOS). Thanks for the warning, guys. Time to download MySQL. On the tutorial, for Sierra it is recommended MySQL 5.7.16, but I tool of course the latest MySQL 8.0.22. Remember to choose Β» No thanks, just take me to the downloads!Β to get the dmg. Run it. Wait, we almost got it. Now try

sudo /usr/local/mysql/support-files/mysql.server stop

There it is, the error on the title! I enable root user on my mac just to try the commands directly, in case it’s some funny new sudo thing/feature, but no way, the error stays. StackOverflow has a question about this message but for Sierra, that I somehow use. I find the pid

ps aux | grep mysql

kill the process and try again, as in the stackoverflow thread.

mymac:root# 
/usr/local/mysql/support-files/mysql.server start

Starting MySQL
. SUCCESS!
mymac:root#
/usr/local/mysql/support-files/mysql.server stop

Shutting down MySQL
. SUCCESS! 

I’m happy everything is under control now. Maybe it was a long post for a simple issue. I don’t know. But I can go ahead with the phpMyAdmin thing now. Or even better, instead, I will try to escape from Earth. We’ll see what I do tomorrow πŸ˜‰