PHP site database connection

I also have a PHP site running on my virtual server, this PHP site was also migrated over from cPanel along with everything else.

cPanel was using PHP version 5.6.38 whereas Virtualmin is using PHP 7.2.24

Ever since I migrated to Virtualmin, this PHP site can no longer connect to the database. I checked the connection string in the PHP code and used the same username and password in MySQL workbench, it is working fine there. So I’m guessing it has something to do with the PHP version?

Hi,

There is no reason to guess, look at the logs but at first make sure that you have php-mysql package installed.

Thanks @Ilia , I verified that php-mysql package is installed and I found the problem in the error logs, it is configuration from cPanel earlier that is causing the problems, here is what the error message is:

[Tue Feb 25 19:22:38.030380 2020] [fcgid:warn] [pid 7475] [client 183.90.37.221:10971] mod_fcgid: stderr: PHP Warning: session_start(): open(/var/cpanel/php/sessions/ea-php56/sess_mt8kudd88p8s01qvmidc92t6nt, O_RDWR) failed: No such file or directory (2) in /home/snatch/public_html/admin/login-page.php on line 2, referer: https://snatch.com/admin/login-page.php

[Tue Feb 25 19:22:38.030411 2020] [fcgid:warn] [pid 7475] [client 183.90.37.221:10971] mod_fcgid: stderr: PHP Warning: session_start(): Failed to read session data: files (path: /var/cpanel/php/sessions/ea-php56) in /home/snatch/public_html/admin/login-page.php on line 2, referer: https://snatch.com/admin/login-page.php

Also here is the content of my php.ini file, it is referring to a session directory from cPanel, any idea what I should change it to?:

; cPanel-generated php ini directives, do not edit
; Manual editing of this file may result in unexpected behavior.
; To make changes to this file, use the cPanel MultiPHP INI Editor (Home >> Software >> MultiPHP INI Editor)
; For more information, read our documentation (https://go.cpanel.net/EA4ModifyINI)

asp_tags = Off
display_errors = Off
max_execution_time = 300
max_input_time = 600
max_input_vars = 1000
memory_limit = 2048M
post_max_size = 2048M
session.gc_maxlifetime = 1440
session.save_path = "/var/cpanel/php/sessions/ea-php56"
upload_max_filesize = 20M
zlib.output_compression = Off

As a temporary solution i have just created the directory /var/cpanel/php/sessions/ea-php56 on my server and gave it chmod 777 permissions.

I think not the best solution, but for now my site is finally working.

Anything better than the above workaround will be most welcome.

Yes, just put this inside of your webserver root and outside of public_html. You could put it also inside of public_html but make sure to deny anyone accessing it.

Like creating .htaccess with contents:

<Files *>
	Require all denied
</Files>

@Ilia thanks again! Did the above and all working fine.