Hosting Laravel Application on Ubuntu Server - laravel

I have recently developed my first Laravel application (version 5.2.).
I now want to host the application on my client's server running Ubuntu.
Their admin managed to install and run the native Laravel application on the server which works just fine, however when I come to copy and paste my own application over, the browser returns:
403 Forbidden
nginx/1.4.6 (Ubuntu)
Accessing the public folder directly (www.example.com/public/index.php) the browser returns:
The www.example.com page isn’t working
www.example.com is currently unable to handle this request.
HTTP ERROR 500
Can anybody please help me out with the proper method of hosting my application?

Seems more like an nginx-problem. Try to change your nginx virtualhost config to this.
server {
listen 80;
server_name yoursite.tld
root /var/www/yoursite/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;
}
}

First save your file inside,
var/www/html/
Then using Terminal go to your folder
cd var/www/html/your_folder
Run Laravel application
sudo php -S localhost:8888 -t public
Make sure your port number is not same as the other Laravel instance running in the server.

Related

Deployment of Laravel project on Debian 9 using nginx

I try to deploy my Laravel project from localhost to Debian server using nginx. First of all, i followed this tutorial LINK. Ended at the end of 5. chapter. I did not get any errors. Also I successfully connect Laravel project with server DB. I use Laravel version 6, so when i was modifying newly created config file on /etc/nginx/sites-available/myFile I used laravel's deployment tutorial LINK. As my server does not have any domain, I've got only IP available. Screenshot of my config file:
Config file
When I try to open server page using IP, i got error "This page isn't working". It's because i deleted nginx's default file from sites-enabled. Before, i deleted the default file, i got only default home page of nginx.
I tried to change server_name like server_name _;, server_name "";, server_name IP. After all changes i restarted nginx server.
Any help how to run my Laravel project please? Thank you!!
EDIT: route to project: /var/www/html/OciNaCeste/BP_final
Please use the following configuration
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name localhost;
root /var/www/html/OciNaCeste/BP_final/public;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
Then restart nginx

How To Deploy Laravel Application on Nginx Ubuntu 16.04 Server?

I want to deploy simple laravel app on nginx ubuntu 16.04 server .
I have put my app inside /var/www/html folder
on my server , i have already setup php and mysql .
i have added below code in my /etc/nginx/sites-enabled/myapp.com
server {
listen 80;
listen [::]:80;
root /var/www/html/MyApp/public;
index index.php index.html index.htm index.nginx-debian.html;
charset utf-8;
server_name myapp.com;
error_log /var/log/nginx/myapp.com.log error;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
but instead of running app , it is downloading file , so i have searched and found stackoverflow link :
Nginx serves .php files as downloads, instead of executing them
But this in Not working in my case .
I have not much idea about nginx , please help me .
nginx will show error 502 (bad gateway) when php-fpm is not running or it can't find the socket.
In your case, I think the problem is on this line:
fastcgi_pass unix:/run/php/php7.0.22-fpm.sock;
try changing it to
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
save and reload or restart nginx.

Laravel 4.2 on Nginx getting 404 (VPS)

I'm trying to use the Laravel 4.2 on nginx. I have a VPS (Dreamhost) and I put the Laravel framework inside the root path of user (/home/vi360/) and the public path is on /home/vi360/vide360.com.br
I've been researching several ways to set up nginx for Laravel, but I'm not getting any success. Only the home page is opening (www.vide360.com.br), but all the other pages (directed by /home/vi360/app/routes.php) are returning with error 404.
I have created the /home/vi360/nginx/vide360.com.br/vide360.conf as follows:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /home/vi360/vide360.com.br;
index index.php index.html index.htm;
server_name [server ip address];
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri =404;
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;
}
}
What am I maybe doing wrong?
I guess you changed the public folder name.
Laravel looks up its files in public folder. Say your laravel application running on /home/vi360 then your public folder path will be /home/vi360/public.
Then on your nginx, it should be like
root /home/vi360/public;
Try renaming the vide360.com.br folder back to public and it will be fine. This is because the framework follows the request by booting up and forwarding it to public/index.php file.
Don't forget to restart nginx and php-fpm after the settings change.
EDIT
If the developer wants to change the public directory of laravel from public folder to other folder, say vide360.com.br, then edit your Application Service Provider (ASP) which is located at App\Providers\AppServiceProvider.php. And under the register method add the code with your new public folder name.
$this->app->bind('path.public', function() {
return base_path().'/vide360.com.br';
});

Don't think I have php setup right in nginx virtual host configs

I'm trying to install magento php ecommerce on a virtual server that previously did not have php. When I put simple php pages into a directory they run (for example I have index.php run phpinfo). But when I try to run the magento setup scripts they bomb out without outputting an error. I have two other virtual servers through a different service (running apache) and when I drop the magento files into them the setup pages light up right away and start checking requirements. On my nginx server the only output is a small grey box, but no error output.
My best guess is that I have not configured nginx virtual hosts properly for php.
I am on php5.5 using fpm on Ubuntu 12.04. I don't run a default file in sites-enabled, just two vhost files. Here's the vhost in question (the other site is working fine, but it's python):
server {
listen 80;
listen [::]:80;
#
server_name magento.mydomain.com;
#
root /var/www/magento.mydomain.com/public_html;
index index.php index.html index.htm;
#
# location / {
# try_files $uri $uri/ /index.php =404;
# }
# location / {
# /index.php;
# }
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:8070;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/magento.mydomain.com/public_html/$fastcgi_script_name;
}
}
You can see my commented out location / directives. I have tried those is various fashion. My hunch was that magento was calling php with directory names only (instead of somedir/index.php) so I was messing with those, but it seems like that would be handled by the index directive before the locations.
I'm pretty green with nginx. Does anyone see anything obvious?

Nginx on Ubuntu Server throws 404 not found

After rebooting the laravel-based website on a Ubuntu server using nginx, and configured everything properly (hopefully, at least it worked before), I can only access to the index page but not any other page - nginx keeps throwing 404 not found.
Thought it could be permission issue but I've already tried
sudo chown -R :www-data /var/www/foo-bar
sudo chmod -R 775 /var/www/foo-bar/storage
sudo chmod -R 775 /var/www/foo-bar/resources
But seems not helping. And here is my nginx config file:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www/foo-bar/public;
index index.php index.html index.htm;
server_name 120.25.203.113;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri /index.php =404;
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?
(Try http://120.25.203.113/ and click on the center button to have a look if interested!)
Update: the error log shows
[error] 24119#0: *77 open() "/var/www/ozunimate/public/student/register" failed (2: No such file or directory), client: 14.202.230.9, server: 120.25.203.113, request: "GET /student/register HTTP/1.1", host: "120.25.203.113", referrer: "http://120.25.203.113/"
"student/register" is not under /public and should be redirected (it used to be redirected normally before rebooting). Seems redirect not working anymore.
Let me answer my question.
All the configs are fine - it turned out that the autoloader is not working. See in the error log nginx didn't redirect http requests to the right directories. It should be working fine, but I guess it's polluted somehow during rebooting.
Solution:
1. in the remote server: composer install
2. if not working, simply restore the entire server and boot again. It's a booting problem anyway.
That might be right. However for me I was missing the following:
location / {
# This line
#try_files $uri $uri/ /index.php$is_args$args;
# OR this
try_files $uri $uri/ /index.php?$query_string;
}
That solved the problem!

Resources