Running php file with php


I am trying to do automatic database backup
website home directory


The above file will be checked from time to time and when the backup time comes “backup.php” will run the file
Admin panel directory


I have a few questions here

  1. admin panel directory encrypted
  2. I need to send data from run_backup.php to backup.php via post

How to run the backup.php file in the administration panel, whose directory is encrypted, using run_backup.php in the home directory?

Your description is not clear. Do you mean you want to back up the database automatically?
Then, just use a CRON job which is just a simple PHP file that can create the backup for you.
Then, the other system can copy that file as needed. You would not want to use a post system to transfer your database. And, you would NOT care about encryption at all. If you have access to your database on the system is it hosted on, then you can use standard PHP/MySQL commands to back it up.

Here is a simple example:

$filename = 'Adem_database_backup_' . date('Y-m-d') . '.sql';
$result = exec('mysqldump DATABASE-NAME -u USER-NAME -p PASSWORD > ' . $filename);

This will create a full backup file of your database. You can alter this to just backup one table. There are many other ways to backup database tables, but, this is the easiest, in my humble opinion!
*** You have to enter your database name, the user and password for the database. Once this process is completed, you can transfer the file to the other machine using FTP if needed.

I hope this is what you are asking about.

( Oh, note I added the date-timestamp in the filename. This will not overwrite older backups, you may not want that to happen. You might want to remove the timestamp so it overwrites the backup file each time.)

Didn’t know MySQL backup was this easy.
good to know that.

There is a CRON job that I wrote amateurly and it provides the opportunity to schedule tasks from the administration panel.
Here you can set the time when the exchange rates will update.
Again, you can specify the backup time of the entire database or the tables to be selected from here.

So far it works flawlessly
The question is:
The file “backup.php” is in the directory where the directory is encrypted and the directory password is preventing me from accessing this file.
To prevent access to encrypted directory
Actually it is unreasonable to access the Encrypted directory

The reason the “backup.php” file is in the encrypted directory is because the database backups are in the encrypted directory

Well, just change the file to push it to a non-encrypted folder. Just change the $filename to point to a different location loosely like this…

$filename = '/public_html/Adem/backup_.sql';

Or whatever works for your server’s folder layout. Starting with a slash / will start at the root of the server, or, just create a new folder that is not encrypted and point to that. Normally, I would use the first way with the date included. And, in a non-encrypted folder. Then, in another program that is for just the ADMIN to use, you can review backups and delete old ones. Normally, you keep three backups and remove the oldest one when you create a new one. This makes sure you can go back three levels if needed. Normally, three monthly backups is enough so you can go back three months if needed.
Should work !

Thank you for this very good and useful information.
This way you gave me an idea, thank you

Benim sorum şu
My question is: Is it possible to run a file in the encrypted directory?

admin” directory encrypted

Is it possible with cURL or something else?

Well, encryption is a complicated discussion for here. But, encryption is used to protect the files on a server. And, encryption can be set up with different levels of access permissions. What this means is that most web systems that need to be encrypted can be set up for the server itself to use the files and not other users. Therefore, on the server, most things continue as normal. Meaning that, yes, you can run files in encrypted folders as long as it was set up to allow the server to do so. Usually, the files can not be accessed directly from outside sources like browsers or FTP clients.

Encryption is dangerous in several ways. If the access gets denied from a glitch on the server, then everything is gone since it can not be accessed. There are ways to protect folders without encrypting them. What do you have on the admin folder that needs to be protected by encryption? Just curious!

Add, edit, Delete products
Member management
Backup and restore database
Settings, blah blah blah
That’s why I’m encrypting the admin directory
Maybe not necessary but I don’t know.

No, it is NOT needed. All of those items have to do with your database and nothing to do with a folder on the server. Normally, you just have your database secured with a user-ID and password. That is step one. Next, you do not let anyone access the database from the outside. This means that all of your connection code that let’s you link to the database needs to make sure the accesses are coming from your server only.
When you set up a folder on your server, you set access-permissions. They are handled using FTP or other client that lets you set the values to the folder itself. Such as 777 which gives full access to the folder. You can restrict folder access to just your own server. This means that people outside your website can not even see the folder and can never access it.
It is NOT encryption. Encryption would be used if you were worried about someone having access to the server’s hardware and might be able to copy your files out of the hard disk on the server.
Encryption is not what you think it is for. Just secure your server’s folders, you must set the access-permissions on every folder. Except for public folders where you want to allow users to upload files to.

1 Like

Got it, thank you very much

Sponsor our Newsletter | Privacy Policy | Terms of Service