GingerBondy007
Posts: 16
Joined: Thu Jul 20, 2017 11:41 pm

Apache2 - downloads .php rather than opening it

Tue Jun 12, 2018 10:35 pm

Hi,

I'm trying to use my raspberry pi to remotely control a project. I have used apache2 to create a web server, and I have built my own website using a template. When I click on the Starter heading in the menu bar of this website, it downloads the file starter.php, instead of running it. The index file is fully in html. When I click on any of the other options on the menu apart from the starter file, they open the file and display them correctly on the website. However, I believe that this is because all of the other headings, are html files not php. How can I fix my website so that it runs the starter.php file instead of downloading it.

Thanks

index.html

Code: Select all

<!DOCTYPE HTML>
<html>

<head>
  <title>simplestyle_3</title>
  <meta name="description" content="website description" />
  <meta name="keywords" content="website keywords, website keywords" />
  <meta http-equiv="content-type" content="text/html; charset=windows-1252" />
  <link rel="stylesheet" type="text/css" href="style/style.css" />
</head>

<body>
  <div id="main">
    <div id="header">
      <div id="logo">
        <div id="logo_text">
          <!-- class="logo_colour", allows you to change the colour of the text -->
          <h1><a href="index.html">simple<span class="logo_colour">style_3</span></a></h1>
          <h2>Simple. Contemporary. Website Template.</h2>
        </div>
      </div>
      <div id="menubar">
        <ul id="menu">
          <!-- put class="selected" in the li tag for the selected page - to highlight which page you're on -->
          <li class="selected"><a href="index.html">Home</a></li>
          <li><a href="starter.php">Starters</a></li>
          <li><a href="page.html">A Page</a></li>
          <li><a href="another_page.html">Another Page</a></li>
          <li><a href="contact.html">Contact Us</a></li>
        </ul>
      </div>
    </div>
    <div id="site_content">
      <div id="sidebar_container">
        <div class="sidebar">
          <div class="sidebar_top"></div>
          <div class="sidebar_item">
            <!-- insert your sidebar items here -->
            <h3>Highest Scores</h3>
            <h5>Recent Players Online</h5>
          </div>
          <div class="sidebar_base"></div>
        </div>
        <div class="sidebar">
          <div class="sidebar_top"></div>
          <div class="sidebar_item">
            <h3>Useful Links</h3>
            <ul>
              <li><a href="#">link 1</a></li>
              <li><a href="#">link 2</a></li>
              <li><a href="#">link 3</a></li>
              <li><a href="#">link 4</a></li>
            </ul>
          </div>
          <div class="sidebar_base"></div>
        </div>
        <div class="sidebar">
          <div class="sidebar_top"></div>
          <div class="sidebar_item">
            <h3>Search</h3>
            <form method="post" action="#" id="search_form">
              <p>
                <input class="search" type="text" name="search_field" value="Enter keywords....." />
                <input name="search" type="image" style="border: 0; margin: 0 0 -9px 5px;" src="style/search.png" alt="Search" title="Search" />
              </p>
            </form>
          </div>
          <div class="sidebar_base"></div>
        </div>
      </div>
      <div id="content">
        <h1>Welcome to Reuben Bond's BB Gun Target System</h1>
        <p>This website, controls the Target System. You can start off a game by using this website, if you want to, you can also see the highest scores for each shooting length. Are you on it ?! </p>
      </div>
    </div>
    <div id="footer">
      <p><a href="index.html">Home</a> | <a href="starter.php">Starter</a> | <a href="page.html">A Page</a> | <a href="another_page.html">Another Page</a> | <a href="contact.html">Contact Us</a></p>
      <p>Copyright &copy; simplestyle_3 | <a href="http://validator.w3.org/check?uri=referer">HTML5</a> | <a href="http://jigsaw.w3.org/css-validator/check/referer">CSS</a> | <a href="http://www.html5webtemplates.co.uk">HTML5 Web Templates</a></p>
    </div>
    <p>&nbsp;</p>
  </div>
</body>
</html>
starter.php

Code: Select all

<?php
echo "<!DOCTYPE HTML>\n";
echo "<html>\n";
echo "<head>\n";
echo "  <title>simplestyle_3 - Starter</title>\n";
echo "  <meta name=\"description\" content=\"website description\" />\n";
echo "  <meta name=\"keywords\" content=\"website keywords, website keywords\" />\n";
echo "  <meta http-equiv=\"content-type\" content=\"text/html; charset=windows-1252\" />\n";
echo "  <link rel=\"stylesheet\" type=\"text/css\" href=\"style/style.css\" />\n";
echo "</head>\n";
echo "<body>\n";
echo "  <div id=\"main\">\n";
echo "    <div id=\"header\">\n";
echo "      <div id=\"logo\">\n";
echo "        <div id=\"logo_text\">\n";
echo "          <!-- class=\"logo_colour\", allows you to change the colour of the text -->\n";
echo "          <h1><a href=\"index.html\">simple<span class=\"logo_colour\">style_3</span></a></h1>\n";
echo "          <h2>Simple. Contemporary. Website Template.</h2>\n";
echo "        </div>\n";
echo "      </div>\n";
echo "      <div id=\"menubar\">\n";
echo "        <ul id=\"menu\">\n";
echo "          <!-- put class=\"selected\" in the li tag for the selected page - to highlight which page you\'re on -->\n";
echo "          <li><a href=\"index.html\">Home</a></li>\n";
echo "          <li class=\"selected\"><a href=\"starter.php\">Starter</a></li>\n";
echo "          <li><a href=\"page.html\">A Page</a></li>\n";
echo "          <li><a href=\"another_page.html\">Another Page</a></li>\n";
echo "          <li><a href=\"contact.html\">Contact Us</a></li>\n";
echo "        </ul>\n";
echo "      </div>\n";
echo "    </div>\n";
echo "    <div id=\"site_content\">\n";
echo "      <div id=\"sidebar_container\">\n";
echo "        <div class=\"sidebar\">\n";
echo "          <div class=\"sidebar_top\"></div>\n";
echo "          <div class=\"sidebar_item\">\n";
echo "            <!-- insert your sidebar items here -->\n";
echo "            <h3>Highest Scores</h3>\n";
echo "            <h4>Recent Players</h4>\n";
echo "          </div>\n";
echo "          <div class=\"sidebar_base\"></div>\n";
echo "        </div>\n";
echo "        <div class=\"sidebar\">\n";
echo "          <div class=\"sidebar_top\"></div>\n";
echo "          <div class=\"sidebar_item\">\n";
echo "            <h3>Search</h3>\n";
echo "            <form method=\"post\" action=\"#\" id=\"search_form\">\n";
echo "              <p>\n";
echo "                <input class=\"search\" type=\"text\" name=\"search_field\" value=\"Enter keywords.....\" />\n";
echo "                <input name=\"search\" type=\"image\" style=\"border: 0; margin: 0 0 -9px 5px;\" src=\"style/search.png\" alt=\"Search\" title=\"Search\" />\n";
echo "              </p>\n";
echo "            </form>\n";
echo "          </div>\n";
echo "          <div class=\"sidebar_base\"></div>\n";
echo "        </div>\n";
?>
an example of a working option : page.html

Code: Select all

<!DOCTYPE HTML>
<html>

<head>
  <title>simplestyle_3 - a page</title>
  <meta name="description" content="website description" />
  <meta name="keywords" content="website keywords, website keywords" />
  <meta http-equiv="content-type" content="text/html; charset=windows-1252" />
  <link rel="stylesheet" type="text/css" href="style/style.css" />
</head>

<body>
  <div id="main">
    <div id="header">
      <div id="logo">
        <div id="logo_text">
          <!-- class="logo_colour", allows you to change the colour of the text -->
          <h1><a href="index.html">simple<span class="logo_colour">style_3</span></a></h1>
          <h2>Simple. Contemporary. Website Template.</h2>
        </div>
      </div>
      <div id="menubar">
        <ul id="menu">
          <!-- put class="selected" in the li tag for the selected page - to highlight which page you're on -->
          <li><a href="index.html">Home</a></li>
          <li><a href="starter.php">Starter</a></li>
          <li class="selected"><a href="page.html">A Page</a></li>
          <li><a href="another_page.html">Another Page</a></li>
          <li><a href="contact.html">Contact Us</a></li>
        </ul>
      </div>
    </div>
    <div id="site_content">
      <div id="sidebar_container">
        <div class="sidebar">
          <div class="sidebar_top"></div>
          <div class="sidebar_item">
            <!-- insert your sidebar items here -->
            <h3>Latest News</h3>
            <h4>New Website Launched</h4>
            <h5>January 1st, 2010</h5>
            <p>2010 sees the redesign of our website.....&nbsp;<a href="#">read more</a></p>
          </div>
          <div class="sidebar_base"></div>
        </div>
        <div class="sidebar">
          <div class="sidebar_top"></div>
          <div class="sidebar_item">
            <h3>Useful Links</h3>
            <ul>
              <li><a href="#">link 1</a></li>
              <li><a href="#">link 2</a></li>
              <li><a href="#">link 3</a></li>
              <li><a href="#">link 4</a></li>
            </ul>
          </div>
          <div class="sidebar_base"></div>
        </div>
        <div class="sidebar">
          <div class="sidebar_top"></div>
          <div class="sidebar_item">
            <h3>Search</h3>
            <form method="post" action="#" id="search_form">
              <p>
                <input class="search" type="text" name="search_field" value="Enter keywords....." />
                <input name="search" type="image" style="border: 0; margin: 0 0 -9px 5px;" src="style/search.png" alt="Search" title="Search" />
              </p>
            </form>
          </div>
          <div class="sidebar_base"></div>
        </div>
      </div>
      <div id="content">
        <!-- insert the page content here -->
        <h1>A Page</h1>
        <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui.</p>
        <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui.</p>
        <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui.</p>
        <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui.</p>
        <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui.</p>
      </div>
    </div>
    <div id="footer">
      <p><a href="index.html">Home</a> | <a href="starter.php">Starter</a> | <a href="page.html">A Page</a> | <a href="another_page.html">Another Page</a> | <a href="contact.html">Contact Us</a></p>
      <p>Copyright &copy; simplestyle_3 | <a href="http://validator.w3.org/check?uri=referer">HTML5</a> | <a href="http://jigsaw.w3.org/css-validator/check/referer">CSS</a> | <a href="http://www.html5webtemplates.co.uk">HTML5 Web Templates</a></p>
    </div>
    <p>&nbsp;</p>
  </div>
</body>
</html>

mfa298
Posts: 1303
Joined: Tue Apr 22, 2014 11:18 am

Re: Apache2 - downloads .php rather than opening it

Wed Jun 13, 2018 11:15 am

GingerBondy007 wrote:
Tue Jun 12, 2018 10:35 pm
When I click on the Starter heading in the menu bar of this website, it downloads the file starter.php, instead of running it.
...
How can I fix my website so that it runs the starter.php file instead of downloading it.
This might suggest you don't have PHP installed/configured properly within your webserver.

Getting it working might be as simple as installing the 'libapache2-mod-php' package (it's been a while since I've completed setting up an apache/php server so it might need some other config as well these days.

Return to “Networking and servers”

Who is online

Users browsing this forum: No registered users and 13 guests