fideloper / Vaprobash

Vagrant Provisioning Bash Scripts
1.93k stars 497 forks source link

Server error 500 issues with Apache and PHP #184

Closed LimeBlast closed 10 years ago

LimeBlast commented 10 years ago

Freshly provisioned servers with Apache and PHP are getting a Server Error 500 when trying to serve php files via Apache.

The error log for apache shows the following:

FastCGI: comm with server "/usr/lib/cgi-bin/php5-fcgi" aborted: idle timeout (30 sec)
FastCGI: incomplete headers (0 byets) received from server "/usr/lib/cgi-bin/php5-fcgi"

Poking around on the server has shown than /usr/lib/cgi-bin/php5-fcgi doesn't exist, which I think is the cause of the issue.

My theory is that this commit: https://github.com/fideloper/Vaprobash/commit/48e5d4370838eff6174fe7b46ac0f9cef6c8d6ed either didn't work, or has since broken.

fideloper commented 10 years ago

I've been using Vapro since that commit for weeks.

That's not to say something else isn't broken. You uncommented ONLY apache/php in the Vagrantfile, right?

LimeBlast commented 10 years ago

My Vagrant file currently looks like the following

# -*- mode: ruby -*-
# vi: set ft=ruby :

# Config Github Settings
github_username = "LimeBlast"
github_repo     = "Vaprobash"
github_branch   = "master"
project_name    = "unknowntales.net"

# Server Configuration
server_ip             = "192.168.56.101"
server_memory         = "1024" # MB
server_timezone       = "UTC"

# Database Configuration
mysql_root_password   = "root"   # We'll assume user "root"
mysql_version         = "5.5"    # Options: 5.5 | 5.6
pgsql_root_password   = "root"   # We'll assume user "root"
mariadb_version       = "10.0"   # Options: 5.5 | 10.0
mariadb_root_password = "root"   # We'll assume user "root"

# Languages and Packages
ruby_version          = "latest" # Choose what ruby version should be installed (will also be the default version)
ruby_gems             = [        # List any Ruby Gems that you want to install
  "bundler",
]
php_version           = "latest" # Options: latest|previous|distributed   For 12.04. latest=5.5, previous=5.4, distributed=5.3
composer_packages     = [        # List any global Composer packages that you want to install
  "phpunit/phpunit:3.7.*",
  "codeception/codeception=*",
  "phpspec/phpspec:2.0.*@dev",
]
laravel_root_folder   = "/vagrant" # Where to install Laravel. Will `composer install` if a composer.json file exists
symfony_root_folder   = "/vagrant/symfony" # Where to install Symfony.
nodejs_version        = "latest"   # By default "latest" will equal the latest stable version
nodejs_packages       = [          # List any global NodeJS packages that you want to install
  "grunt-cli",
  "gulp",
  "bower",
  "yo",
]

