troglobit/merecat

help me enable PHP

Opened this issue · 25 comments

This is my configuration, I installed php and php-cgi, but I couldn't enable php, it doesn't run the example script phpinfo.php, it just shows plain text of php code:


directory = /var/www
data-directory = /htdocs/php_test
charset = "UTF-8"
chroot = true
compression-level = -1
global-passwd = false
hostname = 127.0.0.1
list-dotfiles = false

#virtual-host = true

#sudo pacman -S php php-cgi

php "**.php" {
        enabled = true
        cgi-path = "/usr/bin/php-cgi"
}


server php_test_server {
        port = 80
}

Unlike other popular web servers, Merecat does not allow serving content outside its server directory. It's a security thing.
So the data-directory setting in your config must be a sub-directory to /var/www. One way around this is to use bind mounts on Linux, i.e., bind mount /htdocs/php_test to /var/www/php_test

Also, for this to work you need to run the still unreleased (unstable) master branch. It's a work in progress, sorry.

yes, my proyect or test proyect it's a subdirectory, /var/www/htdocs/php_test, the script phpinfo.php or /var/www/htdocs/php_test/phpinfo.php it's open, but Merecat with php-cgi do not execute the script, just show source code of script, sorry 😔, my english it's bad

Aha, OK I'll look into it. See if I can find some time later today, otherwise it'll be tomorrow. Don't worry about your English, we'll manage :)

In the meantime, have you seen my write-up of how to use regular CGIs? 👉 https://troglobit.com/2019/08/Basic-CGI-in-C-with-Merecat-httpd/

OK, I've reproduced your problem. Looking into it

Found it! :-)

Turned out to be a regression introduced fairly recently. Sorry about the problems it caused you! :-(

yes php now works but only if merecat is executed in the current directory, if the "directory" variable is configured, php stops working, if it is not configured php works again

Sorry about that. The data-directory directive isn't really supposed to be used when you're not also chrooting. I've just pushed another patch for this to master, making sure to compose the resulting path to the server root even when not chrooting.

@RicardoG08 Does everything work now, or do you have any lingering problems and want me to reopen this issue?

php works fine if chroot = false, I thought this variable should be true if directory is proposed

Nope, chroot is an actual dedicated confined area, like the man page chroot(1) says. In a chroot you cannot access anything outside of it, like /usr/bin/php-cgi or even the C library in /usr/lib. Thank you for responding, I'll make sure to clarify these things in the documentation!

very well, I really like Merecat, I am using it for my PHP practices, it is easy to configure compared to other http / https web servers, I will keep testing the software, and I will report bugs or any problems I find, it is the only way I can help the project

Thank you so much! All contributions are welcome :-)

I want to add more simple (!) unit tests. Those are just scripts that usually employ curl. Take a look at how I added a basic CGI test here -> 6a0735f. Wanted to add a php test as well, but I'm not that well versed in php, and I don't have any example PHP CGI in the repo. But I guess a simple phpinfo test would be really useful.

hello again, how long has it been ..., i have continued testing merecat since then, haven't you considered adding support for different extensions for indexes? for example index.php natively?

Great to hear back from you!

Did you mean like this, which is already in merecat.h?

/* CONFIGURE: A list of index filenames to check.  The files are searched
** for in this order.
*/
#define INDEX_NAMES "index.shtml", "index.shtm", "index.stm",	\
		"index.cgi", "index.php",			\
		"index.html", "index.htm",			\
		"index.xhtml", "index.xht",			\
		"Default.htm"

yes, I have it exactly the same, but it does not detect the index.php unless I tell it explicitly from the browser url

Well that's a bug (separate from this one, so we should open a new one), unless you have one of the other ones also in the root directory?

my root directory is "/ var / www" with a "data-directory = / htdocs", which contains the folders "/ a", "/ b" and "/ c", the folders "a" and "b" they contain an index.html and it works fine, but folder "c" has an index.php, it doesn't run automatically unless I specify it in the browser url

OK, that's certainly not how it's supposed to work. It should check for all the INDEX_NAMES in a directory. Could you please open a separate bug report for this?

Thank you <3

Merecat not support Query strings in PHP??

I don't even know what that is, but the full environment and arguments to the CGI should be passed to php, if that's what you mean?

yes, exactly, but for example, Mercat returns error 403 for a valid url like the following:

http://192.168.1.1/htdocs/foro/fudforum/install.php?1463445063

Aha, well that's yet another bug (and more for me to do, unless someone pitches in). Please report a separate issue.

sorry if I'm not helpful in terms of programming
:'c, when I discovered Merecat I really liked the ease of having http / https server ready to use, I am a student and I am focusing or specializing in the administration of GNU / Linux servers and backend programming.

I understand, that's OK. Free/Open Source Software needs all sorts of talent to help out :)