Got a bit of a specific problem here. I’m in the process of developing an automated script in PHP to aid in the creation of a demonstration web application in the event a customer wants a demo site setup.
I’m using a dedicated server running Plesk.
My intention is to create a new sub-domain, create a new database, copy the database from elsewhere, copy the site files from another folder and finally email the customer with their login credentials, etc.
I’m using the Plesk API RPC to create the sub-domain, database and database user which is all working perfectly. I have the database copying the schema from elsewhere and I have the email part working. The only part that is eluding me is the copying of the files from one folder to another.
The source folder is within the same ‘httpdocs’ folder as the destination folder. The initial problem I had was the open_basedir issue which I’ve rectified but now I’ve got the permission denied problem.
I know I can’t chmod with windows.
I’ve tried using xcopy via exec() which returns
string(13) "Access denied"
I’ve also tried both cacls and icacls, both of which give me a similar error of
string(57) "Successfully processed 0 files; Failed processing 1 files"
Short of giving the whole httpdocs folder write permissions I’m at a bit of a loss on how best to further approach this. Any advice/help would be much appreciated.
2
Answers
I managed to solve my predicament using the following code;
The first line sets full permissions for the chosen username on the destination folder.
The second line uses xcopy to copy all folders and subfolders, even empty ones from the source folder to the destination folder.
The third line resets the permissions for the destination folder back to read and execute only.
This script is works for me:
You can use xcopy:
But not in all cases:
Also you can use icacls:
You can even disable inheretence: