Apache not allowing PHP to create fileChanging folder permissions to enable PHP to create a fileCan SELinux...

Why do distances seem to matter in the Foundation world?

How can I practically buy stocks?

A strange hotel

Initiative: Do I lose my attack/action if my target moves or dies before my turn in combat?

Checks user level and limit the data before saving it to mongoDB

Phrase for the opposite of "foolproof"

Classification of surfaces

How did Captain America manage to do this?

How to denote matrix elements succinctly?

How to display Aura JS Errors Lightning Out

Check if a string is entirely made of the same substring

I preordered a game on my Xbox while on the home screen of my friend's account. Which of us owns the game?

Can I grease a crank spindle/bracket without disassembling the crank set?

Does tea made with boiling water cool faster than tea made with boiled (but still hot) water?

Can someone publish a story that happened to you?

What is the most expensive material in the world that could be used to create Pun-Pun's lute?

Two field separators (colon and space) in awk

Is Diceware more secure than a long passphrase?

Re-entry to Germany after vacation using blue card

"The cow" OR "a cow" OR "cows" in this context

What's the polite way to say "I need to urinate"?

What are the steps to solving this definite integral?

Like totally amazing interchangeable sister outfits II: The Revenge

Apply MapThread to all but one variable



Apache not allowing PHP to create file


Changing folder permissions to enable PHP to create a fileCan SELinux Affect ApacheApache PHP not working after UpdateSuPHP: PHP 403 ErrorDocument in Apache won't workCannot create file in /var/www/htmlHow to display .php pages?Where do I put backend PHP files on Apache?php file not running in apache 2PHP is not working on ubuntu 14phpmyadmin installed but the page not rendered correctly by phpcant run php file






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







2















I am trying to save data using HTML and PHP in localhost in Ubuntu. My HTML & PHP files are working great but when I am using commands to open a file in the localhost using



$myfile = fopen("testfile.txt", "w")


it does not allow it to create it, but the PHP file is working and when set with commands to output variables from PHP it works well.



How to permit PHP to create files in Apache in localhost Ubuntu.










share|improve this question

























  • Does the user running the web server have write privileges on this file (if existing) or on the containing folder (if creating a new file)? That user also needs directory traversal privileges on all recursively containing directories.

    – David Foerster
    May 24 '15 at 8:54











  • My question refers to that only i believe that - how do I set my apache2 to allow writing new files that php creates?

    – Moithil Biswas
    May 24 '15 at 10:39











  • It's not just a question of Apache configuration, but also of file system permissions, since you want Apache to write in the file system.

    – David Foerster
    May 24 '15 at 12:50











  • ok, i am having issues with usage of this forum, I mean why am i getting voted down for a question that i find relevant with Ubuntu. My problem is solved but still I am being prompted for getting low quality response for my question.

    – Moithil Biswas
    May 31 '15 at 17:05






  • 1





    See How do I ask a good question? and What topics can I ask about here? for possible reasons. People are currently voting this as off topic, which I can only explain plausibly, because it may be appear to be about PHP programming and not Ubuntu web server administration on first sight. The downvotes may result from the lack of necessary, requested information in your question to track down the cause of the problem. If you want to know more, open a question on Meta.AU.

    – David Foerster
    May 31 '15 at 20:14




















2















I am trying to save data using HTML and PHP in localhost in Ubuntu. My HTML & PHP files are working great but when I am using commands to open a file in the localhost using



$myfile = fopen("testfile.txt", "w")


it does not allow it to create it, but the PHP file is working and when set with commands to output variables from PHP it works well.



How to permit PHP to create files in Apache in localhost Ubuntu.










