You are not logged in.

#1 2016-04-10 22:01:02

kete
Member
Registered: 2015-01-01
Posts: 36

[SOLVED] How to use PHP with Hiawatha

When I try to open index.php, Firefox asks me if I'd like to save the file.
I have installed php and hiawatha. Do I need to install the cgi and fpm
packages for php, too? https://wiki.archlinux.org/index.php/Hiawatha I
don't think I need CGI. I'm just going to do some basic templates with
PHP.

I have configured hiawatha.conf and php.ini according to the wiki pages
and Hiawatha's PHP security recommendations. I'm just using the default
directory, now, not a virtual host. HTML works.

Last edited by kete (2016-04-11 13:58:20)

Offline

#2 2016-04-10 22:05:11

EmilyShepherd
Member
From: Bucks, UK
Registered: 2016-03-20
Posts: 45
Website

Re: [SOLVED] How to use PHP with Hiawatha

How are you accessing the files? (Is it, for example, via a URL like http://localhost/myfile.php or like file:///var/www/myfile.php)?

Offline

#3 2016-04-10 22:09:34

kete
Member
Registered: 2015-01-01
Posts: 36

Re: [SOLVED] How to use PHP with Hiawatha

localhost

Here is the file:

<!doctype html>
<html lang="en-US">
  <title>Tes</title>
  <p>Tes!</p>
  <p><?php echo "Testing standard PHP"; ?></p>
  <p><script language="php">echo "Testing a PHP script selector";</script></p>
</html>

Offline

#4 2016-04-10 22:14:29

EmilyShepherd
Member
From: Bucks, UK
Registered: 2016-03-20
Posts: 45
Website

Re: [SOLVED] How to use PHP with Hiawatha

kete wrote:

Do I need to install the cgi and fpm packages for php, too?

I somehow missed this in your original post. Yes, you absolutely need these - CGI is the way in which a web server communicates with PHP; without it, PHP is simply a stand alone scripting language on your system like bash, python, awk, etc.

I'd recommend having a careful reread of that wiki link that you posted, as it does quite clearly say that the php-cgi and php-fpm packages are required...

Last edited by EmilyShepherd (2016-04-10 22:14:43)

Offline

#5 2016-04-10 23:55:06

kete
Member
Registered: 2015-01-01
Posts: 36

Re: [SOLVED] How to use PHP with Hiawatha

The wiki pages for a few web servers have PHP information under FastCGI, but I wasn't
sure if it was just for FCGI or necessarily for PHP as well.

I tried to enable CGI by installing php-cgi and adding the line,
'ExecuteCGI = yes', but it got the same result. I also tried as a
virtualhost and got the same results; html worked, but the browser tried
to download the php.

I tried to enable FCGI in addition to CGI by also installing fcgi and
php-fpm. Then, I started php-fpm. I verified php-cgi was working.
The php file now says, "No input file specified." If I mistype the
filename, it says, "File not found." The html files still work.

FastCGIserver {
#    FastCGIid = PHP5
    FastCGIid = PHP7
#    ConnectTo = /var/lib/hiawatha/php-fcgi.sock
    ConnectTo = /run/php-fpm/php-fpm.sock
    Extension = php
    SessionTimeout = 30
}

I also had the 'UseFastCGI = PHP7' line in the VirtualHost section.
The error log files are not writing yet, and the virtualhost error log
directory doesn't even exist yet.

I also uncommented CGIhandler = /usr/bin/php-cgi:php, and the
default site said, "403 - Forbidden". The php file has the same perms as
the html.

journalctl says

hiawatha[15694]: Configuration OK.
hiawatha[15696]: No non-fatal errors found in the Hiawatha configuration.
hiawatha[15700]: Error creating logfile /srv/http/myhost/log/access.log or changing its protection or ownership.
hiawatha[15700]: Error creating logfile /srv/http/myhost/log/error.log or changing its protection or ownership.

/srv/http/myhost is drwxr-xr-x 3 kete root all the way down.
Ok, careless idea—changed to root:root.
I made the log files like this

sudo mkdir log
sudo touch log/{access,error,exploit,garbage,system}.log
sudo chown http:http log/*.log

I followed the Hiawatha PHP instructions.

Last edited by kete (2016-04-11 09:50:53)

Offline

#6 2016-04-11 11:23:58

EmilyShepherd
Member
From: Bucks, UK
Registered: 2016-03-20
Posts: 45
Website

Re: [SOLVED] How to use PHP with Hiawatha

kete wrote:

It is typically better to stick to the tutorials on the Arch Wiki when you can, especially if you have been running into issues, as the wiki is tailored towards the known setup of Arch Linux machines.

Have you enabled and started the php-fpm service? Could you post up the output of 'php-cgi --version' please?

kete wrote:

I made the log files like this

Have you got the log files working now then? If so, could you post up their output after a reboot of Hiawatha?

Offline

#7 2016-04-11 13:57:55

kete
Member
Registered: 2015-01-01
Posts: 36

Re: [SOLVED] How to use PHP with Hiawatha

[kete@lbrbtprbl ~]$ systemctl status php-fpm.service
● php-fpm.service - The PHP FastCGI Process Manager
   Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; disabled; vendor preset: disabled
   Active: active (running) since Sun 2016-04-10 17:08:22 EDT; 16h ago
...

~ $ php-cgi --version
PHP 7.0.5 (cgi-fcgi) (built: Mar 29 2016 18:07:13)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies

/var/log/hiawatha/error.log wrote:

127.0.0.1|Sun 10 Apr 2016 19:41:34 -0400|/srv/http/hiawatha/index.php|CGI execution not allowed

/srv/http/myhost/log/error.log wrote:

127.0.0.1|Sun 10 Apr 2016 22:17:49 -0400|/srv/http/myhost/public/future_index.php|PHP message: PHP Warning:  Unknown: open_basedir restriction in effect. File(/srv/http/myhost/public/future_index.php) is not within the allowed path(s): (/srv/http/hiawatha/) in Unknown on line 0|PHP message: PHP Warning:  Unknown: failed to open stream: Operation not permitted in Unknown on line 0|Unable to open primary script: /srv/http/myhost/public/future_index.php (Operation not permitted)

I checked the php and hiawatha configs, and php is no
longer set to the hiawatha directory: just the http directory and all
below, including myhost. I restarted hiawatha to make sure, but I got
the same error, again. The hiawatha config doesn't really have this
setting except for the default site's location.

Got it—restarted php-fpm.
Thanks!

Offline

Board footer

Powered by FluxBB