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.
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!
Related
I'm getting this error when I serve my Joomla on server_name www.domain.com. No error if I serve the same Joomla directory with server_name test.domain.com
I have a production server that is on an AWS EC2 instance and run smoothly the last years under Apache web server and I'm trying to migrate the whole Joomla installation to be served by an NginX/PHP container on a different environment.
So I just got the files and the database and start testing. Everything was fine when I was testing on www.dev.domain.com (development environment as well to test.domain.com (production environment).
The problem popped up when I changed to www.domain.com
I've tried different server_names.
I've tried to serve an index.html file instead of my original index.php file and works fine even if I place it at the end of the URL manually or even if I set it into my nginx.conf as index;
Joomla backend (administration) works fine on www.domain.com/administrator
I tried server_name domain.com www.domain.com test.domain.com; into my configuration but only test.domain.com was functional.
*In cases with no error, the site is fully functional
server {
listen 80;
server_name domain.com www.domain.com test.domain.com;
server_name_in_redirect off;
root /var/www/html;
index index.php;
access_log /logs/access.log;
location ~ [^/]\.php(/|$) {
proxy_cache my_cache;
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
fastcgi_param HTTP_PROXY "";
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
server_tokens off;
try_files $uri $uri/ /index.php?$args;
}
}
I was expecting the site to run smoothly with no issues as it was served fine under test.domain.com server_name but I got the error bellow:
0 Cannot pass parameter 1 by reference Please try one of the following
pages: HOME PAGE
Problem Solved.
There was a published Virtual Domain into my Joomla installation. A setting configured from my predecessor system administrator or maybe my company's web developers.
So, I unpublished that through my.domain.com/administrator console components->Virtual Domains and everything went smooth as well with my
server_name www.domain.com
You should upgrade Virtual Domains component for Joomla from 1.3.1 to 1.3.2.
1.3.2 version works with PHP7.
I am currently trying to implement a wordpress on a sub-domain using nginx.
I've installed all the dependencies (php 7.2, mariadb, mysql) and configured it all.
When I try to access to the website, here is what I got :
To be more explicit: here's what I did to configure nginx in order to use wordpress:
sudo nano /etc/nginx/conf.d/location.conf
server{
server_name subdomain.domain.fr;
root /home/domain/wordpress/;
location / {
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
include fastcgi_params;
index index.php index.html index.htm;
try_files $uri $uri/ =404;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}
}
My problem is that when I first use a wordpress website, I'm used to see some CSS on the page. When I inspect this page, I can see that the css files are included, but not used. I dont understand why. I think I have a privilege issue or anything else, but it's my first time using nginx with wordpress so I must have done something wrong:
Thanks for your help
I've found a solution that works perfectly:
adding this solved all my problems :
location ~* \.(?:css|js|map|jpe?g|gif|png)$ { }
Thanks for your help
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
I try to run a simple Symfony2 application on a virtual machine. I have Nginx on this VM (generated with PuPHPet and Vagrant), but there's a problem.
When I try to access to the demo route /demo (local.dev/Symfony/web/app_dev.php/demo), Nginx force me to download a file. It seems it works the same way when I specify a random route.
I don't know how to solve this problem, I searched while 2 days for a specific configuration of Nginx but I found nothing. Here is my config file for this Symfony app :
server {
server_name test.dev;
root /var/www/local.dev/Symfony/web;
location / {
try_files $uri /app.php$is_args$args;
}
location ~ ^/(app|app_dev|config)\.php(/|$) {
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
error_log /var/log/nginx/sf-error.log;
access_log /var/log/nginx/sf-access.log;
}
Thanks for your help.
I tried to learn and configure phalcon by testing INVO sample application
It appears that the tutorial doesn't include nginx config for the testing so that I got some difficulty to test the sample application.
I used nginx as the web server, I took nginx configuration from here
Here is my nginx config:
server {
listen 80;
server_name local.phalcon.dev;
access_log /Users/mylocal/www/log/phalcon.access.log;
error_log /Users/mylocal/www/log/phalcon.error.log;
index index.php index.html index.htm;
set $root_path '/Users/mylocal/www/phalcon/current';
root $root_path;
try_files $uri $uri/ #rewrite;
location #rewrite {
rewrite ^/(.*)$ /index.php?_url=/$1;
}
location ~ \.php {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index /index.php;
include /usr/local/etc/nginx/fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {
root $root_path;
}
location ~ /\.ht {
deny all;
}
}
Looking at the tutorial, I believe the structure is like this:
webroot
invo
app
...
public
index.php
...
...
which means, webroot is my /Users/mylocal/www/phalcon/current
and I should be able to access it with this url http://local.phalcon.dev/invo
It lead to 403 forbidden which is understandable because it appears that we should rewrite path from webroot/invo to webroot/invo/public
I did some trial and error changing the configuration but found no luck, can somebody help me to configure the nginx config for that tutorial? (which means accessing it from http://local.phalcon.dev/invo)
PS:
I was able to access it by changing the $root_path into /Users/mylocal/www/phalcon/current/invoice/public
and changing the $url->setBaseUri($config->application->baseUri); into $url->setBaseUri('/'); in invo/public/index.php
but that means I accessed it from url http://local.phalcon.dev NOT http://local.phalcon.dev/invo
To access it via http://local.phalcon.dev/invo instead of http://local.phalcon.dev all you need to do now is to configure the routing. I think in your case you simply need to set the base uri as per this example:
//Setup a base URI so that all generated URIs include the "tutorial" folder
$di->set('url', function(){
$url = new \Phalcon\Mvc\Url();
$url->setBaseUri('/tutorial/');
return $url;
});
I'm also getting a feeling that you also want to use http://local.phalcon.dev for other Phalcon apps? If that's the case then it will not work. All requests are forwarded to index.php, which rules out what to do. You can create multi-module app, but you can't have different apps sittings on the same domain (without serious pain).
the only directory which should be available via url is public. You home direcotry must end with public something like:
/Users/mylocal/www/phalcon/public
and you will be able to use base dir of /:
$di->set('url', function(){
$url = new \Phalcon\Mvc\Url();
$url->setBaseUri('/');
return $url;
});
of course you can use whatever name for your public dir, but not recommended, because if you will want to use phalcon's devtools, they are working with home dir called "public"
Please check app/config/config.ini file. There is a "baseUri" section.
1. nginx root_path should be "webroot/invo/public.
2. phalcon code: app/config/config.ini -> baseUri = /
3. url: local.phalcon.dev