share|improve this question

























  • Does the user running the web server have write privileges on this file (if existing) or on the containing folder (if creating a new file)? That user also needs directory traversal privileges on all recursively containing directories.

    – David Foerster
    May 24 '15 at 8:54











  • My question refers to that only i believe that - how do I set my apache2 to allow writing new files that php creates?

    – Moithil Biswas
    May 24 '15 at 10:39











  • It's not just a question of Apache configuration, but also of file system permissions, since you want Apache to write in the file system.

    – David Foerster
    May 24 '15 at 12:50











  • ok, i am having issues with usage of this forum, I mean why am i getting voted down for a question that i find relevant with Ubuntu. My problem is solved but still I am being prompted for getting low quality response for my question.

    – Moithil Biswas
    May 31 '15 at 17:05






  • 1





    See How do I ask a good question? and What topics can I ask about here? for possible reasons. People are currently voting this as off topic, which I can only explain plausibly, because it may be appear to be about PHP programming and not Ubuntu web server administration on first sight. The downvotes may result from the lack of necessary, requested information in your question to track down the cause of the problem. If you want to know more, open a question on Meta.AU.

    – David Foerster
    May 31 '15 at 20:14
















2












2








2








I am trying to save data using HTML and PHP in localhost in Ubuntu. My HTML & PHP files are working great but when I am using commands to open a file in the localhost using



$myfile = fopen("testfile.txt", "w")


it does not allow it to create it, but the PHP file is working and when set with commands to output variables from PHP it works well.



How to permit PHP to create files in Apache in localhost Ubuntu.










share|improve this question
















I am trying to save data using HTML and PHP in localhost in Ubuntu. My HTML & PHP files are working great but when I am using commands to open a file in the localhost using



$myfile = fopen("testfile.txt", "w")


it does not allow it to create it, but the PHP file is working and when set with commands to output variables from PHP it works well.



How to permit PHP to create files in Apache in localhost Ubuntu.







apache2 php webserver localhost






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 31 '15 at 20:05









David Foerster

28.7k1367113




28.7k1367113










asked May 11 '15 at 18:31









Moithil BiswasMoithil Biswas

5961512




5961512













  • Does the user running the web server have write privileges on this file (if existing) or on the containing folder (if creating a new file)? That user also needs directory traversal privileges on all recursively containing directories.

    – David Foerster
    May 24 '15 at 8:54











  • My question refers to that only i believe that - how do I set my apache2 to allow writing new files that php creates?

    – Moithil Biswas
    May 24 '15 at 10:39











  • It's not just a question of Apache configuration, but also of file system permissions, since you want Apache to write in the file system.

    – David Foerster
    May 24 '15 at 12:50











  • ok, i am having issues with usage of this forum, I mean why am i getting voted down for a question that i find relevant with Ubuntu. My problem is solved but still I am being prompted for getting low quality response for my question.

    – Moithil Biswas
    May 31 '15 at 17:05






  • 1





    See How do I ask a good question? and What topics can I ask about here? for possible reasons. People are currently voting this as off topic, which I can only explain plausibly, because it may be appear to be about PHP programming and not Ubuntu web server administration on first sight. The downvotes may result from the lack of necessary, requested information in your question to track down the cause of the problem. If you want to know more, open a question on Meta.AU.

    – David Foerster
    May 31 '15 at 20:14





















  • Does the user running the web server have write privileges on this file (if existing) or on the containing folder (if creating a new file)? That user also needs directory traversal privileges on all recursively containing directories.

    – David Foerster
    May 24 '15 at 8:54











  • My question refers to that only i believe that - how do I set my apache2 to allow writing new files that php creates?

    – Moithil Biswas
    May 24 '15 at 10:39











  • It's not just a question of Apache configuration, but also of file system permissions, since you want Apache to write in the file system.

    – David Foerster
    May 24 '15 at 12:50











  • ok, i am having issues with usage of this forum, I mean why am i getting voted down for a question that i find relevant with Ubuntu. My problem is solved but still I am being prompted for getting low quality response for my question.

    – Moithil Biswas
    May 31 '15 at 17:05






  • 1





    See How do I ask a good question? and What topics can I ask about here? for possible reasons. People are currently voting this as off topic, which I can only explain plausibly, because it may be appear to be about PHP programming and not Ubuntu web server administration on first sight. The downvotes may result from the lack of necessary, requested information in your question to track down the cause of the problem. If you want to know more, open a question on Meta.AU.

    – David Foerster
    May 31 '15 at 20:14



















