Question

How can I create txt file using php apache?

I’m trying to create txt file on fly using php fopen but unable to create it for unknown reason.


Submit an answer


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!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

alexdo
Site Moderator
Site Moderator badge
February 12, 2023

Hello @pranavkiritkumarsuchak

Just to add on what has already been mentioned, you can also check for any generated PHP error_log files in the directory where the .txt file is supposed to be created. This might point in the right direction as well.

Regards

KFSys
Site Moderator
Site Moderator badge
February 12, 2023

Hey @pranavkiritkumarsuchak,

I’m sure the problem is with permissions. Apart from what Bobby has already mentioned I’ll recommend you to check the SELINUX of your Ubuntu.

You can check this tutorial for more information:

https://www.digitalocean.com/community/tutorials/what-is-selinux

Bobby Iliev
Site Moderator
Site Moderator badge
February 10, 2023

Hi there,

You would need to make sure that the Apache user has access to create files in your web root directory.

By default Apache runs as the www-data user so you could use: sudo chown www-data /var/www/html to change the owner of the directory where you want to create your file at.

If this still does not work, I would recommend checking your Apache error log for mre infomration on why this is failing:

tail -100 /var/log/apache2/error.log

Let me know how it goes!

Best,

Bobby

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

card icon
Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Sign up
card icon
Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We’d like to help.

Learn more
card icon
Become a contributor

You get paid; we donate to tech nonprofits.

Learn more
Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow – whether you’re running one virtual machine or ten thousand.

Learn more ->
DigitalOcean Cloud Control Panel
Get started for free

Enter your email to get $200 in credit for your first 60 days with DigitalOcean.

New accounts only. By submitting your email you agree to our Privacy Policy.

© 2023 DigitalOcean, LLC.