This script performs automatic backup of PHP and Nginx configuration files, then hides the version information of PHP and Nginx to enhance security.
- Automatically detects the installed PHP version.
- Backs up the PHP FPM and CLI configuration files.
- Backs up all Nginx configuration files in
/etc/nginx/sites-enabled/*.conf
. - Modifies the PHP configuration to hide the PHP version.
- Modifies the Nginx configuration files to hide the Nginx version.
- Backs up the script itself before making any changes.
- Restarts the necessary services to apply changes.
- Bash shell
- PHP
- Nginx
- Sudo privileges
-
Clone this repository to your local machine.
git clone https://github.com/Sincan2/Backup-and-Hide-PHP-NGinx-Versions-Script.git cd Backup-and-Hide-PHP-NGinx-Versions-Script
-
Modify the script to set the backup directory if needed. The default backup directory is
/root/backup
. -
Make the script executable.
chmod +x 1.sh
-
Run the script with sudo privileges.
sudo ./1.sh
The script performs the following steps:
- Creates a backup directory if it does not exist.
- Backs up the PHP FPM configuration file (
php.ini
). - Backs up the PHP CLI configuration file (
php.ini
). - Backs up all Nginx configuration files in
/etc/nginx/sites-enabled/*.conf
. - Backs up the script itself.
- Modifies the PHP FPM and CLI configuration files to set
expose_php = Off
. - Modifies all Nginx configuration files in
/etc/nginx/sites-enabled/*.conf
to addserver_tokens off;
inside theserver {}
block. - Restarts PHP FPM and Nginx services to apply the changes.
- Ensure you have the necessary permissions to read, write, and execute the files and directories involved.
- Test the script in a staging environment before running it in production to avoid any unintended disruptions.
This project is licensed under the MIT License - see the LICENSE file for details.