Vagrant.configure("2") do |config|

  # Set server to Ubuntu 12.04
  config.vm.box = "precise64"

  config.vm.box_url = "http://files.vagrantup.com/precise64.box"
  # If using VMWare Fusion Provider:
  # config.vm.box_url = "http://files.vagrantup.com/precise64_vmware.box"

  # Create a hostname, don't forget to put it to the `hosts` file
  config.vm.hostname = "vagrant"

  # Create a static IP
  config.vm.network :private_network, ip: server_ip

  # Use NFS for the shared folder
  config.vm.synced_folder ".", "/vagrant"

  # If using VirtualBox
  config.vm.provider :virtualbox do |vb|

    # Set server memory
    vb.customize ["modifyvm", :id, "--memory", server_memory]

    # Set the timesync threshold to 10 seconds, instead of the default 20 minutes.
    # If the clock gets more than 15 minutes out of sync (due to your laptop going
    # to sleep for instance, then some 3rd party services will reject requests.
    vb.customize ["guestproperty", "set", :id, "/VirtualBox/GuestAdd/VBoxService/--timesync-set-threshold", 10000]

    # Prevent VMs running on Ubuntu to lose internet connection
    # vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
    # vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]

  end

  # If using VMWare Fusion
  config.vm.provider :vmware_fusion do |vb|

    # Set server memory
    vb.vmx["memsize"] = server_memory

  end

  ####
  # Base Items
  ##########

  # Provision Base Packages
  config.vm.provision "shell", path: "https://raw.github.com/#{github_username}/#{github_repo}/#{github_branch}/scripts/base.sh"

  # Provision PHP
  config.vm.provision "shell", path: "https://raw.github.com/#{github_username}/#{github_repo}/#{github_branch}/scripts/php.sh", args: [php_version, server_timezone]

  # Enable MSSQL for PHP
  # config.vm.provision "shell", path: "https://raw.github.com/#{github_username}/#{github_repo}/#{github_branch}/scripts/mssql.sh"

  # Provision Oh-My-Zsh
  # config.vm.provision "shell", path: "https://raw.github.com/#{github_username}/#{github_repo}/#{github_branch}/scripts/zsh.sh"

  # Provision Vim
  # config.vm.provision "shell", path: "https://raw.github.com/#{github_username}/#{github_repo}/#{github_branch}/scripts/vim.sh"

  ####
  # Web Servers
  ##########

  # Provision Apache Base
  config.vm.provision "shell", path: "https://raw.github.com/#{github_username}/#{github_repo}/#{github_branch}/scripts/apache.sh", args: server_ip

  # Provision HHVM
  # Install HHVM & HHVM-FastCGI
  # config.vm.provision "shell", path: "https://raw.github.com/#{github_username}/#{github_repo}/#{github_branch}/scripts/hhvm.sh"

  # Provision Nginx Base
  # config.vm.provision "shell", path: "https://raw.github.com/#{github_username}/#{github_repo}/#{github_branch}/scripts/nginx.sh", args: server_ip

  ####
  # Databases
  ##########

  # Provision MySQL
  config.vm.provision "shell", path: "https://raw.github.com/#{github_username}/#{github_repo}/#{github_branch}/scripts/mysql.sh", args: [mysql_root_password, mysql_version]

  # Provision PostgreSQL
  # config.vm.provision "shell", path: "https://raw.github.com/#{github_username}/#{github_repo}/#{github_branch}/scripts/pgsql.sh", args: pgsql_root_password

  # Provision SQLite
  config.vm.provision "shell", path: "https://raw.github.com/#{github_username}/#{github_repo}/#{github_branch}/scripts/sqlite.sh"

  # Provision Couchbase
  # config.vm.provision "shell", path: "https://raw.github.com/#{github_username}/#{github_repo}/#{github_branch}/scripts/couchbase.sh"

  # Provision CouchDB
  # config.vm.provision "shell", path: "https://raw.github.com/#{github_username}/#{github_repo}/#{github_branch}/scripts/couchdb.sh"

  # Provision MongoDB
  # config.vm.provision "shell", path: "https://raw.github.com/#{github_username}/#{github_repo}/#{github_branch}/scripts/mongodb.sh"

  # Provision MariaDB
  # config.vm.provision "shell", path: "https://raw.github.com/#{github_username}/#{github_repo}/#{github_branch}/scripts/mariadb.sh", args: [mariadb_root_password, mariadb_version]

  ####
  # Search Servers
  ##########

  # Install Elasticsearch
  # config.vm.provision "shell", path: "https://raw.github.com/#{github_username}/#{github_repo}/#{github_branch}/scripts/elasticsearch.sh"

  ####
  # Search Server Administration (web-based)
  ##########

  # Install ElasticHQ
  # Admin for: Elasticsearch
  # Works on: Apache2, Nginx
  # config.vm.provision "shell", path: "https://raw.github.com/#{github_username}/#{github_repo}/#{github_branch}/scripts/elastichq.sh"

  ####
  # In-Memory Stores
  ##########

  # Install Memcached
  config.vm.provision "shell", path: "https://raw.github.com/#{github_username}/#{github_repo}/#{github_branch}/scripts/memcached.sh"

  # Provision Redis (without journaling and persistence)
  # config.vm.provision "shell", path: "https://raw.github.com/#{github_username}/#{github_repo}/#{github_branch}/scripts/redis.sh"

  # Provision Redis (with journaling and persistence)
  # config.vm.provision "shell", path: "https://raw.github.com/#{github_username}/#{github_repo}/#{github_branch}/scripts/redis.sh", args: "persistent"
  # NOTE: It is safe to run this to add persistence even if originally provisioned without persistence

  ####
  # Utility (queue)
  ##########

  # Install Beanstalkd
  config.vm.provision "shell", path: "https://raw.github.com/#{github_username}/#{github_repo}/#{github_branch}/scripts/beanstalkd.sh"

  ####
  # Additional Languages
  ##########

  # Install Nodejs
  config.vm.provision "shell", path: "https://raw.github.com/#{github_username}/#{github_repo}/#{github_branch}/scripts/nodejs.sh", privileged: false, args: nodejs_packages.unshift(nodejs_version)

  # Install Ruby Version Manager (RVM)
  # config.vm.provision "shell", path: "https://raw.github.com/#{github_username}/#{github_repo}/#{github_branch}/scripts/rvm.sh", privileged: false, args: ruby_gems.unshift(ruby_version)

  ####
  # Frameworks and Tooling
  ##########

  # Provision Composer
  config.vm.provision "shell", path: "https://raw.github.com/#{github_username}/#{github_repo}/#{github_branch}/scripts/composer.sh", privileged: false, args: composer_packages.join(" ")

  # Provision Laravel
  # config.vm.provision "shell", path: "https://raw.github.com/#{github_username}/#{github_repo}/#{github_branch}/scripts/laravel.sh", args: [server_ip, laravel_root_folder]
  # (not using this because we have a custom solution below)

  # Provision Symfony
  # config.vm.provision "shell", path: "https://raw.github.com/#{github_username}/#{github_repo}/#{github_branch}/scripts/symfony.sh", args: [server_ip, symfony_root_folder]

  # Install Screen
  config.vm.provision "shell", path: "https://raw.github.com/#{github_username}/#{github_repo}/#{github_branch}/scripts/screen.sh"

  # Install Supervisord
  config.vm.provision "shell", path: "https://raw.github.com/#{github_username}/#{github_repo}/#{github_branch}/scripts/supervisord.sh"

  # Install Mailcatcher
  config.vm.provision "shell", path: "https://raw.github.com/#{github_username}/#{github_repo}/#{github_branch}/scripts/mailcatcher.sh"

  # Install git-ftp
  # config.vm.provision "shell", path: "https://raw.github.com/#{github_username}/#{github_repo}/#{github_branch}/scripts/git-ftp.sh", privileged: false

  ####
  # Unknown Tales
  ##########

  # Update Vhosts
  config.vm.provision "shell", path: "https://raw.github.com/#{github_username}/#{github_repo}/#{github_branch}/projects/#{project_name}/01_vhosts.sh", args: server_ip

  # Creating Databases
  config.vm.provision "shell", path: "https://raw.github.com/#{github_username}/#{github_repo}/#{github_branch}/projects/#{project_name}/02_database.sh", args: mysql_root_password

  # Laravel Bits
  config.vm.provision "shell", path: "https://raw.github.com/#{github_username}/#{github_repo}/#{github_branch}/projects/#{project_name}/03_laravel.sh"

  # Miscellaneous Global
  config.vm.provision "shell", path: "https://raw.github.com/#{github_username}/#{github_repo}/#{github_branch}/extras/misc.sh"

