Daniel Roy
Daniel Roy

Reputation: 41

FuelPHP with Nginx routing not working

I'm new to FuelPHP and web development in general. I'm trying to redirect a user to a different controller but for some reason I can't get the page to display. The homepage displays fine and if I change the default homepage to the Blog page it displays fine.

Here is the link on the homepage: <?php echo Html::anchor('blog', 'BLOG'); ?>

Then I have the controller it points too:

class Controller_Blog extends Controller_Template {
public function action_index() {
return Response::forge(View::forge('blog/index', $views,false)->render());
}

When I click the link it takes me to 'mywebsite.com/blog' but it says "Access denied."

Here is my nginx virtual host:

server {
listen 80;
server_name mywebsite.com
index index.php index.html index.html

root /home/me/fuelphp_project/public;

location / {
index index.php
try_files $uri $uri @php_index;

location ~ \.php$ {
 deny all;
}

location @php_index {
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param FUEL_ENV "production";
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}

I'm not sure if I haven't setup FuelPHP correctly or it's Nginx. Any help would be much appreciated, thank you.

Upvotes: 2

Views: 352

Answers (1)

Daniel Roy
Daniel Roy

Reputation: 41

I managed to get it working. I will post the answer in case anyone else comes along this problem. For clarification this is on an Ubuntu 16.04 server running Nginx 1.10.0 and php7.0-fpm trying to setup for a Fuelphp project.

Using this page from ytsejam as a guide https://github.com/rajibmp/FuelPHP-Nginx/blob/master/nginx/sites-available/FuelPHP

I changed a few things to suit my situation:

  • Set the server_name to my server

  • Set the root folder to the public folder of my fuelphp project

  • I got rid of fastcgi_param SCRIPT_NAME $script and fastcgi_param PATH_INFO $path_info as they gave me errors complaining about undeclared variables.

  • the access and error log files are in /var/www/fuelphp/nginxlogs for me

  • set fastcgi_pass unix:/run/php/php7.0-fpm.sock

  • listen 80 not sure why it says to set it to port 57

Then I followed the tips given here about further setup for php7.0-fpm: How to find my php-fpm.sock?

I think that was everything. Thank you for your help ytsejam!

Upvotes: 2

Related Questions