I am facing severe issues after I moved a website from a shared server to VPS. I am not sure if its due to more secure settings or so.
This App build on MySQL + PHP + Angular 9 fails to retrieve simple queries. It works find on my localhost, old server, etc. But on the new VPS, I need to substring the field to 20 chars or LIMIT output to 500 rows etc.
OS Linux
Apache Version 2.4.57
MySQL Version 5.7.43
PHP 7.4
Slim Framwork 4.4
Sample:
FAILS: SELECT item_Id, sales_Description AS sales_Description FROM item_master
SUCCESS: SELECT item_Id, SUBSRING(sales_Description, 1, 20) AS sales_Description FROM item_master
SUCCESS: SELECT item_Id, sales_Description AS sales_Description FROM item_master LIMIT 400
Actual Code:
$ItemsSource = "SELECT `item_Id`, SUBSTRING(`sales_Description`, 1, 120) AS sales_Description
FROM `item_master`
WHERE `StatusId1` <> 4 AND `Is_Assembly` = 'No'
AND (`sales_Description` IS NOT NULL AND `sales_Description` <> '')
ORDER BY `sales_Description` LIMIT 500 ";
$stmt = $this->db->prepare($ItemsSource);
$stmt->execute();
$count = $stmt->rowcount();
$assembly_specification = $stmt->fetchAll();
if (!empty($assembly_specification)) {
$payload = ['status' => 'ok', 'list_data' => $assembly_specification];
} else {
$payload = ['status' => 'fail', 'msg' => list data not found!'];
}
$response->getBody()->write(json_encode($payload));
return $response
->withHeader('Content-Type', 'application/json')
->withStatus(201);
Your issue seems related to the configuration or resource limitations on the new VPS.
It might be running out of memory or CPU which can lead to different failures.
Check the VPS php.ini for memory and execution time limits:
memory_limit = 256M
max_execution_time = 300
You might need to adjust these values based on the data size you’re working with
Make sure error reporting is turned on for PHP. Add these lines to the beginning of your PHP script temporarily:
As instructed, I enabled exceptions for PDO. Copied the options variable and included same in new PDO connection. I would be also happy to know, where can we view the errors displayed.
As soon as a (database) error occurs, the exception error message should be displayed.
If there is no error with the query itself, the problem is somewhere else.