end
LimeBlast commented 10 years ago

I'm going to try and brand new and fresh provisioning, without any customisations, enabling only Apache and PHP to see what happens. I'll report back once it's done.

fideloper commented 10 years ago

Thanks! Yea let's reduce the variables on this to see the most base-line version with the issue.

LimeBlast commented 10 years ago

You can track my progress by using: https://github.com/LimeBlast/fixing-vaprobash - I've just set the vagrant up, this might take a while :)

fideloper commented 10 years ago

Cool. I have to disappear for a while since I'm at work and haven't actually done any work yet :D I'll check in and test more out this afternoon. Thanks for your help!

On Tue, Mar 4, 2014 at 9:09 AM, Daniel Hollands notifications@github.comwrote:

You can track my progress by using: https://github.com/LimeBlast/fixing-vaprobash - I've just set the vagrant up, this might take a while :)

Reply to this email directly or view it on GitHubhttps://github.com/fideloper/Vaprobash/issues/184#issuecomment-36626754 .

LimeBlast commented 10 years ago

LOL, yeah, I'm at work too whoops - meh, it's for their benefit ;)

LimeBlast commented 10 years ago

OK, results of my most basic test - fails.

As of this commit (which includes nothing except provision Apache and PHP), it's failing.

Visiting http://192.168.33.10.xip.io/ and http://192.168.33.10.xip.io/index.html work as intended..