Does the user running the web server have write privileges on this file (if existing) or on the containing folder (if creating a new file)? That user also needs directory traversal privileges on all recursively containing directories.

– David Foerster
May 24 '15 at 8:54





Does the user running the web server have write privileges on this file (if existing) or on the containing folder (if creating a new file)? That user also needs directory traversal privileges on all recursively containing directories.

– David Foerster
May 24 '15 at 8:54













My question refers to that only i believe that - how do I set my apache2 to allow writing new files that php creates?

– Moithil Biswas
May 24 '15 at 10:39





My question refers to that only i believe that - how do I set my apache2 to allow writing new files that php creates?

– Moithil Biswas
May 24 '15 at 10:39













It's not just a question of Apache configuration, but also of file system permissions, since you want Apache to write in the file system.

– David Foerster
May 24 '15 at 12:50





It's not just a question of Apache configuration, but also of file system permissions, since you want Apache to write in the file system.

– David Foerster
May 24 '15 at 12:50













ok, i am having issues with usage of this forum, I mean why am i getting voted down for a question that i find relevant with Ubuntu. My problem is solved but still I am being prompted for getting low quality response for my question.

– Moithil Biswas
May 31 '15 at 17:05





ok, i am having issues with usage of this forum, I mean why am i getting voted down for a question that i find relevant with Ubuntu. My problem is solved but still I am being prompted for getting low quality response for my question.

– Moithil Biswas
May 31 '15 at 17:05




1




1





See How do I ask a good question? and What topics can I ask about here? for possible reasons. People are currently voting this as off topic, which I can only explain plausibly, because it may be appear to be about PHP programming and not Ubuntu web server administration on first sight. The downvotes may result from the lack of necessary, requested information in your question to track down the cause of the problem. If you want to know more, open a question on Meta.AU.

– David Foerster
May 31 '15 at 20:14







See How do I ask a good question? and What topics can I ask about here? for possible reasons. People are currently voting this as off topic, which I can only explain plausibly, because it may be appear to be about PHP programming and not Ubuntu web server administration on first sight. The downvotes may result from the lack of necessary, requested information in your question to track down the cause of the problem. If you want to know more, open a question on Meta.AU.

– David Foerster
May 31 '15 at 20:14












3 Answers
3






active

oldest

votes


















4














You must allow the Apache user (usually www-data) to create files in that directory. This can be accomplished by making Apache the owner of the directory, for example, if the directory were called my-dir, you would open a terminal and run this:



sudo chown www-data my-dir





