i'm newbie in openshift and nginx. This is my first experiment creating DIY app using php 5.5 on nginx. Nginx server is working perfectly, but when i add php-fpm configuration :
...
location ~ ^/index.php(/|$) {
root html;
include fastcgi_params;
fastcgi_pass unix:${OPENSHIFT_RUN_DIR}/php-fpm.socket;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME html/$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_intercept_errors on;
}
...
in nginx.conf, I get 503 error on my browser telling service is unavailable. I had modify above script by many suggestion, but still no luck. Please anyone? Thanks
ps : I also had following https://www.openshift.com/forums/openshift/installing-php-fpm-and-nginx from github, but still no luck
I suggest you creating a Downloadable cartridge instead of DIY. There are several nginx-php community cartridges on GitHub at the moment, eg. OpenShift Nginx PHP-FPM Cartridge by Getup Cloud, which you can spin up very easily with a single command:
rhc app create php https://reflector-getupcloud.getup.io/reflect?github=getupcloud/openshift-nginx-php-fpm
References:
OpenShift Origin Documentation Site
OpenShift Origin Cartridge Developer’s Guide
Download and Run Your Own Cartridges on OpenShift
List of OpenShift Origin community cartridges (an early instance of oo-index, see it's GitHub repo)
Related
This question already has an answer here:
How to use nginx with PHP?
(1 answer)
Closed 2 years ago.
On my website "craff.ddns.net" (isn't online 24/7 yet) I didn't install php to nginx yet, becuse I'm not sure if I need to, and when I visit my website it just downloads the "index.php". I already asked a friend of mine who knows a bit more than me about webservers and he said I should set the index to "index.php", but I already have and it hasn't worked. Then he asked me if I installed php and I didn't. Will it automatically start to download "index.php" if I don't have php installed to nginx? And do I need to install php or is there anything else I need to install?
Btw I don't have anything installed on my nginx yet and I'm running nginx on Windows.
Nginx needs a program to proccess the php file. You need to install the php-fpm package.
Here is a sample location you need to enter in server block from the official doc.
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
# Mitigate https://httpoxy.org/ vulnerabilities
fastcgi_param HTTP_PROXY "";
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
# include the fastcgi_param setting
include fastcgi_params;
# SCRIPT_FILENAME parameter is used for PHP FPM determining
# the script name. If it is not set in fastcgi_params file,
# i.e. /etc/nginx/fastcgi_params or in the parent contexts,
# please comment off following line:
# fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
I found a similar question here but it didn't quite answer my question.
I've always installed my stack locally for development, NginX, PHP7, MySQL, and Couchbase. No Problems.
Now I have to work on a project that requires a lower version of PHP... And my team will have to work on it as well, so I've looked to Docker to try to find the solution.
In my existing NGINX conf files I send the requests off to php-fpm like this
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME
$document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_ignore_client_abort on;
fastcgi_param SERVER_NAME $http_host;
}
See the line
fastcgi_pass 127.0.0.1:9000;
?
I was hoping to be able to create a docker container running a specific version of PHP and write it into the server block as above but with
fastcgi_pass 172.17.0.1:9000;
Where 172.17.0.1 is the IP of the container.
I have used, very simply,
FROM php:7.1-fpm
EXPOSE 9000
As my dockerfile. I can build an image, run the container, run bash in the container and see that PHP -I and PHP -v return what I expect.
Running docker inspect has given me two IP addresses, 172.17.0.1, and 172.17.0.2 (I've tried both in the example above)
However, this set up is not working - when I try to visit the site in a browser I get an NGINX 504 gateway timeout error.
Guessing I'm missing something, but not sure what.
Happy to use docker compose if I need to, happy to mount volumes into the container if I need to. Just not sure what I need!:)
I'm honestly just getting quite frustrated. I feel like I keep fiddling with my nginx conf, and I'll get it working, until I restart my PC or docker. All of the docker functionality seems to be working fine, I can build and docker-compose up without problem, but it seems like every time I restart my computer or docker I have to fiddle with my nginx conf again until it works. I'm using wordpress, and currently have wordpress installed to a subdirectory wp and my wp-content in a different subdirectory at content.
My nginx configuration looks like this:
server {
listen 80;
root /var/www;
index index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
try_files $uri $uri/index.php /index.php;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass app:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
and it was working yesterday while I was working, but after restarting the PC overnight, and trying to work on the site today, I'm getting the standard php-fpm issue FastCGI sent in stderr: "Primary script unknown". I'm just curious if anybody has a solution, or knows why I'm having this issue. I understand that the "Primary script unknown" error usually means that my SCRIPT_FILENAME param is bad, but it was working yesterday, and as far as I can tell should always point to /var/www/index.php, which is where my wordpress index file is.
Should I basically just hardcode $document_root/index.php ?
EDIT: I literally just rebuilt my docker containers with docker-compose build and everything is working as intended. So I guess this question is more associated with docker than nginx/php, but I would still love some guidance. Would there be some reason my docker containers are ephemeral and need rebuilding on boot everytime?
we are running nginx + php5-fpm and as part of our deployment process we use a symlink to point to the latest version of our PHP code.
In order to avoid problems with changing files when deploying new versions, we use the following nginx-config, which uses $realpath_root to send the real file path to php-fpm:
location ~* ^/(app|app_dev|config)\.php(/|$) {
fastcgi_pass php;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
}
This setup worked well for the last year while we used AWS instances. Now we switched to Google Cloud and every time we deploy a new version, our servers response time increases by factor 2-3.
After reloading PHP-fpm using kill -USR2 17 (where 17 is the process ID of the master process), response times recover to normal values.
Any suggestions how to solve this without restarting php-fpm worker processes after every release?
Best,
Tobias
I am trying to configure nginx and have the following configuration in:
/etc/nginx/sites-enabled/default
server {
server_name firstproj.dev www.firstproj.dev;
root /var/www/firstProj/web;
location / {
try_files $uri /app.php$is_args$args;
}
location ~ ^/(app_dev|config)\.php(/|$) {
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
}
location ~ ^/app\.php(/|$) {
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
internal;
}
location ~ \.php$ {
return 404;
}
error_log /var/log/nginx/project_error.log;
access_log /var/log/nginx/project_access.log;
}
where both app.php and app_dev.php are files in /var/www/firstProj/web/ folder created by symfony with no further modifications.
firstProj is a symfony project that I am currently working on and what I fail to understand here is:
Why when i access www.firstproj.dev I get
Oops! An Error Occurred The server returned a "500 Internal Server Error".
Why when I access www.firstproj.dev/app_dev.php everything is ok and I can also access my routes (eg: www.firstproj.dev/app_dev.php/homepage works perfectly fine and returns the expected response from the action in my controller)
Why when I access www.firstproj.dev/app.php I get 404 error.
I want it to work with www.firstproj.dev/homepage with no app_dev.php there but I cannot make it work that way.
Furthermore, if I access
http://localhost
I get:
Welcome to nginx!
If you see this page, the nginx web server is successfully installed
and working. Further configuration is required.
For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.
Thank you for using nginx.
I apologize if this is a rather dumb question but I'm a beginner as far server configuration is concerned.
Thank you!
So you're finding that your app_dev.php works but app.php does not work?
I've had this happen in the past and there are a few things worth checking.
Copy the contents of app_dev.php into app.php and see if www.firstproj.dev/app.php or www.firstproj.dev work. If it works then you know it's not a problem with NGINX but instead a problem with your Symfony Setup.
Have you created a cache or logs directory for prod or only for dev? Are they writable by www-data?
Have you checked /var/log/nginx/project_error.log to see if any error is showing up when trying to access app.php?
At the top of the app.php file add in the line error_reporting(E_ALL);. Now when you try to access the production version do you see any error?
Try clearing the cache for production. Depending how you have you server setup (Are you using ACL or CHOWN/CHMOD for your cache/log files?) You can run something like sudo su -u www-data php bin/console cache:clear --env prod