Hi,
I have been developing Laravel on the same vagrant server for 3 weeks now, but it suddenly stopped working. I tried to reinstall everything, but it is not working now.
Error message:
502 Bad Gateway
- - - -
nginx/1.2.1
access.log:
10.11.12.1 - - [14/May/2014:10:21:39 +0000] "GET / HTTP/1.1" 502 172 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv: 29.0) Gecko/20100101 Firefox/29.0"
error.log:
2014/05/14 10:21:39 [crit] 11097#0: *1 connect() to unix:/var/run/php5-fpm.sock failed (13: Permission denied) while conne cting to upstream, client: 10.11.12.1, server: localhost, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/ph p5-fpm.sock:", host: "10.11.12.13"
Vagrantfile:
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
config.vm.box = "debian-7.4-64"
config.vm.box_url = "http://basebox.libera.cc/debian-wheezy-64.box"
config.vm.provision :shell, :path => "bootstrap.sh"
config.vm.boot_timeout = 600
config.vm.network :forwarded_port, guest: 80, host: 8080
config.vm.network :private_network, ip: "10.11.12.13"
config.ssh.username = "vagrant"
config.ssh.port = 2222
config.ssh.insert_key = true
end
bootstrap.sh:
#!/usr/bin/env bash
echo " --- Updating packages list --- "
apt-get update
# Base Packages
# -------------
echo " --- Installing Base Packages --- "
apt-get install -y vim wget curl python-software-properties
echo " --- Configuring Base Packages --- "
echo -e "syntax on\nset number\ncolorscheme koehler" > /root/.vimrc
cp /root/.vimrc /home/vagrant/.vimrc
# Remove unneeded packages
# ------------------------
echo " --- Removing unneeded packages --- "
apt-get remove -y nano
# PHP 5.5
# -------
echo " --- Adding PHP 5.5's source --- "
echo "deb http://packages.dotdeb.org wheezy-php55 all" >> /etc/apt/sources.list
echo "deb-src http://packages.dotdeb.org wheezy-php55 all" >> /etc/apt/sources.list
wget http://www.dotdeb.org/dotdeb.gpg
sudo apt-key add dotdeb.gpg
echo " --- Updating packages list --- "
apt-get update
# Install: php5, nginx, mysql, git-core
# -------------------------------------
echo " --- Installing Server Stuff --- "
export DEBIAN_FRONTEND=noninteractive
apt-get install -y nginx php5 php5-fpm php5-cli php5-mysql php5-curl php5-gd php5-mcrypt mysql-server-5.5 git-core
# Nginx
# -----
echo " --- Configuring Nginx --- "
VHOST=$(cat <<EOF
server {
server_name localhost;
root /vagrant/public;
index index.php;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
location / {
location ~* ^.+\.(?:css|cur|js|jpg|jpeg|gif|htc|ico|png|html|xml)\$ {
access_log off;
expires 30d;
sendfile off;
}
location ~ /\. {
access_log off;
log_not_found off;
deny all;
}
try_files \$uri @php;
}
location @php {
include fastcgi_params;
fastcgi_param QUERY_STRING _url=\$uri&\$args;
fastcgi_param SCRIPT_NAME /index.php;
fastcgi_param SCRIPT_FILENAME \$document_root/index.php;
fastcgi_intercept_errors on;
fastcgi_read_timeout 14400;
fastcgi_index index.php;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
location ~* ^.+\.php\$ {
return 404;
}
}
EOF
)
echo "${VHOST}" > /etc/nginx/sites-available/default
sed -i 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/' /etc/php5/fpm/php.ini
sed -i 's/listen = 127.0.0.1:9000/listen = \/var\/run\/php5-fpm.sock/g' /etc/php5/fpm/pool.d/www.conf
echo " --- Fixing permissions --- "
sed -i 's/user = www-data/user = vagrant/g' /etc/php5/fpm/pool.d/www.conf
sed -i 's/group = www-data/group = vagrant/g' /etc/php5/fpm/pool.d/www.conf
chmod -R 755 /vagrant/app/storage
echo " --- Restarting php5-fpm ---"
service php5-fpm restart
echo " --- Restarting Nginx --- "
service nginx restart
# MySQL
# -----
echo " --- Configuring MySQL ---"
echo " user: 'user', password: 'pass', database: 'demo'"
echo "FLUSH PRIVILEGES" | mysql
echo "CREATE DATABASE IF NOT EXISTS demo" | mysql
echo "CREATE USER 'user'@'localhost' IDENTIFIED BY 'pass'" | mysql
echo "GRANT ALL PRIVILEGES ON demo.* TO 'user'@'localhost' IDENTIFIED BY 'pass'" | mysql
# echo " --- Upgrading packages list --- "
# apt-get upgrade -y
# Laravel stuff
# -------------
echo " --- Installing Laravel's stuff --- "
curl -s https://getcomposer.org/installer | php
mv ./composer.phar /usr/local/bin/composer
echo " --- Configuring Laravel's stuff --- "
cd /vagrant
composer install --dev
php artisan migrate --env=development
php artisan db:seed --env=development
Any tips? Thanks!
If you upgraded to PHP 5.5.12 then open up /etc/php5/fpm/pool.d/www.conf and uncomment the following listen directives:
listen.owner = www-data
listen.group = www-data
listen.mode = 0660
Run this afterwards:
sudo service php5-fpm restart
Okay, tried this, but it does not work as expected. :(
If anybody else has the same error, try to add this before the Fixing permissions
part of the bootstrap.sh file.
echo " --- Fixing 502 Bad Gateway --- "
sed -i 's/;listen.owner = www-data/listen.owner = vagrant/g' /etc/php5/fpm/pool.d/www.conf
sed -i 's/;listen.group = www-data/listen.group = vagrant/g' /etc/php5/fpm/pool.d/www.conf
sed -i 's/;listen.mode = 0660/listen.mode = 0660/g' /etc/php5/fpm/pool.d/www.conf
Well, worked for me for all our production sites and my local vagrant server. We're using Nginx 1.6 and Ubuntu 14.04, though, so might make a difference.
Okay, I will check it again. We are using nginx 1.2.1 and Debian Wheezy if I remember correctly.
Thanks!
I updated to 1.6, but it didn't work. This will:
Just change php5-fpm.sock
's owner from root
/vagrant
to www-data
like below...
chown www-data:www-data /var/run/php5-fpm.sock
@shabushabu thanks a lot! I was having the same issue and this solved it perfectly.
I also found that comments were breaking my code causing 502 errors. I was accidentally breaking comments with @includes, by mixing comments.
I met the same issue. I found a solution to ignore the error.
Adding two lines to Nginx configuration file /etc/nginx/nginx.conf :
http {
...
fastcgi_buffers 8 16k;
fastcgi_buffer_size 32k;
...
}
i just got the same error as the thread owner, the fix i did was to open my virtualbox app (mac) and just REMOVE it and clear it all, and then just did a vagrant up and now it works again
and if you are using laravel its easy to migrate your database again
I agree with SimonJ. Delete the lot and start again. It was quick, easy and fixed the problem. I wish I'd read this thread earlier instead of trying to "fix" the problem and getting nowhere.
What I did was..... Upgrade to latest VirtualBox (4.3.16 for me) Select your virtual Machine from the list "VirtualBox/Machine/Close/Power Off", then "VirtualBox/Machine/Remove [+"Delete All files" option]" then "Close VirtualBox"
From the Terminal..... CD to your Homestead folder (for me "cd WWWBOX/VirtualBoxVM/homestead") then "Vagrant up"
Thats all there is to it. Just let Vagrant rebuild the virtual machine and you are good to go.
This will not affect any of your "Settings" as these are all contained in your Homestead.yaml file. Everything that worked before will spring into life again.
Good luck
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community