Hello! When I try a simple fopen(“hello.txt”, “w”) it doesn’t do anything at all. I changed to full permissions 777 and changed around the owner to root and different ones and nothing. I added var_dump and echoed the fopen and it gives me False(bool). I checked the fopen configuration in the php.ini file and it is enabled. Any help??
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
What are you trying to do?
The “w” in fopen(“hello.txt”,“w”) means to write to a file, not read. It would be best to read the PHP documentation on fopen().
http://php.net/manual/en/function.fopen.php
Lots of examples! Hope that helps, let me know if I can help more.
This comment has been deleted
open_basedir Restriction:If open_basedir is set in php.ini, it restricts PHP from accessing files outside of specified directories. Check if it’s enabled:
php -i | grep open_basedir
If it’s set, either disable it by removing or commenting the open_basedir directive in php.ini, or add the path to your directory:
open_basedir = /path/to/your/allowed/directories
Make sure the user under which your web server (likely www-data or apache) runs has write permissions to the directory where hello.txt is being created.
To check the current user running the web server:
ps aux | grep apache # or httpd on CentOS
Then, ensure that the directory where you’re trying to create the file has the correct ownership and permissions:
sudo chown www-data:www-data /path/to/your/directory
sudo chmod 755 /path/to/your/directory
Sometimes, the failure could be caused by a lack of disk space or quota issues. Check the available disk space:
df -h
If you’re running a system like CentOS with SELinux enabled, SELinux could be preventing PHP from writing to certain directories. Temporarily disable SELinux to check if it’s causing the issue:
sudo setenforce 0
If this fixes the problem, you can either adjust the SELinux policies or leave it in permissive mode.
Check the PHP or Apache error logs for more detailed information about the failure. You can find logs in the following locations:
tail -f /var/log/apache2/error.log # For Apache on Ubuntu/Debian
tail -f /var/log/httpd/error_log # For Apache on CentOS/RedHat
Look for any relevant errors related to file permissions or fopen.
disable_functions in php.ini:Ensure that fopen is not disabled in the php.ini file under the disable_functions directive. Check if it’s listed:
php -i | grep disable_functions
If fopen is listed, remove it from the disable_functions directive and restart your web server:
sudo systemctl restart apache2 # Or php-fpm depending on your setup
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.