nginx + codeigniter configuration not working on CentOS 7? - php

I am new on nginx and try to find the issue on StackOverflow but not found the exact one on forums.
After successful installation of nginx, MySQL and php-fpm I test the php.info that was working fine.
I am moving the CodeIgniter project to the nginx from apache server. I edit the nginx.conf file that has code
server {
listen 80;
server_name 173.249.40.xxx;
# note that these lines are originally from the "location /" block
root /usr/share/nginx/html/ci;
index index.html index.htm index.php;
location /ci {
try_files $uri $uri/ /index.php;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
it was working fine for php.info like my path is http://173.249.40.xxx/ci/info.php but not working for CodeIgniter controller name like http://173.249.40.xxx/ci/index.php/Welcome when called. I try from
https://www.nginx.com/resources/wiki/start/topics/recipes/codeigniter/#
for CodeIgniter application but it also not work for me.
The CodeIgniter application path is '/usr/share/nginx/html/ci/;'
Please suggest me something. how can I fix it?

The codeigniter has it's own routing mechanism so in order to work you need from web server to pass everything you can't find to the index.php not to toss 404 messages.
So try to change your location / {...} block to the following:
location /ci/ {
# Check if a file or directory index file exists, else route it to index.php.
try_files $uri $uri/ /ci/index.php;
}
The above it's taken from the link in your question.

Related

Error on Installing Wordpress on Nginx

I'm trying to install a wordpress site in a Linux VPS with LEMP Setup. So far I've done setting up the wordpress files and setting ownership for nginx user/group on the WP directory/files, but when I go to the address to access the installation page for WP (https://domain.tld/wp-admin/install.php), I end up with a php file download instead.
Here's my virtual host configuration for the WP site:
server {
listen 80;
server_name domain.tld;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
ssl on;
ssl_certificate /directory/to/crt;
ssl_certificate_key /directory/to/key;
server_name domain.tld;
root /var/www/html/domain.tld;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?q=$uri&$args;
}
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_index index.php;
include fastcgi_params;
}
}
EDIT: I tried it in Firefox, and it's acting differently than in Chrome. The install.php page instead ends up in an error page like this:
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.
I got it working now. The error was on the virtual host's *.conf file. I got the directory for php-fpm sock wrong. So that was the reason the php is not working on the site, and instead just downloads the install.php file, and domain is ending up in error.
fastcgi_pass unix:/var/run/php5-fpm.sock; <---- I just got the directory wrong on this one.
Maybe just u forget to start your php-fpm
cd /usr/local/php7-chanxiao/etc/
../sbin/php-fpm

Laravel 5 - Nginx/PHP config issue

I'm having an issue where when I go to the /public directory it shows the Laravel app as normal, but navigating away to any other page results in it saying
No input file specified.
I am using an Nginx server with PHP 5.5.9 FPM.
I've scoured google for the last 4 hours or so, looking at every tutorial and stackoverflow page for rewriting issues in Laravel however they all yield the same result.
I've even set all the files and folders to 777 so I could see if it was some sort of permissions issue. I've checked the Laravel config and it's all set, I've no idea what is wrong.
Can anyone point me in the right direction?
The last config I tried is below:
server {
listen 80 default_server;
root /usr/share/sites/base;
index index.php
server_name localhost;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
include fastcgi_params;
}
}
I have also tried many others such as:
server {
listen 80;
server_name domain.com;
root /usr/share/sites/base;
index index.php;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
if (!-d $request_filename) {
rewrite ^/(.+)/$ /$1 permanent;
}
location ~* \.php$ {
# Server PHP config.
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$;
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~ /\.ht {
deny all;
}
}
The error "No input files specified" will nearly always be related to the fact that the wrong path was sent to php.
Looking at your 'last config tried' I can see that fastcgi_param SCRIPT_FILENAMEis not defined in your php location. You should first begin by defining it in the location :
location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name
}
Furthermore you say that you can reach the app so this means that index.php is working but not when you change page. So the problem should also come from /index.php?$args. Indeed, using this line if I try to reach yourserver.com/test and if 'test' is not a file in your root path nginx will then try request /index.php? (I had this probem). You should try only with /index.php.
EDIT : The solution was that root directive should point to the Laravel public folder, in that case /usr/share/sites/base/public.

only see 'welcome to nginx' when accessing site from public ip address

