uHTTPd is dowloading the PHP Script instead of executing it

I have a similar/same problem as here:
uHTTPd is Downloading My PHP Script Instead of Executing it - Installing and Using OpenWrt - OpenWrt Forum
But i couldn't solve it after headcrashing and struggling arround so i hope somebody has some new ideas or a solution.

Here is my uHTTPd config:


config uhttpd 'main'
	list listen_http '0.0.0.0:80'
	list listen_http '[::]:80'
	list listen_https '0.0.0.0:443'
	list listen_https '[::]:443'
	option home '/www'
	option rfc1918_filter '1'
	option max_requests '3'
	option max_connections '100'
	option cert '/etc/uhttpd.crt'
	option key '/etc/uhttpd.key'
	option cgi_prefix '/cgi-bin'
	list lua_prefix '/cgi-bin/luci=/usr/lib/lua/luci/sgi/uhttpd.lua'
	option script_timeout '60'
	option network_timeout '30'
	option http_keepalive '20'
	option tcp_keepalive '1'
	option ubus_prefix '/ubus'
	option redirect_https '0'
	list interpreter '.php=/usr/bin/php-cgi'

config uhttpd 'livephp'
        option listen_http '8080'
        option home '/livephp'

config cert 'defaults'
	option days '730'
	option key_type 'rsa'
	option bits '2048'
	option ec_curve 'P-256'
	option country 'ZZ'
	option state 'Somewhere'
	option location 'Unknown'
	option commonname 'OpenWrt'

The PHP.ini:

[PHP]

;;;;;;;;;;;;;;;;;;;;
; Language Options ;
;;;;;;;;;;;;;;;;;;;;

engine = On
short_open_tag = On
precision = 12
output_buffering = Off
;output_handler =
zlib.output_compression = Off
;zlib.output_compression_level = -1
;zlib.output_handler =
implicit_flush = Off
unserialize_callback_func =
;unserialize_max_depth = 4096
serialize_precision = 100
;open_basedir =
disable_functions =
disable_classes =
;highlight.string = #DD0000
;highlight.comment = #FF9900
;highlight.keyword = #007700
;highlight.default = #0000BB
;highlight.html = #000000
;ignore_user_abort = On
;realpath_cache_size = 16k
;realpath_cache_ttl = 120
;zend.enable_gc = On
;zend.multibyte = Off
;zend.script_encoding =
;zend.exception_ignore_args = On
;zend.exception_string_param_max_len = 0

;;;;;;;;;;;;;;;;;
; Miscellaneous ;
;;;;;;;;;;;;;;;;;

expose_php = On

;;;;;;;;;;;;;;;;;;;
; Resource Limits ;
;;;;;;;;;;;;;;;;;;;

max_execution_time = 30
max_input_time = 60
;max_input_nesting_level = 64
;max_input_vars = 1000
memory_limit = 8M

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Error handling and logging ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

error_reporting = E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT
display_errors = On
display_startup_errors = Off
log_errors = Off
ignore_repeated_errors = Off
ignore_repeated_source = Off
report_memleaks = On
;report_zend_debug = 0
track_errors = Off
;html_errors = Off
;docref_root = "/phpmanual/"
;docref_ext = .html
;error_prepend_string = "<span style='color: #ff0000'>"
;error_append_string = "</span>"
;error_log = syslog
;syslog.ident = php
;syslog.facility = user
;syslog.filter = ascii

;;;;;;;;;;;;;;;;;
; Data Handling ;
;;;;;;;;;;;;;;;;;

;arg_separator.output = "&amp;"
;arg_separator.input = ";&"
variables_order = "EGPCS"
request_order = "GP"
register_argc_argv = On
auto_globals_jit = On
;enable_post_data_reading = Off
post_max_size = 8M
auto_prepend_file =
auto_append_file =
default_mimetype = "text/html"
;default_charset = "UTF-8"
;internal_encoding =
;input_encoding =
;output_encoding =

;;;;;;;;;;;;;;;;;;;;;;;;;
; Paths and Directories ;
;;;;;;;;;;;;;;;;;;;;;;;;;

;include_path = ".:/php/includes"
doc_root = ""
user_dir =
extension_dir = "/usr/lib/php8"
;sys_temp_dir = "/tmp"
enable_dl = On
;cgi.force_redirect = 1
;cgi.nph = 1
;cgi.redirect_status_env =
cgi.fix_pathinfo = 1
;cgi.discard_path = 1
;fastcgi.impersonate = 1
;fastcgi.logging = 0
;cgi.rfc2616_headers = 0
;cgi.check_shebang_line = 1

;;;;;;;;;;;;;;;;
; File Uploads ;
;;;;;;;;;;;;;;;;

file_uploads = On
upload_tmp_dir = "/tmp"
upload_max_filesize = 2M
max_file_uploads = 20

;;;;;;;;;;;;;;;;;;
; Fopen wrappers ;
;;;;;;;;;;;;;;;;;;

allow_url_fopen = On
allow_url_include = Off
;from = "john@doe.com"
;user_agent = "PHP"
default_socket_timeout = 60
;auto_detect_line_endings = Off

My info.php i want to execute is:

<?php phpinfo(); ?>

I call it with:
http://openwrt:8080/info.php
and then it immediately downloads the file instead of executing it.

So this should be no real hard computer science problem but it seems so...:smiley:
Any help would be very nice! :wink:
Thanks!

In the topic you posted - the post marked as the solution says this:

Did you do so?

Yes i tried it still downloads it ...
I get a "download" file in this case instead of the info.php file but the content is the same.

Tried it now on my Android there it looks fine..will check again tomorrow...realy strange...

To be clear, it says it has to be named index.php :point_left:

You mentioned info.php again - so I wanted to be sure you saw and understood the post say you have to rename the file.

It's been a while since I used uhttpd with php, but I did use it extensively with php before moving to lighttpd. From memory it looks very much to me that your config is all wrong.

As far as memory serves, your 'livephp' section should at least look something like:

config uhttpd 'livephp'
        list listen_http '0.0.0.0:8080'
        list interpreter '.php=/usr/bin/php-cgi'
        option home '/livephp'

Note that listen_http is a list, not an option, and the value must be of the form ip:port

2 Likes

Thanks for all your inputs, finally it works :+1: