I'm trying to install a fresh installation of Laravel on my nginx setup.
I get presented with a blank page, and my error log states the following:
PHP message: PHP Fatal error: require(): Failed opening required '/srv/laravel/public/../bootstrap/autoload.php' (include_path='.:/usr/share/php:/usr/share/pear') in /srv/laravel/public/index.php on line 21" while reading response header from upstream, client: **.***.***.**, server: laravel.{domain}.nl, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fcgi-laravel-php-fcgi-0.sock:", host: "laravel.{domain}.nl"
I have checked if the file exists. From the cli it actually returns 1 if i use
php -r "echo file_exists(__DIR__.'../bootstrap/autoload.php');"
i have also checked if my PHP version is up to date. The version number is 5.4.4
I have also ran composer update in the application root folder, but to no avail.
I assume this has nothing to do with my nginx setup, as it does load the index.php.
I don't have too much experience with nginx though so i might be wrong.
UPDATE: I'll post the nginx config here
server {
listen *:80;
server_name laravel.{domain}.nl;
access_log /var/log/nginx/laravel.access.log;
error_log /var/log/nginx/laravel.error.log;
root /srv/laravel/public;
index index.html index.htm index.php;
# serve static files directly
location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$ {
access_log off;
expires max;
}
location / {
index index.html index.htm index.php; #try static .html file first
##try_files $uri $uri/ /index.php; <<Wrong!! this will break bundles like OneAuth for example
try_files $uri $uri/ /index.php?q=$uri&$args;
}
# catch all
error_page 404 /index.php;
location ~ [^/]\.php(/|$) {
fastcgi_index index.php;
include fcgi.conf;
fastcgi_pass unix:/var/run/php-fcgi-laravel-php-fcgi-0.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
I'm at a loss at this moment... Can anyone help me?
I'll provide more information if neccesary. Excuse me for any bad English, thank you.
1 - How did you installed Laravel?
2 - Have you tried to dump the autoload files again? If not:
composer dump-autoload
Source: Laravel docs
I found out that the open_basedir was not set so i couldn't get access to that folder. Setting the open_basedir to %app%/public got it working for me.
You can alternative disable open_basedir for that specific domain ,follow these steps :
In ispconfig3 tabs ,click on sites tab
2.Click on the laravel based site's domain
3.Now click on the options tab
3.put "none" in the PHP open_basedir field
none
4.then in the nginx Directives , put this for urls to work :
location / {
try_files $uri $uri/ /index.php?q=$uri&$args;
}
Related
With some (or very much) trial and error i was able to modify my copy and pasted nginx fastcgi php configuration from somewhere years ago to be able to run my php application in a subfolder.
But the last final step i am not able to solve is how to get nginx to pass the query string to php to be able to access the GET parameters. This is my configuration mostly perfect with only the configuration parameters missing:
server {
listen 80;
server_name project.dev;
location /app/ {
alias /path/to/my/application/;
index index.php;
try_files $uri $uri/ /app/index.php;
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
}
}
location / {
# configuration for static website
}
}
I read that there are different options you have to pass to try_files to get request parameters:
try_files $uri $uri/ /app/index.php$is_args$query_string;
try_files $uri $uri/ /app/index.php$is_args$args;
try_files $uri $uri/ /app/index.php?$query_string;
Unfortunately changing it to any of these results in my php script no longer being found because nginx resets the request to it's document root:
2016/11/25 11:54:48 [error] 45809#0: *1169 open() "/usr/local/Cellar/nginx-full/1.10.2/htmlindex.php" failed (2: No such file or directory), client: 127.0.0.1, server: project.dev, request: "GET /app/myurl?test=works HTTP/2.0", host: "project.dev", referrer: "http://project.dev/app/myurl?test=works"
Providing an absolute path for fastcgi_param SCRIPT_FILENAME does not work too producting the same error. Even setting a root configuration on the server level does not work correctly, because the separating slash for the path and the index.php is omitted everytime. But (if possible) i would prefer without setting a root directory at the server level because this project is consisting of many different folders and applications on the filesystem sharing no common directory.
You have an application installed under /path/to/my/app2/public and would like to access it using the URI /app.
Assuming that we can use /app2/ as an internal URI (which does not collide with any other public URIs served by this server - but importantly will not be seen by your customers).
You have one PHP file.
location ^~ /app {
rewrite ^/app(.*)$ /app2/public$1 last;
}
location ^~ /app2/ {
internal;
root /path/to/my;
index index.php;
try_files $uri $uri/ /app2/public/index.php$is_args$args;
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME /path/to/my/app2/public/index.php;
}
}
The first location block simply alters the internal URI to match the document root (so we can use root instead of alias). The second location block serves the static content. The third location block invokes index.php.
How index.php gets the query string is program dependent. It will use one of the parameters defined in fastcgi_params. Usually either REQUEST_URI or QUERY_STRING. Either way, both variables should be preserved with the above configuration.
The ^~ modifier ensures that these location blocks take precedence over other regular expression location blocks (should any exist). See this document for details.
The scenario is that I'd like to use Wordpress as a backend API provider for our Ember.js frontend app.
The Ember.js frontend needs to be served from the root, and the Wordpress instance ideally would be reachable by going to a subdirectory. So for example on localhost it would be http://localhost and http://localhost/wordpress
On the disk the two are deployed in /srv/http/ember and /srv/http/wordpress respectively.
I was trying to assemble the configuration going by the example on the Nginx site:
https://www.nginx.com/resources/wiki/start/topics/recipes/wordpress/
The config:
http {
upstream php {
server unix:/run/php-fpm/php-fpm.sock;
}
server {
listen 80;
server_name localhost;
root /srv/http/ember;
index index.html;
try_files $uri $uri/ /index.html?/$request_uri;
location /wordpress {
root /srv/http/wordpress;
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
#NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
include fastcgi.conf;
fastcgi_intercept_errors on;
fastcgi_pass php;
fastcgi_split_path_info ^(/wordpress)(/.*)$;
}
}
}
However this is obviously not the correct solution.
Upon trying to access the address http://localhost/wordpress/index.php I get the following in the logs:
2016/05/01 17:50:14 [error] 4332#4332: *3 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 127.0.0.1, server: localhost, request: "GET /wordpress/index.php HTTP/1.1", upstream: "fastcgi://unix:/run/php-fpm/php-fpm.sock:", host: "localhost"
The recipe isn't clear about where to put the root directive for the location of wordpress. I also tried with adding index index.php, which doesn't help either.
(Serving the Ember app works fine.)
From your question it seems that the location ~ \.php$ block is used by WordPress alone. However, it needs a root of /srv/http in order to find the script files for URIs beginning with /wordpress under the local path /srv/http/wordpress.
As there are two locations which both use the same WordPress root, it is possibly cleaner to make /srv/http the default (that is, inherited from the server block) and move root /srv/http/ember; into a separate location / block.
server {
listen 80;
server_name localhost;
root /srv/http;
location / {
root /srv/http/ember;
index index.html;
try_files $uri $uri/ /index.html?/$request_uri;
}
location /wordpress {
index index.php;
try_files $uri $uri/ /wordpress/index.php?$args;
}
location ~ \.php$ {
include fastcgi.conf;
fastcgi_intercept_errors on;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass php;
}
}
Notice that the default URI in location /wordpress is /wordpress/index.php and not /index.php as you originally had.
I have explicitly set SCRIPT_FILENAME as it may or may not appear in your fastcgi.conf file.
fastcgi_split_path_info has been removed as it is unnecessary in your specific case, and I think it would actually break WordPress the way you had it.
I have just installed a fresh copy of Laravel 5 into /var/www.
When I browse to the server I get net::ERR_CONNECTION_REFUSED.
My Nginx config (default) is:
server {
listen 80;
root /var/www/public;
index index.php index.html index.htm;
server_name _;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Any idea what I'm doing wrong?
I am also confused about sites-enabled and sites-available. Where should default actually go?
I have moved default from sites-available to sites-enabled and I am now getting a 403 with "Access denied".
You probably got net::ERR_CONNECTION_REFUSED because you hadn't told nginx what port to listen on (note the listen 80 line in your config file), so you were trying to a port that wasn't open - hence the connection refused error.
As for sites-available vs sites-enabled, that's a Debian/Ubuntu thing to make sites easier to manage - you can have many sites configured in sites-available, but only run specific ones by adding a link in sites-enabled pointing at the respective config file in sites-available.
As an example, my sites-enabled folder has
lrwxrwxrwx 1 root root 40 Feb 8 07:53 site.net -> /etc/nginx/sites-available/site.net
No copying, just a link to sites-available.
For your 403 error, look in your error log for what precisely is failing. It should be located at /var/log/nginx/error.log - look for error_log in your main conf file to get the exact location.
I am deploying Laravel application on NGINX
I have a route specified in routes.php for handling non-blade php files and well as some of my blade php files
Route::any('/{pagephp}.php',function($pagephp) {
return View::make($pagephp); //This will handle .PHP as well as blades
});
But I get No Input File specified error whenever I try to access files such as terms.blade.php
Note that I do not get error when I access specified routes. for e.g. I have signin.blade.php for which I have
Route::get('/signin',function() {
return View::make('signin');
});
When looked in to error log I see
[error] 969#0: *91 FastCGI sent in stderr: "Unable to open primary script:
/var/www/xxxx/public/terms.php (No such file or directory)" while reading response
header from upstream, client: xxxxxxxx, server: xxxx, request: "GET /terms.php HTTP/1.1",
upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host:
As per the error, NGINX is trying to look for terms.php in public directory and not sending it to the route.php
Is there any way to fix this?
My NGINX config file is as follows
server {
# Port that the web server will listen on.
listen 80;
# Host that will serve this project.
server_name xxxx;
# Useful logs for debug.
access_log /var/www/xxxx/app/storage/logs/access.log;
error_log /var/www/xxxx/app/storage/logs/error.log;
rewrite_log on;
# The location of our projects public directory.
root /var/www/xxxx/public;
# Point index to the Laravel front controller.
index index.php;
location / {
# URLs to attempt, including pretty ones.
try_files $uri $uri/ /index.php?$query_string;
}
# Remove trailing slash to please routing system.
if (!-d $request_filename) {
rewrite ^/(.+)/$ /$1 permanent;
}
# PHP FPM configuration.
location ~* \.php$ {
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;
}
# We don't need .ht files with nginx.
location ~ /\.ht {
deny all;
}
# Set header expirations on per-project basis
location ~* \.(?:ico|css|js|jpe?g|JPG|png|svg|woff)$ {
expires 365d;
}
}
If these files does not belongs to laravel framework they should not be on the directory but if in case you want to test a particular php script you can put that in public folder and that will be accessible via yourdomain.com/script.php
I found many links regarding this type of topic , so far i still could not solve my problem.
I have just installed nginx via homebrew. Here are the steps that i did :
Added site name to etc/hosts
127.0.0.1 mysite.com
On my usr/local/etc/nginx, i created folder using
mkdir sites
(most instructions i have read so far already have sites-enabled or sites-default on thier setup, but mine was clean so i created one.) Then within the folder i created file just using vim :
vim mysite
then in the file i have this :
server {
listen 80;
server_name mysite.com;
root /Users/myname/mysite/mainsite;
client_max_body_size 10M;
# serve static files
location ~ ^/(images|javascript|js|css|flash|media|static)/ {
expires 30d;
}
location / {
index index.php index.html index.htm;
try_files $uri $uri/ /index.php$is_args$args;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /opt/local/share/nginx/html;
}
location ~ \\.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param FF_BOOTSTRAP_ENVIRONMENT dev;
fastcgi_param FF_BOOTSTRAP_CONFIG webroot/dev;
fastcgi_buffer_size 1024k;
fastcgi_buffers 1024 1024k;
fastcgi_busy_buffers_size 1024k;
include /usr/local/etc/nginx/fastcgi.conf;
}
}
After this i include my created folder to nginx.conf and nginx.cnf.default but after this i still get a 404 error. The above configuration on mysite file, except for some directory changes, worked on my other computer but some how i cant replicate for it to work, I tried revising and editing my directory in root but i still get 404. Did I miss some important stuff when configuring? Or what are the other possible reasons why i cannot access mysite.com after the above configuration or how i would get 404. Also i think no other background applications are currently running because i have just restarted the computer to see it the site doesnt work.. Any more suggestions why this might be happening? Thanks in advance
404 :(
First of all you mentioned the missing sites-enabled part, probably cause you're using centos or some other distro, I've explained this part on my answer on another question
Your site isn't working because nginx can't see the config file, simply creating a folder in anywhere doesn't work, you need to tell nginx to look into you config file, if you're configuration is in usr/local/etc/nginx like you said, then you need to move this config file mysite to usr/local/etc/nginx/conf.d at least,
or create the sites-available, sites-enabled pair like I explained in my other answer and move mysite to sites-available then symlink to it inside sites-enabled
Of course make sure you point things to the right path since your nginx lives inside usr/local/etc/nginx instead of /etc/nginx