... but visiting http://192.168.33.10.xip.io/phpinfo.php takes 30 seconds, then fails with a Server Error 500.

The Apache error log shows:

FastCGI: comm with server "/usr/lib/cgi-bin/php5-fcgi" aborted: idle timeout (30 sec)
FastCGI: incomplete headers (0 bytes) received from server "/usr/lib/cgi-bin/php5-fcgi"
fideloper commented 10 years ago

Sounds like we're getting somewhere then. Can you make a gist of your install output? (instead of pasting it here). - Do you have that available still?

LimeBlast commented 10 years ago

I'll run it again and capture the output, gimme a mo :)

LimeBlast commented 10 years ago

As requested:

https://gist.github.com/anonymous/4e8783d9b0774b5351a5

montogeek commented 10 years ago

I have the same issue, yesterday in a computer's friend with a new and fresh installation and today with a new Vagrant installation on my own computer, at the start of the last week everything run with not problems, but since yesterday that error occurs.

I noticed something that when you execute vagrant up for the first time it give you a warning notification about the version of Virtual Box Guest tools and the VirtualBox version, that is the only thing different from the last week.

This is my Vagrant file https://gist.github.com/montogeek/9352175

Any idea to fix this quickly? I need to work!

[EDIT]

Here is the log from vagrant up https://gist.github.com/montogeek/9352372

fideloper commented 10 years ago

Yeah, trying to take a look this afternoon. Thanks for the vagrantfile. I'm gonna test nginx and apache without any other installs. It's possible, tho, that the Laravel installer is to blame. It does something weird where the public directory is not a directory at all and can't be read (causing a Forbidden error from Apache). Could be something else tho....

LimeBlast commented 10 years ago

Are you sure this is Laravel related? When I did my test, the only two parts enabled were Apache and PHP. On 4 Mar 2014 18:42, "Chris Fidao" notifications@github.com wrote:

Yeah, trying to take a look this afternoon. Tahnks for the vagrantfile. I'm gonna test nginx and apache without any other installs. It's possible, tho, that the Laravel installer is to blame. It does something weird where the public directory is not a directory at all and can't be read (causing a Forbidden error from Apache). COuld be something else tho.

Reply to this email directly or view it on GitHubhttps://github.com/fideloper/Vaprobash/issues/184#issuecomment-36658442 .

fideloper commented 10 years ago

If it's not, then I couldn't reproduce it. Vagrant-upping a fresh server with Apache and PHP (no laravel stuff) provisioners worked fine. I was testing the develop branch, which is now master. If you want to try, do another vagrant up (fresh server!) from the master branch - I just synced them up.

I did just push a "fix" up to Nginx, however, where if you weren't using index.php or a Symfony's default, it wouldn't work "For security" - I kept a comment in code about it, but went back to allowing any php file, since I don't want to assume specific use cases and these are for development.

fideloper commented 10 years ago

OK, just tested apache/php/compser/laravel, and that works EXCEPT 'https' urls. Ya'll aren't accidentally using https are you? Currently the php5-fpm handler doesn't accept https URLs, as I just discovered (working on it).

