Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

help me enable PHP #17

Closed
ghost opened this issue Jul 18, 2020 · 25 comments
Closed

help me enable PHP #17

ghost opened this issue Jul 18, 2020 · 25 comments

Comments

@ghost
Copy link

ghost commented Jul 18, 2020

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
}

@troglobit
Copy link
Owner

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.

@ghost
Copy link
Author

ghost commented Jul 18, 2020

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

@troglobit
Copy link
Owner

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/

@troglobit
Copy link
Owner

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

@troglobit
Copy link
Owner

Found it! :-)

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

@ghost
Copy link
Author

ghost commented Jul 19, 2020

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

troglobit added a commit that referenced this issue Jul 19, 2020
When both directory and data-directory are given, but not chroot, we
must compose the resulting server path *and* append a final slash to
it so we can reference the files/scripts in the server root.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
@troglobit
Copy link
Owner

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.

@troglobit
Copy link
Owner

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

@ghost
Copy link
Author

ghost commented Jul 20, 2020

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

@troglobit
Copy link
Owner

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!

@ghost
Copy link
Author

ghost commented Jul 20, 2020

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

@troglobit
Copy link
Owner

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.

@ghost
Copy link
Author

ghost commented Sep 28, 2020

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?

@troglobit
Copy link
Owner

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"

@ghost
Copy link
Author

ghost commented Sep 29, 2020

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

@troglobit
Copy link
Owner

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?

@ghost
Copy link
Author

ghost commented Sep 29, 2020

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

@troglobit
Copy link
Owner

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?

@troglobit
Copy link
Owner

Thank you <3

@ghost
Copy link
Author

ghost commented Oct 1, 2020

Merecat not support Query strings in PHP??

@troglobit
Copy link
Owner

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?

@ghost
Copy link
Author

ghost commented Oct 1, 2020

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

@troglobit
Copy link
Owner

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

@ghost
Copy link
Author

ghost commented Oct 2, 2020

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.

@troglobit
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant