Archive August 2014

Apache 2.4, PHP 5.5 with php-fpm and mod_rewrite

This guide was updated on April 28, 2016 with some missed details!
– Added timeout and flush params to the External Server command, and added missing -socket
– Added missing apache modules actions and alias

So recently I’ve had trouble with the host I had been using for years (bad support, billing broke, DDOS Attacks on their other customers constantly affecting me), so I decided to move my web infrastructure to the same datacenter I run all of our game servers out of, HiVelocity. I decided to fully build this server out fresh instead of trying to clone the old one, and do things better this time around.

First I had recently done research into the performance impact of using Apache MPM-Prefork with mod_php, in that every Apache process has PHP loaded, so even static requests have PHP loaded – eating lots of resources!

I had heard about FastCGI as I had it when I used shared hosting back in the days with SuExec, but now I found something better: PHP-FPM – A special FastCGI based pool that is designed for PHP itself.

Win! so I set up Ubuntu 14.04.1 LTS, Apache 2.4 and went with the newer MPM Event module, which appears to do even better with Keep Alive requests.

So lets get Apache 2.4 with MPM-Event, PHP5 FPM and some PHP5 Modules going:

sudo apt-get install apache2-mpm-event libapache2-mod-fastcgi php5-fpm php5-cli php5-apcu php5-sqlite php5-gd php5-json php5-curl php5-mcrypt php5-mysqlnd php5-redis

By default it should be configured to use sockets, but if not, check in /etc/php5/fpm/pool.d/www.conf for:

listen = /var/run/php5-fpm.sock

And change it if its using a TCP port instead. Unix Sockets are faster as it avoids the TCP protocol.

Next up add /etc/apache2/conf-available/php5-fpm.conf and paste this in:

<IfModule mod_fastcgi.c>
AddHandler php5-fcgi .php
Action php5-fcgi /php5-fcgi
Alias /php5-fcgi /usr/lib/cgi-bin/php5-fcgi
FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -socket /var/run/php5-fpm.sock -pass-header Authorization -idle-timeout 900 -flush
<Directory /usr/lib/cgi-bin>
Require all granted
Require env REDIRECT_STATUS
</Directory>
</IfModule>

Now to enable these things! You need Actions, Alias, FastCgI and Rewrite modules for Apache.

sudo a2enconf php5-fpm
sudo a2enmod actions alias fastcgi rewrite

now here is the part that caused me so much trouble for an entire week! If you want to have mod_rewrite work, you need to edit /etc/apache2/apache2.conf and find the <Directory /var/www/> stanza

By default this has AllowOverride None, and you need to change that to AllowOverride FileInfo

Without this, rewrite rules will not work.

Following this, you should pretty much be set up with a working PHP5-FPM, with mod_rewrite on Apache MPM Event, and have Apache use a lot less resources in general.

I’m sorry if anything in this is off – I went through so many things trying to get everything working, but this is to the best of my knowledge what the final results were.

Please submit any corrections!

0

The problems with Bukkit and Contributing

I spend quite a lot of time improving the CraftBukkit’s core code, in order to make it perform better, more efficient and overall do things in a better way. I’m responsible for some of the biggest performance improvements that’s been made to the Minecraft Server.

However, if you’re not apart of the Spigot community, it’s likely you’ve not seen my name before. That’s because I’ve barely had any PR’s accepted to the CraftBukkit project.

It’s not for a lack of trying, it really all boils down to politics and policies.

I feel that CraftBukkit’s PR Policy is a reason the project went further downhill. There are countless people like myself that want to work to make the project better, but do not have the time to deal with the politics.

I’m speaking of the “holier than thou” attitude that the (original) CraftBukkit team (well, specifically certain members who handled PR’s) attitude.

It’s not that I’m lazy, it’s quite the opposite: I’m BUSY. I work a full time job to pay the bills, then another full time job to run my own Minecraft Server. I don’t have the time to contribute to Bukkit or Spigot, but I do it any ways especially when it can benefit my own server.

