danielbrendel / hortusfox-web

Self-hosted collaborative plant management and tracking system for plant enthusiasts
https://www.hortusfox.com
MIT License
674 stars 34 forks source link

Upgrade to PHP 8.3 #200

Closed danielbrendel closed 4 months ago

danielbrendel commented 6 months ago

Upgrade product to PHP 8.3.

brianw777 commented 5 months ago

I am trying to install hortusfox-web and get a PHP error when it comes to creating "ChatMsgModel_Migration"

Would this be a result of having php8.3 installed?

Creating "ChatMsgModel_Migration" PHP Fatal error: Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 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 'system BOOLEAN NOT NULL DEFAULT 0, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAM' at line 1 in /var/www/html/hortusfox-web-main/vendor/danielbrendel/asatru-php-framework/src/database.php:354 Stack trace:

0 /var/www/html/hortusfox-web-main/vendor/danielbrendel/asatru-php-framework/src/database.php(354): PDO->exec()

1 /var/www/html/hortusfox-web-main/app/migrations/ChatMsgModel.php(35): Asatru\Database\Migration->create()

2 [internal function]: ChatMsgModel_Migration->up()

3 /var/www/html/hortusfox-web-main/vendor/danielbrendel/asatru-php-framework/src/database.php(1131): call_user_func()

4 /var/www/html/hortusfox-web-main/vendor/danielbrendel/asatru-php-framework/src/database.php(1231): Asatru\Database\MigrationLoader->createAll()

5 /var/www/html/hortusfox-web-main/vendor/danielbrendel/asatru-php-framework/src/console.php(1157): migrate_fresh()

6 /var/www/html/hortusfox-web-main/asatru(56): Asatru\Console\handleInput()

7 {main}

thrown in /var/www/html/hortusfox-web-main/vendor/danielbrendel/asatru-php-framework/src/database.php on line 354

Server details

OS Ubuntu server 24.04

uname -a Linux mymedia 6.8.0-35-generic #35-Ubuntu SMP PREEMPT_DYNAMIC Mon May 20 15:51:52 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

cat /etc/lsb-release DISTRIB_ID=Ubuntu DISTRIB_RELEASE=24.04 DISTRIB_CODENAME=noble DISTRIB_DESCRIPTION="Ubuntu 24.04 LTS"

PHP 8.3.7

php --version PHP 8.3.7 (cli) (built: May 23 2024 12:36:54) (NTS) Copyright (c) The PHP Group Zend Engine v4.3.7, Copyright (c) Zend Technologies with Zend OPcache v8.3.7, Copyright (c), by Zend Technologies

MySQL 8.0.36-2ubuntu3

mysql --version mysql Ver 8.0.36-2ubuntu3 for Linux on x86_64 ((Ubuntu))

Composer version 2.7.1

composer --version Composer version 2.7.1 2024-02-09 15:26:28

brianw777 commented 5 months ago

I tried to downgrade to php8.2 but I get the following error immediately without any of the database created. At least with php8.3 there were many create lines shown then failed on the ChatMsgModel.

php asatru migrate:fresh PHP Fatal error: Uncaught PDOException: could not find driver in /var/www/html/hortusfox-web-main/vendor/danielbrendel/asatru-php-framework/src/database.php:1198 Stack trace:

0 /var/www/html/hortusfox-web-main/vendor/danielbrendel/asatru-php-framework/src/database.php(1198): PDO->__construct()

1 /var/www/html/hortusfox-web-main/asatru(49): require_once('...')

2 {main}

thrown in /var/www/html/hortusfox-web-main/vendor/danielbrendel/asatru-php-framework/src/database.php on line 1198

PHP version: php -v PHP 8.2.20 (cli) (built: Jun 6 2024 16:56:27) (NTS) Copyright (c) The PHP Group Zend Engine v4.2.20, Copyright (c) Zend Technologies with Zend OPcache v8.2.20, Copyright (c), by Zend Technologies

danielbrendel commented 5 months ago

Hi,

the error could not find driver indicates that the pdo_mysql driver is not enabled. Can you check whether you have it enabled or not?

Regarding the MySQL syntax error: This seems to be a version/derivative specific problem. You might want to share your altered docker files, so I can try to reproduce it on my end.

Kind regards

Message ID: @.***>

brianw777 commented 5 months ago

Thank you for the reply.

I will check the pdo_mysql thing and give php8.2 a try but it may be that my testing system won't work on php8.2 now. Every time I try to install any php related things like composer or php-fpm it always installs the php8.3. I will have another look later. I did find some articles on this issue so I can have a look.

As for the php8.3 mysql syntax error this is not a docker install it is a manual install as per the github main page. I may have to wait for the upgrade to v3.2 if php8.3 is going to be implemented and have another look at it. Or I may just take my server machine and reinstall the OS and start from scratch (it is a new server I am setting up so won't be too much trouble).

Thanks again for the quick reply

brianw777 commented 5 months ago

So I was looking into this a little more and started searching the database models to see if I could find why it would fail on that specific data creation. What I found was that there may be an error in the ChatMsgModel.php file. I searched for the line causing the issue "system BOOLEAN NOT NULL DEFAULT 0" but I shortened it to just "system BOOLEAN" to see if any other files had that and the results were:

grep -ri "system BOOLEAN" * app/migrations/AppModel.php: $this->database->add('chat_system BOOLEAN NOT NULL DEFAULT 1'); app/migrations/ChatMsgModel.php: $this->database->add('system BOOLEAN NOT NULL DEFAULT 0');

I assumed the word "system" was the problem so changed it to "chat_system":

grep -ri "system BOOLEAN" * app/migrations/AppModel.php: $this->database->add('chat_system BOOLEAN NOT NULL DEFAULT 1'); app/migrations/ChatMsgModel.php: $this->database->add('chat_system BOOLEAN NOT NULL DEFAULT 0');

After the change in the file app/migrations/ChatMsgModel.ph the database migration went through without any errors.

I haven't went any further yet it is late so I will see if I can get it going when I have some more time.

If my change is incorrect please let me know whenever you get a chance, thanks.

Regards, Brian

danielbrendel commented 5 months ago

Seems to be that system is treated as a reserved word: https://dev.mysql.com/doc/refman/8.4/en/keywords.html#keywords-8-4-detailed-S

I will add a fix for that. Until that you would need to change every reference to that in the code.

Sorry for the inconvenience!

brianw777 commented 5 months ago

Thanks. I was thinking it had become a reserved word and I would need to search for every reference and change it. I got thinking after I posted it was probably that reason. The only reason I didn't get any errors during the DB migration was because I changed that instance to a non reserved word but it wouldn't work because all the other references would still be the word "system".

Thanks for confirming that for me.

Regards, Brian

brianw777 commented 5 months ago

So just to let you know I made the changes in the code and was able to continue on with the installation. Once I figured out how to change the server from localhost to the ip address of the headless server I am testing on I created a user and was able to log in. I haven't went any farther yet but I was able to log in.

Thanks for all your help.

Regards, Brian

danielbrendel commented 5 months ago

That's great! At this point it should most likely work without further problems. Setup is the hardest part. 😅 The new version will be released next month and will include the fix as well.