Any suggestion? I just don't want to give up that easy.
Installing Laravel 5 on Nginx/Ubuntu
Hi,
Does any one here have successfully installed Laravel 5 on Nginx/Ubuntu using a Digitalocean droplet? If yes, can you please describe the process you followed or point me to where I can find more information?
I followed this tutorial but I keep getting a 502 Bad Gateway error.
FYI - I have successfully installed Laravel 5 on Nginx/Ubuntu locally using Vagrant/Homestead.
And 502 error is.........?
Please check logs and response with the whole line (removing IPs/domains etc if you wish).
@bashy Excuse my ignorance but how can I check logs. thanks
You'll set them within the virtualhost, normally /var/logs/nginx/error.log or /var/log/php-fpm.log
Here is what I got running sudo vi /var/log/nginx/error.log
2015/05/28 15:12:01 [crit] 13205#0: *72 connect() to unix:/var/run/php5-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 888.888.888.88, server: mydomain.com, request: "GET / HTTP/1.1", upstream: " fastcgi://unix:/var/run/php5-fpm.sock:", host: "mydomain.com"
Thanks
You need to set that up for php5-fpm to work. Did you edit /etc/php5/fpm/pool.d/www.conf ?
user = nginx
group = nginx
listen = /var/run/php5-fpm.sock
listen.owner = nginx
listen.group = nginx
;listen.mode = 0660 // no need for this on my system but you can change yours
This is how my sudo vi /etc/php5/fpm/pool.d/www.conf looks like...
user = www-data
group = www-data
listen = 127.0.0.1:9000
listen.owner = www-data
listen.group = www-data
listen.mode = 0660
Should I change them to?
user = nginx
group = nginx
listen = /var/run/php5-fpm.sock
listen.owner = nginx
listen.group = nginx
;listen.mode = 0660
I have did that and it works perfectly for me. I have made a little guideline how I did it. I have test it few months back.
Install LARAVEL 5.0 dev on Digital Ocean
Please follow the same link for version 4.0 but
When you come to this line:
sudo composer create-project LARAVEL/LARAVEL /var/www/LARAVEL
Please stop and continue from here:
1- Go to www directory
cd /var/www
2- Create your project:
sudo composer create-project LARAVEL/LARAVEL YourProjectName dev-develop
You can eventually follow the online lesson here (start from 2:47): https://laracasts.com/series/LARAVEL-5-from-scratch/episodes/2
Do you want to remove the existing VCS (.git, .svn..) history? [Y,n]? Answer Y
3- Run following command when you finish
sudo chown -R :www-data /var/www/YourProjectName
sudo chmod -R 775 /var/www/YourProjectName/storage
4- Restart apache server
service nginx restart
5- There you go.
Yeah just update the listen part. You've setup Nginx to pass PHP files to be processed via a socket so you need to listen on that.
listen = /var/run/php5-fpm.sock
@bashy I changed my sudo vi /etc/php5/fpm/pool.d/www.conf as follow and now I'm getting this the following log error.
user = www-data
group = www-data
listen = /var/run/php5-fpm.sock
listen.owner = www-data
listen.group = www-data
;listen.mode = 0660
Error after changes
2015/05/27 14:01:32 [error] 9500#0: *35 connect() failed (111: Connection refused) while connecting to upstream, client: 489.71.657.9, server: mydomain.com, request: "GET / HTTP/1.1", up stream: "fastcgi://486.7.7.1:8907", host: "mydomain.com"
.
.
@maytham I followed the tutorial and your steps and nothing, I keep getting the same error. The only thing I couldn't create was the swapfile, I don't know if this matters because I'm using the smallest droplet (512).
Anything in php5-fpm.log file? You can check to see if the socket file is there, otherwise, just use a IP and port for the listen (127.0.0.1:9000)
It's worth mentioning that Laravel Forge sets up all this stuff (and much more) for you with minimal effort for $10. https://forge.laravel.com/
@robgeorgeuk Blah blah blah blah, not everyone wants to do that, some want to learn :)
@robgeorgeuk I'm well aware of Forge but as @bashy said, I want to learn. thank you though.
@bashy
This is what I see in sudo vi /var/log/php5-fpm.log
[28-May-2015 22:01:06] NOTICE: configuration file /etc/php5/fpm/php-fpm.conf test is successful
Sorry if that is not what you were asking for.
Not sure on connection refused...
It shouldn't use an IP if it's got this
fastcgi_pass unix:/var/run/php5-fpm.sock;
@bashy
Thank you for following along.
I checked sudo vi /etc/php5/fpm/pool.d/www.conf and line...
fastcgi_pass unix:/var/run/php5-fpm.sock;
is not there, should it be there?
No, not in that file.
It should be in your virtualhost for your website. If you followed the tutorial, it should be there. Restart php5-fpm and post any errors on startup/requesting a URL.
@bashy
Here is the latest error sudo vi /var/log/nginx/error.log
2015/05/29 08:54:37 [crit] 17539#0: *13 connect() to unix:/var/run/php5-fpm.sock failed (13: Permission denied) while connecting to upstream, client: 45.467.899.78, server: mydomain.com, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "mydomain.com"
Looks like you may need the ;listen.mode = 0660 part to be uncommented.
- uncommented
listen.mode = 0660 -
sudo service php5-fpm restart -
sudo service nginx restart
Still getting the same error.
Here is the latest error sudo vi /var/log/nginx/error.log
2015/05/29 10:04:16 [crit] 17937#0: *1 connect() to unix:/var/run/php5-fpm.sock failed (13: Permission denied) while connecting to upstr eam, client: 87.766.555.58, server: mydomain.com, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "mydomain.com"
What user are you running everything as? Check that nginx and php5-fpm are running as www-data, if not, I run mine as nginx. I do not require the listen.mode.
I'm running everything with a user I created with root privileges.
sudo vi /etc/php5/fpm/pool.d/www.conf
user = www-data
group = www-data
listen.owner = www-data
listen.group = www-data
listen.mode = 0660
Server Block (just in case)
sudo vi /etc/nginx/sites-available/mydomain.com
server {
listen 80;
listen [::]:80;
root /var/www/mydomain/public;
index index.php index.html index.htm;
server_name mydomain.com www.mydomain.com;
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;
}
}
Can I post the contents in the sudo vi /etc/nginx/nginx.conf without compromising my server?
Depends what you have in there but I guess it's okay.
Here's one of mine
user nginx;
worker_processes 8;
pid /var/run/nginx.pid;
# set open fd limit
worker_rlimit_nofile 100000;
events {
worker_connections 2048;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
client_max_body_size 100M;
sendfile on;
#tcp_nopush on;
keepalive_timeout 30;
#gzip on;
# Load virtual host conf files
include /etc/nginx/sites-enabled/*;
set_real_ip_from 199.27.128.0/21;
set_real_ip_from 173.245.48.0/20;
set_real_ip_from 103.21.244.0/22;
set_real_ip_from 103.22.200.0/22;
set_real_ip_from 103.31.4.0/22;
set_real_ip_from 141.101.64.0/18;
set_real_ip_from 108.162.192.0/18;
set_real_ip_from 190.93.240.0/20;
set_real_ip_from 188.114.96.0/20;
set_real_ip_from 197.234.240.0/22;
set_real_ip_from 198.41.128.0/17;
set_real_ip_from 162.158.0.0/15;
set_real_ip_from 104.16.0.0/12;
set_real_ip_from 2400:cb00::/32;
set_real_ip_from 2606:4700::/32;
set_real_ip_from 2803:f800::/32;
set_real_ip_from 2405:b500::/32;
set_real_ip_from 2405:8100::/32;
real_ip_header CF-Connecting-IP;
}
Here is how my sudo vi /etc/nginx/nginx.conf looks like.
1 worker_processes 4;
2 pid /run/nginx.pid;
3
4 events {
5 worker_connections 768;
6 # multi_accept on;
7 }
8
9 http {
10
11 sendfile on;
12 tcp_nopush on;
13 tcp_nodelay on;
14 keepalive_timeout 65;
15 types_hash_max_size 2048;
16 # server_tokens off;
17
18 server_names_hash_bucket_size 64;
19 # server_name_in_redirect off;
20
21 include /etc/nginx/mime.types;
22 default_type application/octet-stream;
23
24 error_log /var/log/nginx/error.log;
25
26 gzip on;
27 gzip_disable "msie6";
28
29 # gzip_vary on;
30 # gzip_proxied any;
31 # gzip_comp_level 6;
32 # gzip_buffers 16 8k;
33 # gzip_http_version 1.1;
34 # gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
35
36 ##
37 # nginx-naxsi config
38 ##
39 # Uncomment it if you installed nginx-naxsi
40
41 #include /etc/nginx/naxsi_core.rules;
42
43 # nginx-passenger config
44 # Uncomment it if you installed nginx-passenger
45
46 #passenger_root /usr;
47 #passenger_ruby /usr/bin/ruby;
48
49 # Virtual Host Configs
50
51 include /etc/nginx/conf.d/*.conf;
52 include /etc/nginx/sites-enabled/*;
53 }
mail {
57 # # See sample authentication script at:
58 # # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
59 #
60 # # auth_http localhost/auth.php;
61 # # pop3_capabilities "TOP" "USER";
62 # # imap_capabilities "IMAP4rev1" "UIDPLUS";
63 #
64 # server {
65 # listen localhost:110;
66 # protocol pop3;
67 # proxy on;
68 # }
69 #
70 # server {
71 # listen localhost:143;
72 # protocol imap;
73 # proxy on;
74 # }
75 #}
Checked if nginx is running as www-data or something else? Can't remember the default.
If in doubt
user www-data;
Otherwise change the permissions for the socket on that mode setting.
@bashy Checked if nginx is running as www-data or something else?
I know I know but how do I check that?
Oh sorry, here
// can search for www-data as well
ps aux | grep nginx
Here is what I got running ps aux | grep nginx
root 17988 0.0 0.2 86492 1400 ? Ss 10:05 0:00 nginx: master process /usr/sbin/nginx
nobody 17990 0.0 0.3 86492 1840 ? S 10:05 0:00 nginx: worker process
nobody 17991 0.0 0.4 86492 2344 ? S 10:05 0:00 nginx: worker process
nobody 17992 0.0 0.3 86492 1840 ? S 10:05 0:00 nginx: worker process
nobody 17993 0.0 0.3 86492 1840 ? S 10:05 0:00 nginx: worker process
myUserName+ 18372 0.0 0.1 11740 936 pts/0 S+ 12:50 0:00 grep --color=auto nginx
Yeah it's running as nobody. You'll want to put the part I suggested into nginx.conf and restart nginx.
Edit
Can tell Nginx what user to run as, I normally use nginx but www-data is fine. (nginx.conf)
user www-data;
@bashy
Problem solved, added user www-data; to sudo vi /etc/nginx/nginx.conf file and it did the trick.
Now, to understand this a little bit better, why wasn't user www-data; part of the nginx.conf file by default?
Is this something everybody needs to manually set on a brand new server? Should this be part of my workflow when creating a new server?
I know they are too many questions but I would like to have a better idea on how this happen.
Thanks a lot for all of your help!
Please or to participate in this conversation.