share|improve this answer

































    1














    If you want to change all the folders and files within that directory, and not just the directory, add -R like so



    sudo chown -R www-data my-dir





    share|improve this answer































      0














      as stated on the Apache2 Ubuntu Default Page: By default, Ubuntu does not allow access through the web browser to any file apart of those located in /var/www .... This means that any directory or file you want to write to must be under /var/www. Missed this info myself and got my hair pulling for a while trying to write to /tmp etc.






      share|improve this answer








      New contributor




      markus-hb is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





















        Your Answer








        StackExchange.ready(function() {
        var channelOptions = {
        tags: "".split(" "),
        id: "89"
        };
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function() {
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled) {
        StackExchange.using("snippets", function() {
        createEditor();
        });
        }
        else {
        createEditor();
        }
        });

        function createEditor() {
        StackExchange.prepareEditor({
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: true,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        bindNavPrevention: true,
        postfix: "",
        imageUploader: {
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        },
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        });


        }
        });














        draft saved

        draft discarded


















        StackExchange.ready(
        function () {
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f622426%2fapache-not-allowing-php-to-create-file%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        4














        You must allow the Apache user (usually www-data) to create files in that directory. This can be accomplished by making Apache the owner of the directory, for example, if the directory were called my-dir, you would open a terminal and run this:



        sudo chown www-data my-dir





        share|improve this answer






























          4














          You must allow the Apache user (usually www-data) to create files in that directory. This can be accomplished by making Apache the owner of the directory, for example, if the directory were called my-dir, you would open a terminal and run this:



          sudo chown www-data my-dir





          share|improve this answer




























            4












            4








            4







            You must allow the Apache user (usually www-data) to create files in that directory. This can be accomplished by making Apache the owner of the directory, for example, if the directory were called my-dir, you would open a terminal and run this:



            sudo chown www-data my-dir





            share|improve this answer















            You must allow the Apache user (usually www-data) to create files in that directory. This can be accomplished by making Apache the owner of the directory, for example, if the directory were called my-dir, you would open a terminal and run this:



            sudo chown www-data my-dir






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited May 31 '15 at 20:06









            David Foerster

            28.7k1367113




            28.7k1367113










            answered May 11 '15 at 18:48









            Quentin SkousenQuentin Skousen

            167314




            167314

























                1














                If you want to change all the folders and files within that directory, and not just the directory, add -R like so



                sudo chown -R www-data my-dir





                share|improve this answer




























                  1














                  If you want to change all the folders and files within that directory, and not just the directory, add -R like so



                  sudo chown -R www-data my-dir





                  share|improve this answer


























                    1












                    1








                    1







                    If you want to change all the folders and files within that directory, and not just the directory, add -R like so



                    sudo chown -R www-data my-dir





                    share|improve this answer













                    If you want to change all the folders and files within that directory, and not just the directory, add -R like so



                    sudo chown -R www-data my-dir






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Mar 8 '18 at 15:56









                    Josh McCormackJosh McCormack

                    111




                    111























                        0














                        as stated on the Apache2 Ubuntu Default Page: By default, Ubuntu does not allow access through the web browser to any file apart of those located in /var/www .... This means that any directory or file you want to write to must be under /var/www. Missed this info myself and got my hair pulling for a while trying to write to /tmp etc.






                        share|improve this answer








                        New contributor




                        markus-hb is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                        Check out our Code of Conduct.

























                          0














                          as stated on the Apache2 Ubuntu Default Page: By default, Ubuntu does not allow access through the web browser to any file apart of those located in /var/www .... This means that any directory or file you want to write to must be under /var/www. Missed this info myself and got my hair pulling for a while trying to write to /tmp etc.






                          share|improve this answer








                          New contributor




                          markus-hb is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.























                            0












                            0








                            0







                            as stated on the Apache2 Ubuntu Default Page: By default, Ubuntu does not allow access through the web browser to any file apart of those located in /var/www .... This means that any directory or file you want to write to must be under /var/www. Missed this info myself and got my hair pulling for a while trying to write to /tmp etc.






                            share|improve this answer








                            New contributor




                            markus-hb is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.










                            as stated on the Apache2 Ubuntu Default Page: By default, Ubuntu does not allow access through the web browser to any file apart of those located in /var/www .... This means that any directory or file you want to write to must be under /var/www. Missed this info myself and got my hair pulling for a while trying to write to /tmp etc.







                            share|improve this answer








                            New contributor




                            markus-hb is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.









                            share|improve this answer



                            share|improve this answer






                            New contributor




                            markus-hb is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.









                            answered 16 hours ago









                            markus-hbmarkus-hb

                            11




                            11




                            New contributor




                            markus-hb is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.





                            New contributor





                            markus-hb is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.






                            markus-hb is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.






























                                draft saved

                                draft discarded




















































                                Thanks for contributing an answer to Ask Ubuntu!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid



                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.


                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f622426%2fapache-not-allowing-php-to-create-file%23new-answer', 'question_page');
                                }
                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                Why do type traits not work with types in namespace scope?What are POD types in C++?Why can templates only be...

                                Will tsunami waves travel forever if there was no land?Why do tsunami waves begin with the water flowing away...

                                Simple Scan not detecting my scanner (Brother DCP-7055W)Brother MFC-L2700DW printer can print, can't...