LimeBlast commented 10 years ago

I can't imagine this is a pc/mac thing (seeing as that is the only difference I know between our two systems). When you did your test, was it via NFS?

Even if Laravel is the cause of the issue on your machine, it could be that there are two issues (or two causes of the same issue) because I didn't have the Laravel provisioning enabled when I did my test.

LimeBlast commented 10 years ago

Nope, not using https (although I did test that as well, and it equally didn't work)

montogeek commented 10 years ago

Not, I'm not using https urls, just the default IP 192.168.33.10.xip.io or the hostname configured in the Vagrantfile.

fideloper commented 10 years ago

Are you both on Windows? We need to find what's different from your setups than others who aren't experiencing issues.

montogeek commented 10 years ago

My setup OS: Windows 7 x64 Professional VirtualBox 4.3.8 Vagrant 1.4.3

LimeBlast commented 10 years ago

OK... so it looks like this is a Windows thing... Which I don't understand, why would it make any difference what the host machine is?

Could NFS have anything to do with this?

Also, what has caused this to stop working? This worked last week, and not now!

stramel commented 10 years ago

I am running Windows 7 SP1 x64, VirtualBox v4.3.8, MINGW, Vagrant v1.4.3, and vagrant-winnfsd plugin for NFS.

Here is my Vagrantfile, vagrant up output, and error logs: https://gist.github.com/stramel/9355470

I was using NFS last week too and it worked fine, I don't believe it is a NFS issue.

montogeek commented 10 years ago

@LimeBlast Same thought here, it just stop working over the weekend

stramel commented 10 years ago

One note, I did just upgrade to VirtualBox v4.3.8 within the past week. I doubt that has anything to do with it but i'm just trying to think of any changes recently.

LimeBlast commented 10 years ago

I'm currently running VirtualBox 4.3.6 and Vagrant 1.4.3

fideloper commented 10 years ago

Tried different browsers as well?

stramel commented 10 years ago

Tried it on Chrome and Firefox, no luck.

Disabled the NFS mount and the Laravel setup ran successfully, whereas it doesn't run correctly with the NFS mount. Still getting 500 error with NFS disabled.

LimeBlast commented 10 years ago

Just tried again with NFS enabled - same issue.

Just tried in Firefox, Chome and IE - same issue.

OK, so here's what I'm thinking. This used to work, now it doesn't. The great thing about git is being able to rewind to previous commits. To this end, what I propose is the forking of the main repo, and one-by-one reverting each of the previous commits, until we get to one that works.

At that point we'll know which commit started causing the issues, and hopefully will point us in the direction of a fix.

I've just forked the repo here: https://github.com/FixitwithScience/Vaprobash - lets see what happens.

LimeBlast commented 10 years ago

I think I know what it is. I've not been able to prove this yet (because it's way too late and I'm way too tired), but I've got a feeling this issue was caused by commit 4e07c6ae2ea02fec494c393dd7ef45590f880ccb - specifically, I think it's the xdebug.remote_autostart = 1 line in php.sh.

I'll play some more tomorrow

LimeBlast commented 10 years ago

Who needs sleep ;)

I've just proven the above theory - simply commenting out the xdebug.remote_autostart = 1 line in php.sh fixes the issue.

I'm no Xdebug expert, but I've never had remote_autostart enabled - the remote_connect_back and idekey settings are far more important.

fideloper commented 10 years ago

Great. Removed that line for now and pushed it up.

stramel commented 10 years ago

+1, Great work guys! I really appreciate the help and work!

fideloper commented 10 years ago

Me too :D, that was a great call @LimeBlast

montogeek commented 10 years ago

Thanks @LimeBlast have a wonderful night!

LimeBlast commented 10 years ago

zzzzz.... huh? :)

No worries. I'm just working on a pull request which will let you set your xedebug.idekey in the Vagrantfile, I'll send it over once it's done.

onema commented 10 years ago

I have a question about this. I'm getting this 500 error message after spending 30s or more debugging using php and xdebug. Currently on the latest version from master and xdebug.remote_autostart = 1 line is not present. I can continue debugging, but is annoying that the browser get's this error.

