Hi guys,
I’m facing an issue and was wondering if anybody could help me with
this.
I have an Ubuntu server, and I have installed all the softwares required
using apt-get. Now, I have installed Nginx using the same mechanism as
well. I want to use the Nginx for serving php scripts from the browser
too. So therefore, after going through the web, I learn’t that we need
FastCGI to be installed.
Now, as soon as the installation was complete, I restarted Nginx server
and tried accessing the php file. Instead of executing the script, it
was actually showing me the php code on the browser. It wasn’t untill I
executed the following command:
/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9090 -u www-data -g www-data -f
/usr/bin/php5-cgi -P /var/run/fastcgi-php.pid
As soon as I executed this command, and, restarted Nginx again, I was
able to execute the PHP script.
Now, my issue is since fastcgi is being binded by a port, it means that
there’s a kind of a daemon running. So, going forward, if I make this
server live, and, by any chance the fastcgi daemon crashes, the ubuntu
will start throwing up my php code to the users (which is obviously
never desired).
I actually want to know a way we can prevent the php code from getting
displayed to the user, irrespective of whether the fastcgi is running or
not.
regards,
Rishab
On 7/11/11 5:21 AM, Rishab Jain wrote:
Now, as soon as the installation was complete, I restarted Nginx
server and tried accessing the php file. Instead of executing the
script, it was actually showing me the php code on the browser. It
wasn’t untill I executed the following command: /usr/bin/spawn-fcgi
-a 127.0.0.1 -p 9090 -u www-data -g www-data -f /usr/bin/php5-cgi -P
/var/run/fastcgi-php.pid
As soon as I executed this command, and, restarted Nginx again, I
was able to execute the PHP script.
You should be able to reload nginx configuration changes without
restarting:
sudo nginx -s reload
Now, my issue is since fastcgi is being binded by a port, it means
that there’s a kind of a daemon running. So, going forward, if I make
this server live, and, by any chance the fastcgi daemon crashes, the
ubuntu will start throwing up my php code to the users (which is
obviously never desired).
I actually want to know a way we can prevent the php code from
getting displayed to the user, irrespective of whether the fastcgi is
running or not.
If you’re PHP scripts are being passed to a fastcgi daemon using a
“fastcgi_pass” statement in your nginx.conf, then if the PHP daemon does
go down you should see a “502 Bad Gateway” page and not the source code.
On another note, you should use a process manager like Supervisor(d) if
you want to use the standard php-cgi daemon. This will restart the
processes should they die. You might also consider using the php-fpm
sapi and daemon. It has a built in process manager and is much more
stable, as it will spawn children to replace ones that die. Behind that
you can consider using Monit to monitor and automatically restart
daemons. We use it for nginx, php-fpm, memcached, sshd, MySQL, etc.
–
Jim O.
On 11 Jul 2011 10h21 WEST, [email protected] wrote:
As suggested above try php-fpm, it provides a native PHP process
manager. Alternatively to php-fpm and supervisor, I suggest
monit. This is a C program opposed to supervisor which is Python.
— appa
On 7/11/11 10:12 AM, Antnio P. P. Almeida wrote:
On 11 Jul 2011 10h21 WEST, [email protected] wrote:
As suggested above try php-fpm, it provides a native PHP process
manager. Alternatively to php-fpm and supervisor, I suggest
monit. This is a C program opposed to supervisor which is Python.
http://mmonit.com
Didn’t I actually suggest that? I mentioned that we use Monit for nginx,
php-fpm, memcached,etc. Where did I suggest Supervisor and php-fpm? I
actually mentioned Supervisor along with “vanilla” php-cgi although
Monit would work there too.
If one is really paranoid and wants additional redundancy, Supervisor
can be used to manage critical daemons and Monit used to monitor
Supervisor. But that’s beyond the scope of this list and this question.
— appa
nginx mailing list
[email protected]
nginx Info Page
–
Jim O.
On 11 Jul 2011 15h51 WEST, [email protected] wrote:
Didn’t I actually suggest that? I mentioned that we use Monit for
nginx, php-fpm, memcached,etc. Where did I suggest Supervisor and
php-fpm? I actually mentioned Supervisor along with “vanilla”
php-cgi although Monit would work there too.
I was unclear in my reply. I suggest monit to monitor php-cgi and do
the process managing part. But you can always use it as an additional
monitoring agent. You can monitor php-fpm with it also.
If one is really paranoid and wants additional redundancy,
Supervisor can be used to manage critical daemons and Monit used to
monitor Supervisor. But that’s beyond the scope of this list and
this question.
Yes.
— appa