PHP script not executing on Apache server





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







54















I have just reinstalled Apache and PHP5 but when I visit my doc root it just downloads a "download" file. And when I try documentroot/index.php it just downloads the PHP file.



I have PHP installed but Apache doesn't seem to want to execute it.

People suggested adding a 'Load Module' line to my httpd.conf but I don't have that file.










share|improve this question































    54















    I have just reinstalled Apache and PHP5 but when I visit my doc root it just downloads a "download" file. And when I try documentroot/index.php it just downloads the PHP file.



    I have PHP installed but Apache doesn't seem to want to execute it.

    People suggested adding a 'Load Module' line to my httpd.conf but I don't have that file.










    share|improve this question



























      54












      54








      54


      30






      I have just reinstalled Apache and PHP5 but when I visit my doc root it just downloads a "download" file. And when I try documentroot/index.php it just downloads the PHP file.



      I have PHP installed but Apache doesn't seem to want to execute it.

      People suggested adding a 'Load Module' line to my httpd.conf but I don't have that file.










      share|improve this question
















      I have just reinstalled Apache and PHP5 but when I visit my doc root it just downloads a "download" file. And when I try documentroot/index.php it just downloads the PHP file.



      I have PHP installed but Apache doesn't seem to want to execute it.

      People suggested adding a 'Load Module' line to my httpd.conf but I don't have that file.







      apache2 php






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 5 '18 at 14:48









      Yufenyuy Veyeh Dider

      1,56551024




      1,56551024










      asked Apr 20 '14 at 23:46









      user2919631user2919631

      425266




      425266






















          5 Answers
          5






          active

          oldest

          votes


















          97














          Typing:



          sudo apt-get install apache2 php5 libapache2-mod-php5


          will install everything you need and will start the apache server with support for PHP.



          To verify that the php module is loaded, type:



          a2query -m php5


          if not enabled, then load with:



          sudo a2enmod php5


          and restart apache:



          sudo service apache2 restart


          Update for php7.0, tested on Ubuntu 16.04 and 16.10



          Thanks to the comments, I update the answer for php7.



          Install:



          sudo apt-get install apache2 php7.0 libapache2-mod-php7.0 


          Verify:



          a2query -m php7.0


          Load:



          sudo a2enmod php7.0


          Restart apache:



          sudo service apache2 restart





          share|improve this answer


























          • It would be better to use a2enmod than to copy the file manually between mods-available and mods-enabled. a2enmod creates a symlink and so you'll only have one copy of the configuration.

            – jkt123
            Apr 21 '14 at 2:17











          • @jkt123 you're right. thanks for the advice, i edit my answer.

            – girardengo
            Apr 21 '14 at 8:20











          • In my case, it says "ERROR:module php5 does not exist!" it is installed

            – Marian Klühspies
            Mar 8 '15 at 2:07






          • 3





            for ubuntu 16.04 with php7 I have executed these commands in order apt-get install libapache2-mod-php, a2query -m php7.0, service apache2 restart

            – marlo
            Jun 9 '16 at 10:24













          • For ubuntu 14.04 : # a2query -m php7.0 php7.0 (enabled by site administrator) Still php code is not executing

            – Ashish Karpe
            Oct 25 '16 at 12:57



















          18














          Another common cause is that php short tags <? are not enabled by the default php.ini configuration, so after an upgrade or reinstall, that setting may be turned off and php code may depend on it. Try replacing <? with <?php.



          (Credit)






          share|improve this answer

































            12














            Ubuntu 16.04 has moved to PHP 7. This single command will do the job for you:



            sudo apt-get install apache2 php libapache2-mod-php


            Here libapache2-mod-php is a meta-package that installs libapache2-mod-php7.






            share|improve this answer

































              2














              Open php.ini with nano in terminal:



              sudo nano /etc/php/php5.6/apache2/php.ini


              Then change:



              short_open_tag = Off


              to



              short_open_tag = On


              Then save and then restart apache2:



              sudo systemctl restart apache2





              share|improve this answer





















              • 1





                Or fix the PHP scripts :-) This directive determines whether or not PHP will recognize code between <? and ?> tags as PHP source which should be processed as such. It is generally recommended that <?php and ?> should be used and that this feature should be disabled [...]

                – Nicolas Raoul
                May 17 '18 at 3:39



















              0














              the file that you put in /var/www/html/ should have .php
              forexample example.php if it is example it is not working but if you change it to example.php it works.






              share|improve this answer
























                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%2f451708%2fphp-script-not-executing-on-apache-server%23new-answer', 'question_page');
                }
                );

                Post as a guest















                Required, but never shown

























                5 Answers
                5






                active

                oldest

                votes








                5 Answers
                5






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                97














                Typing:



                sudo apt-get install apache2 php5 libapache2-mod-php5


                will install everything you need and will start the apache server with support for PHP.



                To verify that the php module is loaded, type:



                a2query -m php5


                if not enabled, then load with:



                sudo a2enmod php5


                and restart apache:



                sudo service apache2 restart


                Update for php7.0, tested on Ubuntu 16.04 and 16.10



                Thanks to the comments, I update the answer for php7.



                Install:



                sudo apt-get install apache2 php7.0 libapache2-mod-php7.0 


                Verify:



                a2query -m php7.0


                Load:



                sudo a2enmod php7.0


                Restart apache:



                sudo service apache2 restart





                share|improve this answer


























                • It would be better to use a2enmod than to copy the file manually between mods-available and mods-enabled. a2enmod creates a symlink and so you'll only have one copy of the configuration.

                  – jkt123
                  Apr 21 '14 at 2:17











                • @jkt123 you're right. thanks for the advice, i edit my answer.

                  – girardengo
                  Apr 21 '14 at 8:20











                • In my case, it says "ERROR:module php5 does not exist!" it is installed

                  – Marian Klühspies
                  Mar 8 '15 at 2:07






                • 3





                  for ubuntu 16.04 with php7 I have executed these commands in order apt-get install libapache2-mod-php, a2query -m php7.0, service apache2 restart

                  – marlo
                  Jun 9 '16 at 10:24













                • For ubuntu 14.04 : # a2query -m php7.0 php7.0 (enabled by site administrator) Still php code is not executing

                  – Ashish Karpe
                  Oct 25 '16 at 12:57
















                97














                Typing:



                sudo apt-get install apache2 php5 libapache2-mod-php5


                will install everything you need and will start the apache server with support for PHP.



                To verify that the php module is loaded, type:



                a2query -m php5


                if not enabled, then load with:



                sudo a2enmod php5


                and restart apache:



                sudo service apache2 restart


                Update for php7.0, tested on Ubuntu 16.04 and 16.10



                Thanks to the comments, I update the answer for php7.



                Install:



                sudo apt-get install apache2 php7.0 libapache2-mod-php7.0 


                Verify:



                a2query -m php7.0


                Load:



                sudo a2enmod php7.0


                Restart apache:



                sudo service apache2 restart





                share|improve this answer


























                • It would be better to use a2enmod than to copy the file manually between mods-available and mods-enabled. a2enmod creates a symlink and so you'll only have one copy of the configuration.

                  – jkt123
                  Apr 21 '14 at 2:17











                • @jkt123 you're right. thanks for the advice, i edit my answer.

                  – girardengo
                  Apr 21 '14 at 8:20











                • In my case, it says "ERROR:module php5 does not exist!" it is installed

                  – Marian Klühspies
                  Mar 8 '15 at 2:07






                • 3





                  for ubuntu 16.04 with php7 I have executed these commands in order apt-get install libapache2-mod-php, a2query -m php7.0, service apache2 restart

                  – marlo
                  Jun 9 '16 at 10:24













                • For ubuntu 14.04 : # a2query -m php7.0 php7.0 (enabled by site administrator) Still php code is not executing

                  – Ashish Karpe
                  Oct 25 '16 at 12:57














                97












                97








                97







                Typing:



                sudo apt-get install apache2 php5 libapache2-mod-php5


                will install everything you need and will start the apache server with support for PHP.



                To verify that the php module is loaded, type:



                a2query -m php5


                if not enabled, then load with:



                sudo a2enmod php5


                and restart apache:



                sudo service apache2 restart


                Update for php7.0, tested on Ubuntu 16.04 and 16.10



                Thanks to the comments, I update the answer for php7.



                Install:



                sudo apt-get install apache2 php7.0 libapache2-mod-php7.0 


                Verify:



                a2query -m php7.0


                Load:



                sudo a2enmod php7.0


                Restart apache:



                sudo service apache2 restart





                share|improve this answer















                Typing:



                sudo apt-get install apache2 php5 libapache2-mod-php5


                will install everything you need and will start the apache server with support for PHP.



                To verify that the php module is loaded, type:



                a2query -m php5


                if not enabled, then load with:



                sudo a2enmod php5


                and restart apache:



                sudo service apache2 restart


                Update for php7.0, tested on Ubuntu 16.04 and 16.10



                Thanks to the comments, I update the answer for php7.



                Install:



                sudo apt-get install apache2 php7.0 libapache2-mod-php7.0 


                Verify:



                a2query -m php7.0


                Load:



                sudo a2enmod php7.0


                Restart apache:



                sudo service apache2 restart






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Oct 20 '16 at 10:21

























                answered Apr 21 '14 at 1:02









                girardengogirardengo

                3,8621627




                3,8621627













                • It would be better to use a2enmod than to copy the file manually between mods-available and mods-enabled. a2enmod creates a symlink and so you'll only have one copy of the configuration.

                  – jkt123
                  Apr 21 '14 at 2:17











                • @jkt123 you're right. thanks for the advice, i edit my answer.

                  – girardengo
                  Apr 21 '14 at 8:20











                • In my case, it says "ERROR:module php5 does not exist!" it is installed

                  – Marian Klühspies
                  Mar 8 '15 at 2:07






                • 3





                  for ubuntu 16.04 with php7 I have executed these commands in order apt-get install libapache2-mod-php, a2query -m php7.0, service apache2 restart

                  – marlo
                  Jun 9 '16 at 10:24













                • For ubuntu 14.04 : # a2query -m php7.0 php7.0 (enabled by site administrator) Still php code is not executing

                  – Ashish Karpe
                  Oct 25 '16 at 12:57



















                • It would be better to use a2enmod than to copy the file manually between mods-available and mods-enabled. a2enmod creates a symlink and so you'll only have one copy of the configuration.

                  – jkt123
                  Apr 21 '14 at 2:17











                • @jkt123 you're right. thanks for the advice, i edit my answer.

                  – girardengo
                  Apr 21 '14 at 8:20











                • In my case, it says "ERROR:module php5 does not exist!" it is installed

                  – Marian Klühspies
                  Mar 8 '15 at 2:07






                • 3





                  for ubuntu 16.04 with php7 I have executed these commands in order apt-get install libapache2-mod-php, a2query -m php7.0, service apache2 restart

                  – marlo
                  Jun 9 '16 at 10:24













                • For ubuntu 14.04 : # a2query -m php7.0 php7.0 (enabled by site administrator) Still php code is not executing

                  – Ashish Karpe
                  Oct 25 '16 at 12:57

















                It would be better to use a2enmod than to copy the file manually between mods-available and mods-enabled. a2enmod creates a symlink and so you'll only have one copy of the configuration.

                – jkt123
                Apr 21 '14 at 2:17





                It would be better to use a2enmod than to copy the file manually between mods-available and mods-enabled. a2enmod creates a symlink and so you'll only have one copy of the configuration.

                – jkt123
                Apr 21 '14 at 2:17













                @jkt123 you're right. thanks for the advice, i edit my answer.

                – girardengo
                Apr 21 '14 at 8:20





                @jkt123 you're right. thanks for the advice, i edit my answer.

                – girardengo
                Apr 21 '14 at 8:20













                In my case, it says "ERROR:module php5 does not exist!" it is installed

                – Marian Klühspies
                Mar 8 '15 at 2:07





                In my case, it says "ERROR:module php5 does not exist!" it is installed

                – Marian Klühspies
                Mar 8 '15 at 2:07




                3




                3





                for ubuntu 16.04 with php7 I have executed these commands in order apt-get install libapache2-mod-php, a2query -m php7.0, service apache2 restart

                – marlo
                Jun 9 '16 at 10:24







                for ubuntu 16.04 with php7 I have executed these commands in order apt-get install libapache2-mod-php, a2query -m php7.0, service apache2 restart

                – marlo
                Jun 9 '16 at 10:24















                For ubuntu 14.04 : # a2query -m php7.0 php7.0 (enabled by site administrator) Still php code is not executing

                – Ashish Karpe
                Oct 25 '16 at 12:57





                For ubuntu 14.04 : # a2query -m php7.0 php7.0 (enabled by site administrator) Still php code is not executing

                – Ashish Karpe
                Oct 25 '16 at 12:57













                18














                Another common cause is that php short tags <? are not enabled by the default php.ini configuration, so after an upgrade or reinstall, that setting may be turned off and php code may depend on it. Try replacing <? with <?php.



                (Credit)






                share|improve this answer






























                  18














                  Another common cause is that php short tags <? are not enabled by the default php.ini configuration, so after an upgrade or reinstall, that setting may be turned off and php code may depend on it. Try replacing <? with <?php.



                  (Credit)






                  share|improve this answer




























                    18












                    18








                    18







                    Another common cause is that php short tags <? are not enabled by the default php.ini configuration, so after an upgrade or reinstall, that setting may be turned off and php code may depend on it. Try replacing <? with <?php.



                    (Credit)






                    share|improve this answer















                    Another common cause is that php short tags <? are not enabled by the default php.ini configuration, so after an upgrade or reinstall, that setting may be turned off and php code may depend on it. Try replacing <? with <?php.



                    (Credit)







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited May 23 '17 at 12:39









                    Community

                    1




                    1










                    answered Apr 15 '15 at 13:48









                    tufelkindertufelkinder

                    28123




                    28123























                        12














                        Ubuntu 16.04 has moved to PHP 7. This single command will do the job for you:



                        sudo apt-get install apache2 php libapache2-mod-php


                        Here libapache2-mod-php is a meta-package that installs libapache2-mod-php7.






                        share|improve this answer






























                          12














                          Ubuntu 16.04 has moved to PHP 7. This single command will do the job for you:



                          sudo apt-get install apache2 php libapache2-mod-php


                          Here libapache2-mod-php is a meta-package that installs libapache2-mod-php7.






                          share|improve this answer




























                            12












                            12








                            12







                            Ubuntu 16.04 has moved to PHP 7. This single command will do the job for you:



                            sudo apt-get install apache2 php libapache2-mod-php


                            Here libapache2-mod-php is a meta-package that installs libapache2-mod-php7.






                            share|improve this answer















                            Ubuntu 16.04 has moved to PHP 7. This single command will do the job for you:



                            sudo apt-get install apache2 php libapache2-mod-php


                            Here libapache2-mod-php is a meta-package that installs libapache2-mod-php7.







                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Mar 4 '17 at 5:58

























                            answered Oct 16 '16 at 7:47









                            daltonfury42daltonfury42

                            3,46032052




                            3,46032052























                                2














                                Open php.ini with nano in terminal:



                                sudo nano /etc/php/php5.6/apache2/php.ini


                                Then change:



                                short_open_tag = Off


                                to



                                short_open_tag = On


                                Then save and then restart apache2:



                                sudo systemctl restart apache2





                                share|improve this answer





















                                • 1





                                  Or fix the PHP scripts :-) This directive determines whether or not PHP will recognize code between <? and ?> tags as PHP source which should be processed as such. It is generally recommended that <?php and ?> should be used and that this feature should be disabled [...]

                                  – Nicolas Raoul
                                  May 17 '18 at 3:39
















                                2














                                Open php.ini with nano in terminal:



                                sudo nano /etc/php/php5.6/apache2/php.ini


                                Then change:



                                short_open_tag = Off


                                to



                                short_open_tag = On


                                Then save and then restart apache2:



                                sudo systemctl restart apache2





                                share|improve this answer





















                                • 1





                                  Or fix the PHP scripts :-) This directive determines whether or not PHP will recognize code between <? and ?> tags as PHP source which should be processed as such. It is generally recommended that <?php and ?> should be used and that this feature should be disabled [...]

                                  – Nicolas Raoul
                                  May 17 '18 at 3:39














                                2












                                2








                                2







                                Open php.ini with nano in terminal:



                                sudo nano /etc/php/php5.6/apache2/php.ini


                                Then change:



                                short_open_tag = Off


                                to



                                short_open_tag = On


                                Then save and then restart apache2:



                                sudo systemctl restart apache2





                                share|improve this answer















                                Open php.ini with nano in terminal:



                                sudo nano /etc/php/php5.6/apache2/php.ini


                                Then change:



                                short_open_tag = Off


                                to



                                short_open_tag = On


                                Then save and then restart apache2:



                                sudo systemctl restart apache2






                                share|improve this answer














                                share|improve this answer



                                share|improve this answer








                                edited Sep 29 '17 at 10:40









                                Benny

                                3,39821026




                                3,39821026










                                answered Sep 29 '17 at 4:52









                                Satrio PrasojoSatrio Prasojo

                                211




                                211








                                • 1





                                  Or fix the PHP scripts :-) This directive determines whether or not PHP will recognize code between <? and ?> tags as PHP source which should be processed as such. It is generally recommended that <?php and ?> should be used and that this feature should be disabled [...]

                                  – Nicolas Raoul
                                  May 17 '18 at 3:39














                                • 1





                                  Or fix the PHP scripts :-) This directive determines whether or not PHP will recognize code between <? and ?> tags as PHP source which should be processed as such. It is generally recommended that <?php and ?> should be used and that this feature should be disabled [...]

                                  – Nicolas Raoul
                                  May 17 '18 at 3:39








                                1




                                1





                                Or fix the PHP scripts :-) This directive determines whether or not PHP will recognize code between <? and ?> tags as PHP source which should be processed as such. It is generally recommended that <?php and ?> should be used and that this feature should be disabled [...]

                                – Nicolas Raoul
                                May 17 '18 at 3:39





                                Or fix the PHP scripts :-) This directive determines whether or not PHP will recognize code between <? and ?> tags as PHP source which should be processed as such. It is generally recommended that <?php and ?> should be used and that this feature should be disabled [...]

                                – Nicolas Raoul
                                May 17 '18 at 3:39











                                0














                                the file that you put in /var/www/html/ should have .php
                                forexample example.php if it is example it is not working but if you change it to example.php it works.






                                share|improve this answer




























                                  0














                                  the file that you put in /var/www/html/ should have .php
                                  forexample example.php if it is example it is not working but if you change it to example.php it works.






                                  share|improve this answer


























                                    0












                                    0








                                    0







                                    the file that you put in /var/www/html/ should have .php
                                    forexample example.php if it is example it is not working but if you change it to example.php it works.






                                    share|improve this answer













                                    the file that you put in /var/www/html/ should have .php
                                    forexample example.php if it is example it is not working but if you change it to example.php it works.







                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered 11 mins ago









                                    yasin lachiniyasin lachini

                                    1143




                                    1143






























                                        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%2f451708%2fphp-script-not-executing-on-apache-server%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

                                        GameSpot

                                        日野市

                                        Tu-95轟炸機