I've hit a wall while setting up a new localhost on windows 8. The setup was done with laragon (3.0.5) and is comprised of:
php 7.1.5
laravel 5.4.24
nginx 1.12.0
The config file for nginx is
server {
listen 8080;
server_name new_project.dev *.new_project.dev;
root "C:/lar/laragon/www/new_project/dir1/";
index index.html index.htm index.php;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass php_upstream;
#fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
charset utf-8;
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
location ~ /\.ht {
deny all;
}
}
in routes/web.php I have added the following route
Route::get('/foo', function () {
return 'Everything is awesome!';
});
I would expect when going to http://new_project.dev:8080/dir1/public/foo to see the string "Everything is awesome!", instead i get a 404 from nginx.
Absolutely any help will be more than appreciated.
---- UPDATE 1 ----
Again in routes/web.php there is the following route
Route::get('/', function () {
return 'You are on the home page.';
});
When I go to http://new_project.dev:8080/dir1/public/ I get a 200 and the expected string.
You are using Laragon's power but you destroyed it with wrong setting and wrong url.
Your setting must like this: (note the public/)
root "C:/lar/laragon/www/new_project/dir1/public/";
Now, your life is easier - this url should work:
http://new_project.dev:8080/foo
new_project/dir1/ is a part of your root directive and it must not be in request as all file and script searches are doing relative to it. Correct request is http://new_project.dev:8080/public/foo
With your current configuration I think this make work. I updated the try_files index.php location
server {
listen 8080;
server_name new_project.dev *.new_project.dev;
root "C:/lar/laragon/www/new_project/dir1/";
index index.html index.htm index.php;
location / {
try_files $uri $uri/ /public/index.php$is_args$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass php_upstream;
#fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
charset utf-8;
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
location ~ /\.ht {
deny all;
}
}
Although I am not sure about your configuration, I would suggest you set your project root to the public folder instead of having to do /public. You would then leave the try_files from above as it once was.
Laravel Homestead is also a great choice for setting up a dev enviroment: https://laravel.com/docs/5.4/homestead
Related
I have started off with a docker image which has a processor for php files in place.
Requesting the normal index.php file goes without issue, but the routes I added are less accessible.
One of the routes for example is /time, accessing this is done (with the php builtin webserver) with
index.php/time, and it would return me the time. Now the docker I used has php working perfectly, just that I think one of the rules is breaking this functionality for me. tried a lot of changes, but cant seem to find the issue.
$app->get('/time', function ($request, $response, $args) {
// Current Unix timestamp
$seconds = time();
// Current Unix timestamp with microseconds
$milliseconds = microtime(true)*1000;
// Nanosecond precision
// This is default as per InfluxDB standard
$nanoseconds = $milliseconds*1000000;
// Return
return $response->withJson(array(
'seconds' => $seconds,
'milliseconds' => intval($milliseconds),
'nanoseconds' => intval($nanoseconds)
), 200);
});
This is the configuration of the nginx server I am serving in the docker. One of the things I have tried is adding the location /ping { line. But to no avail, /ping, /time keep redirecting to a 404 not found.
server {
listen 80; ## listen for ipv4; this line is default and implied
listen [::]:80 default ipv6only=on; ## listen for ipv6
root /var/www/html/public;
index index.php index.html index.htm;
# Make site accessible from http://localhost/
server_name _;
# Disable sendfile as per https://docs.vagrantup.com/v2/synced-folders/virtualbox.html
sendfile off;
# Add stdout logging
error_log /dev/stdout info;
access_log /dev/stdout;
# Add option for x-forward-for (real ip when behind elb)
#real_ip_header X-Forwarded-For;
#set_real_ip_from 172.16.0.0/12;
location /ping {
try_files $uri $uri/ /index.php/ping;
}
location / {
# First attempt to serve request as file, then
# as directory, then fall back to index.html
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
location = /404.html {
root /var/www/errors;
internal;
}
location ^~ /sad.svg {
alias /var/www/errors/sad.svg;
access_log off;
}
location ^~ /twitter.svg {
alias /var/www/errors/twitter.svg;
access_log off;
}
location ^~ /gitlab.svg {
alias /var/www/errors/gitlab.svg;
access_log off;
}
# pass the PHP scripts to FastCGI server listening on socket
#
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_index index.php;
include fastcgi_params;
}
location ~* \.(jpg|jpeg|gif|png|css|js|ico|webp|tiff|ttf|svg)$ {
expires 5d;
}
# deny access to . files, for security
#
location ~ /\. {
log_not_found off;
deny all;
}
location ^~ /.well-known {
allow all;
auth_basic off;
}
}
I have a machine with latest PHP and MySQL. I need to use Nginx. I managed to serve Omeka using this recipe:
https://www.nginx.com/resources/wiki/start/topics/recipes/omeka/
When I go to my address I am presented with the ‘Install Omeka S - Create the first user’ page. When I fill it in and I submit, the response is the same page with an empty form, i.e. I’m stuck in a loop. The POST response in the browser console gives me a 404-not found error.
I feel I’m very close, can anyone shed some light on this? I feel that Omeka should not support Apache exclusively. Is this a Omeka-s issue? Am I overlooking something obvious?
Thanks.
OK, I found out what the issue is. The Nginx recipe I linked in my question is valid for Omeka, not Omeka-s. For Omeka-s one has to remove the /install and also edit the /admin location. This is the working configuration:
server {
server_name omeka.domain.tld;
root /var/www/omeka;
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ~ \..*/.*\.php$ {
return 403;
}
location / {
try_files $uri /index.php?$args;
}
location /admin {
try_files $uri /index.php?$args;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
#NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors on;
fastcgi_pass unix:/tmp/phpfpm.sock;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
}
Update
I've pushed this recipe to Nginx wiki:
https://www.nginx.com/resources/wiki/start/topics/recipes/omeka-s/
I have two projects both using identical nginx configurationg, only difference is host name and path to web directory:
server {
listen 80;
server_name {project_host};
root /var/www/{project_path}/web;
index index.html index.htm index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_log /var/log/nginx/{project_name}_error.log;
access_log /var/log/nginx/{project_name}_access.log;
error_page 404 /index.php;
sendfile off;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_index index.php;
}
location ~ /\.ht {
deny all;
}
}
both in the web dir has folder docs which has all swagger-ui files with index.html.
All is working fine for project one, I can get access to swagger ui using url prject1/docs/index.html, but in case of project 2 when I going to project2/docs/index.html I'm getting my not found page which should be shown by php when a route is not found. Why in case of app 1 nginx understand that /docs/index.html is not route but in case of app 2 it's considering it as a route instead of path to the file if configurations the same
My web dir structure is (identical for both projects) :
web/
index.php
docs/
index.html
other_swagger_ui_files
Maybe it'll also be useful, both projects are kind of microservices, and locally I have a docker-compose configuration to start and up them, so they both under the same network and using the same Nginx-proxy container and sharing same PHP container, but each of them has own Nginx container (but as I already told they identical and have identical configuration)
I have installed the Homestead VM and setup the Moodle installation folder on my Mac (OSX Yosemite). I also created the 'moodledata' folder and gave it the permissions 0777 as well as the folder 'moodledata/sessions' via my system command line (I tried doing this via SSH inside the VM but it didn't appear to change the permissions). However checking the permissions after doing it via my system showed the folder was writable from inside the VM.
I then moved on to the installation which ran through and created the DB tables and did the check which showed 2 check warnings:
Intl and xmlrpc to check
I don't believe these are essential for initial installation so carried on. It is when I get to the admin user creation where I am getting a problem. The page (/user/editadvanced.php?id=2) stops loading any images and when I post the form I get an error: 'Incorrect sesskey submitted, form not accepted!'
I thought this could be down to the session not being writable in the moodledata folder but as I have checked that now I am out of ideas!
I have attached a couple of screenshots.
Many thanks, Mike.
Ok after a good few days of head scratching I fixed my own issue by editing the NGINX config file. Below is what it was by default:
server {
listen 80;
server_name example.com;
root /home/forge/example.com;
# FORGE SSL (DO NOT REMOVE!)
# ssl_certificate;
# ssl_certificate_key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
index index.html index.htm index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log off;
error_log /var/log/nginx/example.com-error.log error;
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
And this is what I changed it to and it now works:
server {
listen 80;
server_name example.com; #REPLACE SERVER NAME
root /var/www/example.com/www/; #REPLACE MOODLE INSTALL PATH
error_log /var/www/example.com/log/example.com_errors.log; #REPLACE MOODLE ERROR LOG PATH
access_log /var/www/example.com/log/example.com_access.log; #REPLACE MOODLE ACCESS LOG PATH
rewrite ^/(.*\.php)(/)(.*)$ /$1?file=/$3 last;
location / {
index index.php index.html index.htm;
try_files $uri $uri/ /index.php;
}
fastcgi_intercept_errors on;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
I haven't had time to see which part/parts of the above config fixed the issue, maybe someone who knows can see straight away? I suspect it could be the rewrite rule? Either way I hope this helps someone else in the future and I am really happy to get this working!
I can confirm is just the rewrite part for that specific config file, although in the Moodle Nginx page it's not documented that way.
My guess is that the location ~ [^/]\.php(/|$) { part is doing the same thing as the rewrite rule rewrite ^/(.*\.php)(/)(.*)$ /$1?file=/$3 last; and the location ~ \.php$ { directive. Will need to make some test changing the location directive to see if that works as well.
I am looking for some help configuring my nginx to allow laravel routes to work correctly, I have found numerous tutorials giving slightly different ways but to no avail.
following: nginx configuration for Laravel 4 seems quite close to what I need, however I am getting the error No input file specified.
when I look into the error log I can see that instead of my route going to eg
/url/index.php/args
it is instead being routed to /url/args/index.php
This is my nginx app configuration file, and it's all you need to make it work, and, nginx doesn't make use of .htaccess:
server {
listen 80;
server_name laravel.dev;
root /var/www/laravel/public/;
index index.html index.htm index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log /var/log/nginx/laravel.dev-access.log combined;
error_log /var/log/nginx/laravel.dev-error.log error;
error_page 404 /index.php;
sendfile off;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
I managed to get my site working, I think at least one of the configs I had already tried was correct however my sites-enabled copy of the config was a copy and not a symlink so my changes weren't actually updating.