This creates the database but the status shows as (Restoring....) and never completes.
ChatGPT gave me some suggestions, but I have not found an answer as of yet.
You seem to be using Windows paths. On linux you probably need to take the backup from something like /var/opt/mssql/backup and restore to something like /var/opt/mssql/data/ and /var/opt/mssql/log/.
How are you checking the db is in the restoring state. If using SSMS you need to right-click to refresh the database list.
You do not explicitly state RECOVERY in your SP so maybe the defaults are different when calling the SP from PHP. Try something like:
USE paincommon;
GO
SET ANSI_NULLS, QUOTED_IDENTIFIER ON;
GO
CREATE OR ALTER PROCEDURE [dbo].[instantiate_database]
@dbname sysname
AS
SET NOCOUNT, XACT_ABORT ON;
IF @dbname LIKE '%[^a-zA-Z0-9_]%'
RETURN;
DECLARE @sql nvarchar(MAX);
SET @sql = CONCAT(
N'RESTORE DATABASE ', QUOTENAME(@dbName) ,N'
FROM DISK = ''/var/opt/mssql/data/Template.bak''
WITH RECOVERY, REPLACE
,MOVE ''Commercial'' TO ''/var/opt/mssql/data/', @dbName, N'.mdf''
,MOVE ''Commercial_Log'' TO ''/var/opt/mssql/data/', @dbName, N'.ldf'';')
--print @sql;
EXEC sp_executesql @sql;
GO
With the limited information you have provided, this is as far as I can go. If running a proc like this you will need to be very careful with permissions to stop injection attacks.
Msg 4333, Level 16, State 1, Line 2
The database cannot be recovered because the log was not restored.
Msg 3013, Level 16, State 1, Line 2
RESTORE DATABASE is terminating abnormally.
You need to do some divide an conquer problem solving to find out why the log was not restored. Maybe another online db has the same log file name so it cannot be overwritten. Maybe the backup is corrupt etc