Laravel does not appear when browsing VPS's IP - php

I've just installed Laravel 4 with nginx on my ubuntu vps following this tutorial:
https://www.digitalocean.com/community/articles/how-to-install-laravel-with-nginx-on-an-ubuntu-12-04-lts-vps
Evertything seemed to be installed fine, however when browsing it's ip adress, I still get:
It works!
This is the default web page for this server. The web server software is running but no content has been added, yet.
I thought this could have something to do with the virtual host, but that one seems to be configured correctlt aswell
server {
listen 80 default_server;
root /var/www/laravel/public/;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
# pass the PHP scripts to FastCGI server listening on /var/run/php5-fpm.sock
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Would anynone know what I'm doing wrong?
Thank you!

Your web server should point to the /public folder not the root of your laravel application.
That is /var/www/laravel/public not /var/www/laravel/.
Also make sure you restart your server to load up configuration files.

Related

Laravel app with separate php-fpm and nginx servers

Is it possible to run a Laravel app on two separated server, one with NGINX, another with PHP-FPM?
I wanted to create an upstream of PHP-FPM servers for load balancing. I've tried some NGINX configurations but it seems that both NGINX and PHP-FPM needs Laravel app files.
Note: I have separate server for static files.
[user] -request-> [nginx without laravel files] -> [php-fpm upstream with laravel files]
UPDATE
upstream php_pool {
server 192.168.1.1:9000;
}
server {
listen 80;
server_name www.example.com;
index index.php;
access_log /var/log/nginx/q_access.log;
error_log /var/log/nginx/q_error.log info;
location / {
try_files $uri $uri/index.php /index.php;
}
location ~ \.php$ {
index index.php;
fastcgi_pass php_pool;
fastcgi_index index.php;
include fastcgi_params;
}
}
I don't know what should i set for root directory cause there isn't any Laravel app files in that server. And how config \.php$ location properly?
We found solution for our scenario. PHP location should be like this:
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass php_pool;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/app/public$fastcgi_script_name;
}
With this change (SCRIPT_FILENAME) there isn't need for Laravel app files to be on the NGINX server cause all PHP requests will proxied to PHP-FPM servers.

How to make self-contained nginx and php-fpm containers properly

I have two docker-containers: nginx and php-fpm.
I want to make them self-contained (containers will clone repo from git on build) for production. But after cloning repo I need to make some initial stuff, like composer install in project folder. I can do it inside php-fpm container, because I have php there. But how to prepare code in nginx container? I don't have php there for composer.
Everything is fine, when I mount same initialized folder into both containers.
Maybe I'm doing something wrong, what is best way to do self-contained container for nginx+php-fpm?
For now I have this nginx-config:
server {
listen 80;
server_name localhost;
index index.php index.html;
# I need only /api/ path
location /api/ {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
root /var/www/public;
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass api:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
You should only have the PHP files on the FPM server. As you previously noted, you should have php cli to run composer on that server. You shouldn't need any PHP files on the nginx server. SCRIPT_FILENAME will be resolved by the CGI server so that location does not need to exist on the web proxy. If you need to make config changes to the nginx server, you probably want to use something more system oriented like Salt, Chef or Puppet.
location ~ \.php$ {
# This is the webserver root for static junk
root /var/www/public;
...
# Point this somewhere else if the docroot is in a different location on the FPM server.
fastcgi_param SCRIPT_FILENAME /home/php-fpm/wwwroot/$fastcgi_script_name;
}

Nginx Site Configuration for Development Environment

I'm currently trying to setup a generic, multi-project development environment in Vagrant for students of a web-development mentoring project. The idea is the domain <project>.vagrant maps to ~/code/<project>
I thought I had enough experience with Nginx to solve this, but it turns out I don't.
Assuming that PHP-FPM is correctly setup, I need help with the try_files/routing for the site-configuration.
Whilst the homepage (/) works fine, any request to a non-static file (which should therefore be passed to PHP-FPM) results in either a 301 Moved Permanently to the homepage, or downloads the contents of the PHP script instead of executing it.
And yes I know listing so many index files is not ideal but the students will be dealing with multiple projects (phpMyAdmin, WordPress) and frameworks (Symfony, Silex, Laravel, etc).
Any help with this would be greatly appreciated!
The contents of the single site-available configuration file so far is:
map $host $projectname {
~^(?P<project>.+)\.vagrant$ $project;
}
upstream phpfpm {
server unix:/var/run/php5-fpm.sock;
}
server {
listen 80;
server_name *.vagrant;
server_tokens off;
root /home/vagrant/code/$projectname/web;
index app_dev.php app.php index.php index.html;
autoindex on;
client_max_body_size 5M;
location / {
try_files $uri $uri/ / =404;
}
# Pass all PHP files onto PHP's Fast Process Manager server.
location ~ [^/]\.php(/|\?|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
try_files $fastcgi_script_name =404;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# Specify the determined server-name, not the literal "*.vagrant".
fastcgi_param SERVER_NAME $projectname.vagrant;
fastcgi_pass phpfpm;
}
}

NGINX server is downloading php files

i'm trying to setup nginx on my vps and i made it however when i'm try to use .php files it download then instead of runing them. This is my nginx.conf
server {
listen 80;
server_name site;
root /var/www/;
index index.php index.html;
}
Any ideas how to fix it?
(i have php5-fpm installed)
For pass the PHP scripts to FastCGI you must add this into server config:
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
}
You really need to enable php-cgi/fast-cgi or -cli depending on your server/vps configuration.
share with us more information to be able to help you (like config files etc.)

nginx hanging for subdomain

I'm having some trouble getting nginx to work on a subdomain. I have two conf files in /etc/nginx/conf.d/ as follows (some details in the first redacted):
mydomain.conf: the site proper, server_name of mydomain.com and www.mydomain.com:
server {
listen 80;
root /var/www/sites/mydomain;
index index.php;
server_name mydomain.com www.mydomain.com;
access_log /var/log/nginx/mydomain.access.log;
error_log /var/log/nginx/mydomain.error.log;
...
}
phpmyadmin.conf:
server {
listen 80;
root /var/www/sites/phpmyadmin;
index index.php;
server_name pma.mydomain.com;
access_log /var/log/nginx/phpmyadmin.access.log;
error_log /var/log/nginx/phpmyadmin.error.log;
location / {
index index.php;
}
location ~* \.php$ {
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Currently, /var/www/sites/phpmyadmin just contains an index.php with <?php phpinfo(): ?> in it and nothing else. This is on an EC2 instance and I'm trying to load the pages from another computer, wherein both mydomain.com and pma.mydomain.com are set to its IP address in my /etc/hosts.
Navigating to mydomain.com works perfectly fine, PHP works, etc. However when I navigate to the subdomain, it hangs. For any other subdomain the connection immediately fails (there are no DNS records). But for pma it simply doesn't load.
My log files for pma are empty and unhelpful. I have no idea how to debug this silent failure and it's driving me insane.
Probably an issue with the FastCGI handler (are you using php-fpm?) running at 127.0.0.1:9000 - is it running and accepting connections?
Debug it by SSHing to that machine and running:
curl -vv http://127.0.0.1:9000/
What happens?

Categories