To add an auto_prepend_file PHP option in cPanel, navigate to Software > Select PHP Version, click "Switch to PHP Options," locate the auto_prepend_file setting, enter your file's full server path (like /home/username/public_html/your-file.php), click Apply, and save your changes. This configuration loads your specified PHP file before every other PHP script runs on your website.
This setting is commonly needed for WordPress security plugins that require firewall protection at the PHP level, but the same method applies for any custom PHP file you want to load automatically before your site's scripts execute.
Why Use auto_prepend_file
The auto_prepend_file directive tells PHP to automatically include a specific file before processing any PHP script on your website. This is useful for:
- Loading security firewall code before WordPress initializes
- Implementing site-wide authentication or logging
- Adding custom functions available across all PHP files
- Running performance monitoring scripts
When you configure this setting in cPanel, it applies to all PHP scripts within that hosting account or the specific directory you configure it for.
Step-by-Step Instructions for cPanel
Step 1: Get Your File Path
First, determine the full server path to the PHP file you want to prepend. If you're setting this up for a WordPress security plugin, the plugin interface will typically provide this path. It looks something like:
/home/username/public_html/your-prepend-file.php
Copy this complete path as you'll need it in the next steps.
Step 2: Access PHP Version Manager
Log into your cPanel account and follow these steps:
- Scroll to the Software section
- Click on Select PHP Version
- Wait for the PHP selector interface to load
Step 3: Navigate to PHP Options
Once inside the PHP Version interface, click the Switch to PHP Options link in the upper right corner. This will display a list of PHP configuration directives you can modify.
Step 4: Configure auto_prepend_file
Scroll through the list of PHP options until you find auto_prepend_file. The options are typically listed alphabetically. Click on the field to the right of auto_prepend_file, which will show "None" by default.
Delete "None" and paste the full server path you copied in Step 1. Make sure there are no extra spaces or characters.
Step 5: Save Your Changes
After entering the file path:
- Click the Apply button next to the auto_prepend_file option
- Scroll to the bottom of the page
- Click the Save button to confirm all changes
Your PHP configuration will update immediately.
Step 6: Verify the Configuration
Return to your website or plugin interface to verify the setting took effect. For WordPress security plugins, you should see confirmation that extended protection is now active. You can also create a test PHP file with phpinfo() to confirm the auto_prepend_file directive shows your file path.
Common Issues and Solutions
File Path Errors
If the configuration doesn't work, double-check your file path. The most common issues are:
- Missing the leading forward slash (/)
- Incorrect username in the path
- Wrong directory structure (public_html vs www vs httpdocs)
- Typos in the filename
The path must be the absolute server path, not a URL or relative path.
Permission Issues
Ensure your prepend file has the correct permissions (typically 644). If PHP can't read the file, your website may display errors or fail to load. Check file permissions through cPanel's File Manager.
Syntax Errors in Prepend File
If your website shows errors after setting auto_prepend_file, the PHP file itself may contain syntax errors. Review the file's code or temporarily remove the auto_prepend_file setting to restore your site while you troubleshoot.
Alternative Methods
While the cPanel PHP Options interface is the most user-friendly method at OBHost, you can also configure auto_prepend_file through:
- .htaccess file: Add the line php_value auto_prepend_file "/full/path/to/file.php"
- php.ini file: Add auto_prepend_file = "/full/path/to/file.php"
These methods require more technical knowledge and may not work if your server uses PHP-FPM or other PHP handlers.
Frequently Asked Questions
What happens if I enter the wrong file path?
If the file path is incorrect or the file doesn't exist, PHP will generate warnings or errors when trying to load your website. Your site may display a white screen or error messages. To fix this, return to cPanel's PHP Options and remove the auto_prepend_file setting or correct the path.
Can I use auto_prepend_file for multiple files?
No, the auto_prepend_file directive only accepts one file path. However, your prepend file can use include() or require() statements to load additional PHP files. Create one main prepend file that includes all other necessary files.
Will this setting affect all domains on my account?
In cPanel's Select PHP Version interface, the setting typically applies to the current account or domain. If you have multiple domains, you may need to configure auto_prepend_file separately for each one, or use .htaccess files in specific directories for more granular control.
How do I remove the auto_prepend_file setting?
To remove the setting, return to cPanel > Software > Select PHP Version > Switch to PHP Options, locate auto_prepend_file, delete your custom path, and enter "none" (or leave it blank). Click Apply and Save to remove the prepend file configuration.
If you need assistance configuring PHP settings or encounter any issues with auto_prepend_file, our support team is available 24/7. Visit https://www.obhost.net/contact or email support@obhost.org for help.