env:
ubuntu 9.10 /
use gotdeb source /
php version 5.3.1 /
php5-fpm installed /
php5-fpm is running , and listening 9000 port test by 2 commands below
pgrep php5-fpm
telnet localhost 9000
however if I visit from anthor computer in LAN ,using this address
http://192.168.1.103/index.php
the browser ask me to save this index.php , but if visit index.php , everything goes well
sites-enabled/default file content
env:
ubuntu 9.10 /
use gotdeb source /
php version 5.3.1 /
php5-fpm installed /
php5-fpm is running , and listening 9000 port test by 2 commands below
pgrep php5-fpm
telnet localhost 9000
however if I visit from anthor computer in LAN ,using this address
http://192.168.1.103/index.php
the browser ask me to save this index.php , but if visit index.html , everything goes well
sites-enabled/default file content
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000
fastcgi_index index.php
fastcgi_param SCRIPT_FILENAME /var/www/$fastcgi_script_name
include fastcgi_params
}
A common pitfall is when your code is using short open tags <? instead of <?php and it's not enabled in php.ini on a fresh install so it won't get parsed.
To enable it set short_open_tag=On
It seems you need to set your website's index.
You can see a full example on nginx's official wiki, but here's the relevant part:
location / {
index index.html index.htm index.php;
}
As you see, the virtual host needs to know it's supposed to process index.php when accessing the website via it's root dir (i.e. http://domain.com/ or http://domain.com/site/), with no file specified.
I do have an index:
location / {
index index.php;
}
I am not using <? PHP tags.
Related
I'll try to be short as it can get bloated.
I set up an ubuntu server 20.04 VM on an Oracle vbox.
I installed nginx, php7.4, Xdebug 3.
I configured everything properly for remote debugging and sftp ( I use PHPstorm), I forwarded the ports and customized my local hosts file.Everything works except...
when loading HTTP://127.0.0.2 it loads the default nginx landing page.My index.php file is uploaded in the root /var/www/my_domain folder through sftp. I created the server block for my_domain.
Still won't work. I am new to this so I am missing something.
If you need more info please request.
Any help appreciated!
Vhost config ( server block in nginx) - php-projects being my current domain and containing index.php:
server {
listen 80;
listen [::]:80 ipv6only=on;
root /var/www/php-projects;
server_name php-projects www.php-projects;
location / {
try_files $uri $uri/ =404;
}
error_log /var/log/nginx/debug.log debug;
}
Network settings from Vbox:
PS. I have tried :
How to set index.html as root file in Nginx?
and
Rewrite rule for the root file in nginx?
with no success.
"I configured everything properly for remote debugging and sftp"
Please post your xdebug configuration.
"when loading HTTP://127.0.0.2"
From where ? Host machine or VM?
"My index.php file is uploaded in the root /var/www/my_domain folder
through sftp."
Please post your nginx vhost configuration
"I created the server block for my_domain"
Where? Post the path to the file where you have done this
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I'm trying to setup a web interface for some controlled plug sockets I have, the sockets are controlled by a Raspberry Pi. I want to have a couple of links on a web page that I can use to turn the switches on and off. I've been trying to use PHP to do this and for some reason it just won't work.
I've tried various suggestions (see below links). All I'm getting is a white page whenever I click the link, and it doesn't do what its supposed to i.e. turn the switch on and off. Running the PHP script from the command line works as expected, the issue seems to be only when trying to run it from the webpage.
I've looked at the permissions and for the script I've set the permissions with:
chmod 777 /path/to/script
I've tried storing the script in my home folder and in the /var/www/html folder with no joy. Nothing appears in the NGINX logs or PHP-FPM log to indicate any error.
I've tried editing the sudoers file to give www-data access to the script (www-data ALL:=/path/to/script/ and even tried it with all permissions for www-data (www-data ALL=(ALL:ALL) ALL) neither have worked.
I did think it might be because the script I'm trying to run involves starting an SSH session but I can't even get a local command to work to create a blank file either in the /home/pi/ directory or /var/www/html.
I've put the script I'm trying to run below along with the PHP I'm using to call the script and a second PHP file I've used to try other commands.
Any help or pointers in the right direction would be appreciated. I think the script is running but its failing somewhere and I can't work out where. The only thing I get back in a web browser is the echo $username line so I know its working in part but when I try to execute a command nothing happens.
PHP SCRIPT:
<?php
$username = posix_getpwuid(posix_geteuid())['name'];
echo $username;
exec("/home/pi/scripts/switch2off");
?>
TEST SCRIPT:
<?php
exec("touch /var/www/html/s/test.txt");
?>
SWITCH2OFF SCRIPT
#! /bin/bash
ssh pi#example 'python /home/pi/switches/switch_2_off.py'
NGINX CONFIG:
limit_req_zone $binary_remote_addr zone=one:10m rate=1r/s;
server {
listen 80;
listen [::]:80;
return 301 https://$server_name$request_uri;
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name example.com;
location /.well-known/ {
allow all;
}
}
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name example.com;
include snippets/ssl-example.conf;
include snippets/ssl-params.conf;
root /var/www/html;
location / {
limit_req zone=one burst=5;
root /var/www/html;
auth_basic "Please Log In";
auth_basic_user_file /etc/nginx/.htpasswd;
proxy_set_header X-Content-Type-Options: nosniff;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
add_header X-Frame-Options "allow-from example.com";
}
location /.well-known/ {
allow all;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
server {
error_page 401 403 404 /404.html;
}
PHP-FPM LOG:
[03-Aug-2020 05:00:01] NOTICE: Terminating ...
[03-Aug-2020 05:00:01] NOTICE: exiting, bye-bye!
[03-Aug-2020 05:00:29] NOTICE: fpm is running, pid 620
[03-Aug-2020 05:00:29] NOTICE: ready to handle connections
[03-Aug-2020 05:00:29] NOTICE: systemd monitor interval set to 10000ms
MY RESEARCH/THINGS I'VE TRIED:
Nginx serves .php files as downloads, instead of executing them - I started here as initially I had a config issue when instead of running the PHP scripts it served them as a download instead.
Run a shell script with an html button - this is where I got the code from for the PHP script
PHP code is not being executed, instead code shows on the page - not quite the same issue as I'm seeing. The web browser doesn't display any code from the php file even when going to view source
https://askubuntu.com/questions/520566/why-wont-this-php-script-execute-bash-script
https://unix.stackexchange.com/questions/115054/php-shell-exec-permission-on-linux-ubuntu
https://www.linode.com/docs/web-servers/nginx/serve-php-php-fpm-and-nginx/
Thanks for all the help. I found the issue. It wasn't with PHP or NGINX. The owner on /var/www/.ssh was set to pi for some reason. I've changed it to www-data and the script has started working now from the webpage. I'm still not sure why my second script to create a file wouldn't work (probably a permissions issue) but I was experimenting and found that other commands would work (like ls) which brought me back to thinking it had to be a permissions error somewhere.
So I went back through all the scripts and folders and checked and it was the .ssh folder. A quick chown fixed the problem.
Thank you again for all your suggestions and help!
I'm running a new install of Windows 10. I need to create a local testing environment for PHP. I've set up and run NginX/PHP servers on Ubuntu Linux before, but never on Windows. I've installed the NginX and PHP binaries for Windows.
After I've booted up and logged in, if I cd to C:\nginx and run nginx.exe, the Nginx server starts up and runs fine, and I get the "Welcome to NginX" screen at http://127.0.0.1.
Then, if I cd to C:\nginx\php and run php-cgi.exe -b 127.0.0.1:9000 -c c:/nginx/php/php.ini, the PHP server runs, and I can access http://127.0.0.1/php.info and get the output of php_info();. So it seems everything is installed okay.
My goal now, is to to have the PHP server autostart when I boot the machine. I downloaded the Non-Sucking Service Manager, and opened a command prompt in Administraror mode, and ran nssm edit nginx. I filled out the screens as follows:
Then I did the same for PHP:
However, while NginX seems to be starting at boot, PHP does not. After a boot, without manually starting anything at the command line, I get the NginX welcome screen. However, if I try to view the PHP info page, I get the following message:
Unable to connect
Firefox can’t establish a connection to the server at 127.0.0.1.
How do I get PHP to autostart on boot?
This is my nginx.conf file:
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type text/html;
sendfile on;
keepalive_timeout 65;
server {
#Uncomment and edit the line below if you want to use a custom domainname
#server_name your.domain.com;
listen 80;
root c:/nginx/html;
location ~ .php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME c:/nginx/html/$fastcgi_script_name;
include fastcgi_params;
}
}
}
Your nginx.conf seems OK.
... However, while NginX seems to be starting at boot ...
I wouldn't trust NGINX welcome page, it most likely comes from cache. I also don't trust a service status Running unless there are nginx processes started by nssm.
In my tests both nginx and php services were not started properly.
I needed to set AppNoConsole=1 for both services to make them work.
According to the author(s) this is a known issue with Windows 10 Creators Update.
2017-04-26: Users of Windows 10 Creators Update should use prelease
build 2.2.4-101 to avoid an issue with services failing to start. If
for some reason you cannot use that build you can also set
AppNoConsole=1 in the registry, noting that applications which expect
a console window may behave unexpectedly.
You can change this setting via NSSM Service Editor GUI > Process > Console window. Just clear the checkbox and click Edit service. It's done.
The same operation can be done with commands too.
net stop php
net stop nginx
nssm set php AppNoConsole 1
nssm set nginx AppNoConsole 1
net start nginx
net start php
I am at the end of my tail here and could really use some help!
Here's my setup -
NGINX, PHP-FPM on CentOS
Nginx conf file has the following:
location ~ .php$ {
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
PHP-FPM conf file at /etc/php-fpm.d/www.conf has the following
listen=127.0.0.1:9000
With the above configuration, NGINX can properly display PHP pages.
Now, I want to setup Xdebug. So I added the following to the /etc/php.d/xdebug.ini file
<code>
zend_extension=/usr/lib64/php/modules/xdebug.so
xdebug.remote_enable=1
xdebug.remote_host=x.x.x.x
xdebug.remote_port=9009
xdebug.remote_autostart=1
</code>
Note remote port is set to 9009 to not conflict with the PHP-FPM port 9000.
On the x.x.x.x machine, I have XDebugClient running listening for incoming connections on port 9009.
Next, I launch a browser from the host x.x.x.x and request URL http://y.y.y.y?XDEBUG_SESSION_START=1 (where y.y.y.y) is the server with the NGINX, PHP-FPM and XDebug setup.
The issue - nothing happens. XDebugClient never gets a connection!
What am I missing?
Things to check
Pull up a phpinfo() page to make sure your php.ini file is configured correctly. If you don't see a long xdebug section, then the problem is in your configuration.
Try running a trace or profile with xdebug. If they work, then the xdebug module itself is okay.
Try setting xdebug.remote_connect_back=1 in your php.ini file. This will override the remote_host setting and can be helpful if the problem is related to network configuration.
Make sure your IDE is set to listen for the connection on port 9009. In PHPStorm, for example, you must configure the IDE to listen on the custom port, and then you have to push a button to activate the debugging tool before you load the page being debugged.
Those are the basic steps I've had to go through quite a few times. Hopefully one of them will help.
I'm new to all things related to webservers. Until now, I used apache. But I want to give a try to nginx. So I decided to install it, alongside PHP. This are the steps I followed (I mention that I use Windows 7):
download nginx from official website
download php5.6.11 from official website
I extracted nginx in C:/ drive
I extracted and copied php into nginx
I created start.bat file (inside nginx folder), with the following code:
#ECHO OFF
start C:\nginx\nginx.exe
start C:\nginx\php\php-cgi.exe -b 127.0.0.1:9000 -c C:\nginx\php\php.ini-development
ping 127.0.0.1 -n 1>NULL
echo Starting nginx
echo .
echo ..
echo ...
ping 127.0.0.1 >NUL
EXIT
I created stop.bat file (inside nginx folder), with the following code:
#ECHO OFF
taskkill /f /IM nginx.exe
taskkill /f /IM php-cgi.exe
EXIT
I edited nginx/conf/nginx.conf file as follows:
location ~ .php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME C:/nginx/html/$fastcgi_script_name;
include fastcgi_params;
}
I started nginx, with the help of start.bat
navigate to 127.0.0.1 in browser, and I got the nginx welcome page.
I created a new php file (test.php) into nginx/html/ directory, with a simple code:
But when I navigate to 127.0.0.1/test.php, it takes a long time to respond (a minute), and after that I got the following error:
------------------------------------------------------
An error occurred.
Sorry, the page you are looking for is currently unavailable.
Please try again later.
If you are the system administrator of this resource then you should check the error log for details.
Faithfully yours, nginx.
-----------------------------------------------------
If I follow the error log link, I get this screen:
Any solution? Thank you.
After downloading both setups extract them into C:// drive.
put extract php folder in nginx folder.
Now follow steps as I am doing in this video.
To configure PHP in nginx we need to make some changes in nginx.conf file.
Remove old code in nginx.conf file paste below code in nginx.conf.
here is code :
location ~ .php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME C:/nginx/html/$fastcgi_script_name;
}
To start nginx and php use below batch code:
#ECHO OFF
start C:\nginx\nginx.exe
start C:\nginx\php\php-cgi.exe -b 127.0.0.1:9000 -c C:\nginx\php\php.ini
ping 127.0.0.1 -n 1>NUL
echo Starting nginx
echo .
echo ..
echo ...
ping 127.0.0.1 >NUL
EXIT
To stop nginx and php use below batch code.
#ECHO OFF
taskkill /f /IM nginx.exe
taskkill /f /IM php-cgi.exe
Exit