0

I have a 'data collection' website and I'm trying to write some forms for it, the results of which I would like to echo out via PHP. However, I wrote some very basic code testing out the echo statement and I'm getting odd results. My code is as follows:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>Pre-Early-Access Access (testing area)</title>
    </head>
    <body>
        <div class="tweets-container">
        </div>
        <form class="form">
          <div class="form-group">
          <label for="name">Full Name</label>
          <input type="text" class="form-control" id="name" name="name">
          </div>
          <div class="form-group">
          <label for="name">Watchlists You're On (separate entries with ';' symbol)</label>
          <input type="text" class="form-control" id="name" name="watchlists">
          </div>
          <div class="form-group">
          <label for="name">Twitter ID (after the @ sign)</label>
          <input type="text" class="form-control" id="name" name="twitterId">
          </div>
          <div class="form-group">
          <label for="name">Email Address</label>
          <input type="text" class="form-control" id="name" name="email">
          </div>
          <div class="form-group">
          <label for="name">PGP Key (if you have one)</label>
          <input type="text" class="form-control" id="name" name="pgpkey">
          </div>
          <div class="form-group">
          <label for="name">Home IP Address</label>
          <input type="text" class="form-control" id="name" name="ipaddress">
          </div>
          <div class="form-group">
          <label for="name">Uncheck if you do not wish to be placed on our watchlist</label>
          <input type="checkbox" class="form-control" id="name" name="watch" checked>
          </div>
          <input type="submit" value="Submit">
        </form>

        <?php
          echo "<p>Privacy through surveillance</p>";
        ?>

        <script src="https://code.jquery.com/jquery-3.1.1.min.js"
        integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8="
        crossorigin="anonymous"></script>
    </body>
</html>

I have tried using echo("<p>Privacy through surveillance</p>"); instead, with no luck.

The result of running php -v on my server is:

PHP 7.0.8-0ubuntu0.16.04.3 (cli) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.8-0ubuntu0.16.04.3, Copyright (c) 1999-2016, by Zend Technologies

The end result comes out as pictured below:

Privacy through surveillance

No errors are logged to the browser console when viewing.

I would like only:

Privacy through surveillance

To show, without the extra characters.

I have renamed the index.html file to index.php, as well as placed the following lines in my apache2.conf file:

LoadModule php7_module modules/libphp7.so

<FilesMatch \.php$>
    SetHandler application/x-httpd-php
</FilesMatch>

As per the linked solution. However, upon attempting to restart the apache2 process after inputing the new settings, I get this error:

apache2.service - LSB: Apache2 web server Loaded: loaded (/etc/init.d/apache2; bad; vendor preset: enabled) Drop-In: /lib/systemd/system/apache2.service.d └─apache2-systemd.conf Active: failed (Result: exit-code) since Wed 2017-01-11 23:01:51 UTC; 6min a Docs: man:systemd-sysv-generator(8) Process: 10654 ExecStop=/etc/init.d/apache2 stop (code=exited, status=0/SUCCE
Process: 10678 ExecStart=/etc/init.d/apache2 start (code=exited, status=1/FAI lines 1-8/8 (END)

When I remove the lines suggested as additions in the answer to the question listed as a duplicate e.g.

LoadModule php7_module modules/libphp7.so

<FilesMatch \.php$>
    SetHandler application/x-httpd-php
</FilesMatch>

I am able to restart the server as normal, but the index.php php is still not parsed correctly.

The output of running sudo apachectl -e debug on the server the file is serving from is as follows:

[Wed Jan 11 23:25:45.567849 2017] [so:debug] [pid 10961] mod_so.c(266): AH01575: loaded module access_compat_module from /usr/lib/apache2/modules/mod_access_compat.so [Wed Jan 11 23:25:45.568122 2017] [so:debug] [pid 10961] mod_so.c(266): AH01575: loaded module alias_module from /usr/lib/apache2/modules/mod_alias.so [Wed Jan 11 23:25:45.568271 2017] [so:debug] [pid 10961] mod_so.c(266): AH01575: loaded module auth_basic_module from /usr/lib/apache2/modules/mod_auth_basic.so [Wed Jan 11 23:25:45.568420 2017] [so:debug] [pid 10961] mod_so.c(266): AH01575: loaded module authn_core_module from /usr/lib/apache2/modules/mod_authn_core.so [Wed Jan 11 23:25:45.568564 2017] [so:debug] [pid 10961] mod_so.c(266): AH01575: loaded module authn_file_module from /usr/lib/apache2/modules/mod_authn_file.so [Wed Jan 11 23:25:45.568712 2017] [so:debug] [pid 10961] mod_so.c(266): AH01575: loaded module authz_core_module from /usr/lib/apache2/modules/mod_authz_core.so [Wed Jan 11 23:25:45.568835 2017] [so:debug] [pid 10961] mod_so.c(266): AH01575: loaded module authz_host_module from /usr/lib/apache2/modules/mod_authz_host.so [Wed Jan 11 23:25:45.568955 2017] [so:debug] [pid 10961] mod_so.c(266): AH01575: loaded module authz_user_module from /usr/lib/apache2/modules/mod_authz_user.so [Wed Jan 11 23:25:45.569089 2017] [so:debug] [pid 10961] mod_so.c(266): AH01575: loaded module autoindex_module from /usr/lib/apache2/modules/mod_autoindex.so [Wed Jan 11 23:25:45.569283 2017] [so:debug] [pid 10961] mod_so.c(266): AH01575: loaded module deflate_module from /usr/lib/apache2/modules/mod_deflate.so [Wed Jan 11 23:25:45.569406 2017] [so:debug] [pid 10961] mod_so.c(266): AH01575: loaded module dir_module from /usr/lib/apache2/modules/mod_dir.so [Wed Jan 11 23:25:45.569514 2017] [so:debug] [pid 10961] mod_so.c(266): AH01575: loaded module env_module from /usr/lib/apache2/modules/mod_env.so [Wed Jan 11 23:25:45.569629 2017] [so:debug] [pid 10961] mod_so.c(266): AH01575: loaded module filter_module from /usr/lib/apache2/modules/mod_filter.so [Wed Jan 11 23:25:45.569744 2017] [so:debug] [pid 10961] mod_so.c(266): AH01575: loaded module mime_module from /usr/lib/apache2/modules/mod_mime.so [Wed Jan 11 23:25:45.569898 2017] [so:debug] [pid 10961] mod_so.c(266): AH01575: loaded module mpm_event_module from /usr/lib/apache2/modules/mod_mpm_event.so [Wed Jan 11 23:25:45.570047 2017] [so:debug] [pid 10961:tid 140329551361920] mod_so.c(266): AH01575: loaded module negotiation_module from /usr/lib/apache2/modules/mod_negotiation.so [Wed Jan 11 23:25:45.570193 2017] [so:debug] [pid 10961:tid 140329551361920] mod_so.c(266): AH01575: loaded module rewrite_module from /usr/lib/apache2/modules/mod_rewrite.so [Wed Jan 11 23:25:45.570324 2017] [so:debug] [pid 10961:tid 140329551361920] mod_so.c(266): AH01575: loaded module setenvif_module from /usr/lib/apache2/modules/mod_setenvif.so [Wed Jan 11 23:25:45.570591 2017] [so:debug] [pid 10961:tid 140329551361920] mod_so.c(266): AH01575: loaded module status_module from /usr/lib/apache2/modules/mod_status.so httpd (pid 10871) already running

I have also tried using the short form php tags:

<?="<p>Privacy through surveillance</p>"?>

Which instead output:

Privacy through surveillance

"?>

On adding just

LoadModule php7_module modules/libphp7.so

To the apache2.conf file the server fails. On checking the failure logs with journalctl -xe I see:

-- Unit apache2.service has begun starting up. Jan 12 00:27:09 ubuntu apache2[12850]: * Starting Apache httpd web server apache2 Jan 12 00:27:09 ubuntu apache2[12850]: * Jan 12 00:27:09 ubuntu apache2[12850]: * The apache2 configtest failed. Jan 12 00:27:09 ubuntu apache2[12850]: Output of config test was: Jan 12 00:27:09 ubuntu apache2[12850]: apache2: Syntax error on line 221 of /etc/apache2/apache2.conf: Cannot load module Jan 12 00:27:09 ubuntu apache2[12850]: Action 'configtest' failed. Jan 12 00:27:09 ubuntu apache2[12850]: The Apache error log may have more information. Jan 12 00:27:09 ubuntu systemd1: apache2.service: Control process exited, code=exited status=1 Jan 12 00:27:09 ubuntu systemd1: Failed to start LSB: Apache2 web server. -- Subject: Unit apache2.service has failed -- Defined-By: systemd

-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel

-- Unit apache2.service has failed.

-- The result is failed. Jan 12 00:27:09 ubuntu systemd1: apache2.service: Unit entered failed state. Jan 12 00:27:09 ubuntu systemd1: apache2.service: Failed with result 'exit-code'. Jan 12 00:27:09 ubuntu polkitd(authority=local)[3507]: Unregistered Authentication Agent for unix-process:12841:366652013 Jan 12 00:27:36 ubuntu sudo[12866]: peter : TTY=pts/0 ; PWD=/ ; USER=root ; COMMAND=/bin/journalctl -xe Jan 12 00:27:36 ubuntu sudo[12866]: pam_unix(sudo:session): session opened for user root by root(uid=0)

  • Does not seem to be a duplicate at present as the first few presented solutions don't seem to work, but am looking through the lower ranked one's to see if there's anything there. –  Jan 11 '17 at 23:12
  • Do you see the PHP code when you do `View Source` in the browser? – Barmar Jan 11 '17 at 23:44
  • Yes, when I `View Source` the php code appears. –  Jan 11 '17 at 23:46
  • @paulsm4 I know. I noted in the question that the problem is still present in the `.php` file. –  Jan 12 '17 at 00:00
  • Your problem appears to be that you can not get the php module to work in your server, which is more suited for serverfault. – php_nub_qq Jan 12 '17 at 00:01
  • 1
    Obviously the php module is not loaded as it's not showing in the debug output. Does `modules/libphp7.so` even exist? – Capsule Jan 12 '17 at 00:02
  • For someone familiar with the debug output of the apache log this may have been obvious, much as to a resident of France, the language of French may be. In any case, your comment has only tangentially aided in solving the issue, and I am having to recreate Apache2 and PHP by hand from source, which I'd hoped very much to avoid. Though naturally if this was the limit of the assistance you were able to provide of course I accept your advice with good grace. I'd have hoped the default PHP apt install would have configured these things properly. Vain hope I suppose... –  Jan 12 '17 at 16:29

1 Answers1

0

Turns out the solution to this was to remove all traces of PHP AND Apache from my system, running both an sudo apt purge php*/sudo apt purge apache* and a sudo find -name "php"/sudo find -name "apache" from the root directory (/), so there were no elements of the installations left on my system whatsoever.

I then download the tarballs for both the apache server and the latest version of php, then ran ./compile, make, sudo make install for both of these. Once they were in place all I needed to do was add:

<FilesMatch \.php$>
    SetHandler application/x-httpd-php
</FilesMatch>

To the relevant conf file and all worked as it should have previously (LoadModule php7_module modules/libphp7.so was already added after compilation from source).

My current hypothesis is there was a problem with one of the application repositories (probably an early version PHP I was using for another project previously, which I'm surmising probably messed up some elements of Apache as well) which was causing the issue and once I completely removed it and all traces of any damage it had done, everything worked fine.

That's just a theory, though ;).

However, it appears this solution only works intermittently, and seems to vary across different devices and browsers.

Am currently going to try implementing a node server instead, since I suspect some sort of security hole might be causing the error, and I believe node is generally somewhat more secure...

Node server using gulp to access php works fine.