Changing php.ini with code in a LEMP stack on Debian systems

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
2
down vote

favorite












This is how I establish a Debian LEMP and use code to change php.ini directives, as part of php-fpm.



Please review the way I change php.ini. I believe my approach here is bad because I edit a conf file directly instead overriding somewhere.



apt-get upgrade nginx mysql-server php-fpm php-mysql php-mbstring php-mcrypt -y
sed -i "s/post_max_size = .M/post_max_size = 200M/ ; s/upload_max_filesize = .M/upload_max_filesize = 200M/" /etc/php/*/fpm/php.ini
sed -i "s/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/" /etc/php/*/fpm/php.ini






share|improve this question



























    up vote
    2
    down vote

    favorite












    This is how I establish a Debian LEMP and use code to change php.ini directives, as part of php-fpm.



    Please review the way I change php.ini. I believe my approach here is bad because I edit a conf file directly instead overriding somewhere.



    apt-get upgrade nginx mysql-server php-fpm php-mysql php-mbstring php-mcrypt -y
    sed -i "s/post_max_size = .M/post_max_size = 200M/ ; s/upload_max_filesize = .M/upload_max_filesize = 200M/" /etc/php/*/fpm/php.ini
    sed -i "s/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/" /etc/php/*/fpm/php.ini






    share|improve this question























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      This is how I establish a Debian LEMP and use code to change php.ini directives, as part of php-fpm.



      Please review the way I change php.ini. I believe my approach here is bad because I edit a conf file directly instead overriding somewhere.



      apt-get upgrade nginx mysql-server php-fpm php-mysql php-mbstring php-mcrypt -y
      sed -i "s/post_max_size = .M/post_max_size = 200M/ ; s/upload_max_filesize = .M/upload_max_filesize = 200M/" /etc/php/*/fpm/php.ini
      sed -i "s/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/" /etc/php/*/fpm/php.ini






      share|improve this question













      This is how I establish a Debian LEMP and use code to change php.ini directives, as part of php-fpm.



      Please review the way I change php.ini. I believe my approach here is bad because I edit a conf file directly instead overriding somewhere.



      apt-get upgrade nginx mysql-server php-fpm php-mysql php-mbstring php-mcrypt -y
      sed -i "s/post_max_size = .M/post_max_size = 200M/ ; s/upload_max_filesize = .M/upload_max_filesize = 200M/" /etc/php/*/fpm/php.ini
      sed -i "s/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/" /etc/php/*/fpm/php.ini








      share|improve this question












      share|improve this question




      share|improve this question








      edited Jan 26 at 19:52









      200_success

      123k14143401




      123k14143401









      asked Jan 26 at 17:17









      Arcticooling

      5110




      5110




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          By doing ad hoc editing like that, you're making certain assumptions about what the php.ini configuration currently looks like. For example, you have assumed that the size limits end with M, and that those lines are not commented out. You have also assumed that the cgi.fix_pathinfo line is commented out.



          There are two better ways that I prefer.




          • The simple solution is to put all of the local overrides together in one file. From the PHP manual:




            Within each directory, PHP will scan all files ending in .ini in alphabetical order.




            So, instead of editing, simply create a file with a name like /etc/php/7.0/fpm/zz_overrides.ini containing four lines:



            [PHP]
            post_max_size = 200M
            upload_max_filesize = 200M
            cgi.fix_pathinfo = 0


            This has the benefit that you leave all of the distro-provided configuration files in their pristine state, and won't need to merge your changes when upgrading. The disadvantage is that you will need to keep in mind where to look for the effective settings — but that's not hard if you make it a habit.



          • Alternatively, use augtool, which is a configuration file editor, as in this example.






          share|improve this answer























            Your Answer




            StackExchange.ifUsing("editor", function ()
            return StackExchange.using("mathjaxEditing", function ()
            StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
            StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
            );
            );
            , "mathjax-editing");

            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "196"
            ;
            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',
            convertImagesToLinks: false,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );








             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f186066%2fchanging-php-ini-with-code-in-a-lemp-stack-on-debian-systems%23new-answer', 'question_page');

            );

            Post as a guest






























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            1
            down vote



            accepted










            By doing ad hoc editing like that, you're making certain assumptions about what the php.ini configuration currently looks like. For example, you have assumed that the size limits end with M, and that those lines are not commented out. You have also assumed that the cgi.fix_pathinfo line is commented out.



            There are two better ways that I prefer.




            • The simple solution is to put all of the local overrides together in one file. From the PHP manual:




              Within each directory, PHP will scan all files ending in .ini in alphabetical order.




              So, instead of editing, simply create a file with a name like /etc/php/7.0/fpm/zz_overrides.ini containing four lines:



              [PHP]
              post_max_size = 200M
              upload_max_filesize = 200M
              cgi.fix_pathinfo = 0


              This has the benefit that you leave all of the distro-provided configuration files in their pristine state, and won't need to merge your changes when upgrading. The disadvantage is that you will need to keep in mind where to look for the effective settings — but that's not hard if you make it a habit.



            • Alternatively, use augtool, which is a configuration file editor, as in this example.






            share|improve this answer



























              up vote
              1
              down vote



              accepted










              By doing ad hoc editing like that, you're making certain assumptions about what the php.ini configuration currently looks like. For example, you have assumed that the size limits end with M, and that those lines are not commented out. You have also assumed that the cgi.fix_pathinfo line is commented out.



              There are two better ways that I prefer.




              • The simple solution is to put all of the local overrides together in one file. From the PHP manual:




                Within each directory, PHP will scan all files ending in .ini in alphabetical order.




                So, instead of editing, simply create a file with a name like /etc/php/7.0/fpm/zz_overrides.ini containing four lines:



                [PHP]
                post_max_size = 200M
                upload_max_filesize = 200M
                cgi.fix_pathinfo = 0


                This has the benefit that you leave all of the distro-provided configuration files in their pristine state, and won't need to merge your changes when upgrading. The disadvantage is that you will need to keep in mind where to look for the effective settings — but that's not hard if you make it a habit.



              • Alternatively, use augtool, which is a configuration file editor, as in this example.






              share|improve this answer

























                up vote
                1
                down vote



                accepted







                up vote
                1
                down vote



                accepted






                By doing ad hoc editing like that, you're making certain assumptions about what the php.ini configuration currently looks like. For example, you have assumed that the size limits end with M, and that those lines are not commented out. You have also assumed that the cgi.fix_pathinfo line is commented out.



                There are two better ways that I prefer.




                • The simple solution is to put all of the local overrides together in one file. From the PHP manual:




                  Within each directory, PHP will scan all files ending in .ini in alphabetical order.




                  So, instead of editing, simply create a file with a name like /etc/php/7.0/fpm/zz_overrides.ini containing four lines:



                  [PHP]
                  post_max_size = 200M
                  upload_max_filesize = 200M
                  cgi.fix_pathinfo = 0


                  This has the benefit that you leave all of the distro-provided configuration files in their pristine state, and won't need to merge your changes when upgrading. The disadvantage is that you will need to keep in mind where to look for the effective settings — but that's not hard if you make it a habit.



                • Alternatively, use augtool, which is a configuration file editor, as in this example.






                share|improve this answer















                By doing ad hoc editing like that, you're making certain assumptions about what the php.ini configuration currently looks like. For example, you have assumed that the size limits end with M, and that those lines are not commented out. You have also assumed that the cgi.fix_pathinfo line is commented out.



                There are two better ways that I prefer.




                • The simple solution is to put all of the local overrides together in one file. From the PHP manual:




                  Within each directory, PHP will scan all files ending in .ini in alphabetical order.




                  So, instead of editing, simply create a file with a name like /etc/php/7.0/fpm/zz_overrides.ini containing four lines:



                  [PHP]
                  post_max_size = 200M
                  upload_max_filesize = 200M
                  cgi.fix_pathinfo = 0


                  This has the benefit that you leave all of the distro-provided configuration files in their pristine state, and won't need to merge your changes when upgrading. The disadvantage is that you will need to keep in mind where to look for the effective settings — but that's not hard if you make it a habit.



                • Alternatively, use augtool, which is a configuration file editor, as in this example.







                share|improve this answer















                share|improve this answer



                share|improve this answer








                edited Jan 26 at 21:23









                Arcticooling

                5110




                5110











                answered Jan 26 at 20:16









                200_success

                123k14143401




                123k14143401






















                     

                    draft saved


                    draft discarded


























                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f186066%2fchanging-php-ini-with-code-in-a-lemp-stack-on-debian-systems%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Popular posts from this blog

                    Chat program with C++ and SFML

                    Function to Return a JSON Like Objects Using VBA Collections and Arrays

                    Will my employers contract hold up in court?