Every experienced developer knows designing a solution and testing and working all the bugs out is the hard part of writing code, not the syntax or styling details. However, COUNTLESS Pull Requests are closed on Bukkit purely due to minor things.

I look at it this way, if all that is “wrong” is a simple white-space on a single line or a 3 line change, then just make the fix yourself when pulling it!

This PR for example: https://github.com/Bukkit/CraftBukkit/pull/1352

Only feedback was formatting errors essentially which I resolved, then it sat for many months untouched. It then of course conflicted with newer commits.

The problem is Bukkit thinks everyone contributing is sitting around, waiting to make the next change to get it accepted. But, we can’t do that. We have other things to work on. My focus has been switched and I’m now working on the next task.

To have to stop what I’m doing, switch back to a different project/checkout, add a space and recommit and push… It’s hard to justify stopping work on something significant for such a small thing.

Essentially, Bukkit thinks we should lose 10-30+ minutes of our time, and most importantly: break concentration (and we all know how bad that is) for meaningless politics just so that the Bukkit team member doesn’t have to do a single change to the code, to save them 2 minutes.

I disagree with this ideology completely. When you are a team member of a successful open source project, your goal should be to make that product great. If someone took their time to solve a complicated issue, and bring it to production readiness, it is fairly reasonable for you to spend 5-30 minutes when pulling it to fix up tiny things, verify it works yourself, and fix up things that you want changed that does not interfere with the logic of the change itself (styling, whitespace, imports, etc).

The only reason you should be sending a PR back to the submitter is if you have a concern with the implementation, or need more details to understand the change yourself.

A project maintainers time is no more important than the contributors, and remember, its not the contributor who’s going to get the mass-praise over a major new change – its the project itself and its developers, even when they didn’t even do the hard part of a change.

Be happy that someone is helping you improve your product, and work WITH them to improve your product.

Mojang: My suggestion to you – Put someone in charge of the project who is enthusiastic about making the project great. Someone who gets excited when someone is working on “the next big change” for them, and is eager to work with them and discuss it and push for it to be included.

Please build a team of FRIENDLY people, people who are not going to personally insult everyone who tries to have low level talks, and someone who is not going to try to make others feel lesser than them.

Loosen up the PR process, and give people realistic hope that a PR might actually be pulled before the next major upgrade that conflicts the PR.

Another thing to do is encourage low level discussion and “potential” talk. Numerous times I tried to discuss the feasibility of whether or not CraftBukkit would even CONSIDER an idea. I wasn’t about to go spend 12+ hours working on a change to just be told “We don’t want to maintain a change of that scale” or “we don’t think the API should offer that”.

But every time I was told to go do it then bother them with it… And discussing the idea without showing results was met with insults.

That can not happen any more.

Spigot isn’t perfect, but is a much better place than Bukkit was, so if you can at least match Spigot, then you will have done great things for the Bukkit project.

If any Mojang member (Dinnerbone?) wants to discuss this more with me, I’m on IRC (Esper, Spigot, FreeNode) as Aikar every day.

Here’s hoping Dinnerbone is true to his word that Bukkit will be better than before!

 

0

Blog Activity on Aikar.co?

Yes, you’re eyes are not deceiving you. I am writing!

Though, I am cheating and doing many of these post all at once and scheduling them, but I am wanting to get more content up on this blog to share some of my recent learnings with building out my new server.

So, here is to some post.

I will be sharing my post with G+/Twitter/FB(Only if you Follow me, please do not Friend Request, I don’t friend many internet-only people) – So Follow me there for updates!

http://gplus.to/aikar

0

I am Senior Software Engineer and Entrepeneur. I am an enthusiast and love creating things. I operate my own side company in my free time called Starlis LLC, working in Minecraft.

I enjoy doing things right and learning modern technologies.