When I access my wordpress site via localhost or the local LAN address, everything works properly.
But when I access it from outside, like this: http://123.123.123/ (where 123.123.123 is my public ip) I only get the Welcome to nginx page. However, if I access http://123.123.123/wordpress, I do get a wordpress page.
What could be wrong?
The following is my nginx configuration:
server {
listen 80;
root /var/www/;
index index.php index.html index.htm;
server_name 123.123.123.123;
location / {
try_files $uri $uri/ /index.php?q=$uri&$args;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/www;
}
# pass the PHP scripts to FastCGI server listening on a UNIX socket
location ~ \.php$ {
#fastcgi_pass 127.0.0.1:9000;
# With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
How do I get started debugging this?
Since your try_files has $uri as first argument, you will hit the index.html in your /var/www and that will satisfy that, so if you put the php-argument first, or go to:
http://123.123.123.123/index.php
you should see your wordpress site.

Nginx Wordpress Configuration, PHP file in theme directory is not passed to FastCGI

I am new to NGINX configs so bear with me. Below is my configuration which works fine for the whole site:
server {
listen ...;
server_name funkyoslo.no;
#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;
location / {
root /usr/share/nginx/funkyoslo.webbr.org/html;
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?q=$uri&$args;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/funkyoslo.webbr.org/html/;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/funkyoslo.webbr.org/html/$fastcgi_script_name;
include fastcgi_params;
}
}
However, I am trying to load the file /wp-content/themes/funkyoslo/load-songs.php and it's giving me a 500 internal server error. I've checked the error logs and evidently the file isn't passed to FastCGI at all.
I tried adding the following block to no avail:
location ~ .*/wp-content/themes/funkyoslo/.*\.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/funkyoslo.webbr.org/html/wp-content/themes/funkyoslo/$fastcgi_script_name;
include fastcgi_params;
}
Any help is greatly appreciated!
Look I don't know what's wrong with your config but try this and hopefully it should work, this is the minimal config.
Notes:
Removed the index to the server block level, check link to know why
Removed root to server block level, check link to know why
Removed all extra config from the php block level, by trials I realised that I only need those two I've written.
Added http:// to fastcgi_pass, I don't know if it's really required but I got used to writting it this way.
Edit: Ok apparently I don't need the http://, I just checked.
-
server {
listen 80;
server_name funkyoslo.no;
root /usr/share/nginx/funkyoslo.webbr.org/html;
error_page 500 502 503 504 /50x.html;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php$request_uri;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass http://127.0.0.1:9000;
}
}

nginx php with wordpress at root and another app in subdirectory

I'm having some issues getting a subdirectory working on my nginx server.
I'm using nginx to serve a wordpress installation as the web root, and trying to run an additional php application at a subdirectory. Wordpress runs fine, but I cannot for the life of me get the application to run in the subdirectory without a 404, 403, or "No input file specified." error with various configurations. I'm sure there is something obvious, but I can't seem to figure it out!
Here is the relevant config:
Any help would be greatly appreciated!
server {
listen myserver.edu:8081;
server_name myserver.edu:8081;
try_files $uri $uri/ /index.php;
location / {
root /path/to/nginx/html/wordpress;
index index.php;
}
location /stacks {
alias /another/path/to/usr/local/share/stacks/php;
index index.php;
}
location ~ \.php$ {
set $php_root /path/to/nginx/html/wordpress;
include fastcgi_params;
fastcgi_pass localhost:8082;
fastcgi_param SCRIPT_FILENAME $php_root$fastcgi_script_name;
}
location ~ \stacks.php$ {
set $php_root /another/path/to/usr/local/share/stacks/php;
include fastcgi_params;
fastcgi_pass localhost:8082;
fastcgi_param SCRIPT_FILENAME $php_root$fastcgi_script_name;
}
I don't know how to do it using your alias and setting $php_root. I do know how to fix it if you make a symbolic link from the external folder into your wordpress-rootdirectory.
So using the terminal you make a symbolic link so that your stacks-subdirectory is an actual subdirectory:
ln -s /another/path/to/usr/local/share/stacks/php /path/to/nginx/html/wordpress/stacks
As an nginx-config I would use
server {
listen myserver.edu:8081;
server_name myserver.edu:8081;
root /path/to/nginx/html/wordpress;
index index.php;
location / {
try_files $uri $uri/ /index.php;
}
location /stacks {
try_files $uri $uri/ /stacks/index.php;
}
location ~ \.php$ {
fastcgi_pass localhost:8082;
include fastcgi_params;
}
}
Comment out 'try_files'. Do the sub directories start to work then? Perhaps it is processed before the 'location' directives are considered. If that's the case, then move the 'try_files' into the block for 'location /'.
I think that's a better place for 'try_files' anyway. In the current configuration, it looks like requests for files that don't exist will all be sent to Wordpress, even if they are in the 'stacks' directory.

Categories