Any thoughts?

fideloper commented 10 years ago

That's interesting - are you using xdebug within an IDE?

onema commented 10 years ago

Using PHP Storm 7.1.3 on Mac OS 10.9.2 I start xdebug within the IDE. I map my files to the correct location...

I'm trying out the some of the xdebug configuration values I used in my previous vagrant dev environment and see if that makes a difference: https://github.com/onema/Vaprobash/commit/ae9861c1f76c06c7e48c246975e1e79160b79452#diff-1ae6cec60e8eb457969bf16295fcef0d

onema commented 10 years ago

No luck, i still get a timeout 😩

onema commented 10 years ago

I figure out the issue and has nothing to do with xdebug. The problem is that FastCGI is timing out before the PHP process times out. That is why even though I was still able to debug, the web server would timeout with that 500 error message.

The solution to this problem is well documented in different contexts: Increase the -idle-timeout. See

Now, how do you modify the -idle-timeout ? Edit the apache php5-fpm.conf:

sudo vi /etc/apache2/conf-enabled/php5-fpm.conf 

and add the -idle-timeout at the end of the FastCgiExternalServer line:

    <IfModule mod_fastcgi.c>
            AddHandler php5-fcgi .php
            Action php5-fcgi /php5-fcgi
            Alias /php5-fcgi /usr/lib/cgi-bin/php5-fcgi
            # MODIFY THIS LINE -----------------------------------------------------------------------------------------v
            FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -socket /var/run/php5-fpm.sock -pass-header Authorization -idle-timeout 3600 
            <Directory /usr/lib/cgi-bin>
                    Options ExecCGI FollowSymLinks
                    SetHandler fastcgi-script
                    Require all granted
            </Directory>
    </IfModule>

Now restart/reload apache and php5-fpm:

> sudo service apache2 restart 
> sudo service php5-fpm

And that's it! problem solved.

fideloper commented 10 years ago

Thanks! That's interesting. Do you know what caused the timeout to be hit? Were you running a long(ish)-running php process of some sort?

fideloper commented 10 years ago

Also, I should note that develop branch (using ubuntu 14.04) configures php5-fpm to use http instead of a unix socket, so these settings will change (the timeout can likely still be set, but it will be another way).

To match this (also in the develop branch) Apache vhost config uses mod_proxy (along with mod_fcgi), both which come with Apache 2.4+ on Ubuntu. On 12.04, we installed apache2-mpm-event and libapache2-mod-fastcgi. These are no longer available (via our usual PPA's) on 14.04 - mod_proxy seems to the the preferred way to proxy processes off to PHP other cgi/fcgi processes.

onema commented 10 years ago

@fideloper, Yeah, if you do a simple test like :

<?php 
sleep(45);
echo 'Hello, World!';

This would happen mostly when debugging. Any debugging session longer than 30 seconds would cause the server to timeout.

It does sound like you are doing a lot of work on develop branch which will deprecate the use of ubuntu 12.04 which is fine for the project... just keep us (the guys still forced to use older OS in mind :smiley: )

Also keep me posted on how you plan to manage, if at all, the different versions of OS.

fideloper commented 10 years ago

Cool - yea still figuring that out! Could end up being 2 repositories even...

On Saturday, May 3, 2014, Juan Manuel Torres notifications@github.com wrote:

@fideloper https://github.com/fideloper, Yeah, if you do a simple test like :

<?php sleep(45);echo 'Hello, World!';

This would happen mostly when debugging. Any debugging session longer than 30 seconds would cause the server to timeout.

It does sound like you are doing a lot of work on develop branch which will deprecate the use of ubuntu 12.04 which is fine for the project... just keep us (the guys still forced to use older OS in mind [image: :smiley:] )

Also keep me posted on how you plan to manage, if at all, the different versions of OS.

— Reply to this email directly or view it on GitHubhttps://github.com/fideloper/Vaprobash/issues/184#issuecomment-42122399 .