Automated Webserver Stack Build Script (Nginx + PHP + PHP-FPM + APC + memcached)
I’ve made a little script for building a webserver stack as non-root user - it can be used as a development server where everything is installed in just one directory. It installs the following:
- Nginx 0.8.9
- PHP 5.3.0
- PHP-FPM (actually a PHP patch)
- APC 3.1.3p1
- memcache 2.2.5 (pecl extension)
- memcached 1.4.0
If you’re building on Debian, run the following as root - it will skip already installed packages and install the rest. If you’re building on a different distribution, there may be some little differences in names (-devel suffix instead of -dev, …).
aptitude install build-essential bison autoconf automake libtool libevent-dev libxml2-dev libjpeg62-dev libpng12-dev zlib1g-dev libmysqlclient15-dev libpcre3-dev libssl-dev
Usage is very easy - just make a directory, save the script in it, modify it to fit your needs, make it executable and run it. You don’t need to use your root account (unless you want to build the stack in a directory you don’t have rights to - like in the following example).
So, let’s say we want to install the stack to /opt/webstack.
$ su (enter your root password) # mkdir /opt/webstack # chown angel333:users /opt/webstack # exit $ cd /opt/webstack $ wget http://pastie.org/593111.txt -O build $ chmod +x build $ ./build (-- coffee & cigarette break :-/ --)
Optional: if you have a weak Celeron (like me) then start htop and nice the process (give it some priority)..
Ready.. now run it!
Now just run the webserver and PHP fastcgi proxy..
$ sbin/php-fpm start $ sbin/nginx
Note: There are no leading slashes in the code - everything (sbin, bin, etc, …) is in your webstack directory.
If everything went ok, you should see your phpinfo() at http://localhost:8080/.
Note: You can change the listening port in etc/nginx/nginx.conf. If you run your webserver as a non-root user, you can only use ports greater than 1024.
If you’re using this stack as your development server, I suggest running memcached with -vv (2x lower V) parameter and without & (so it won’t disconnect from your terminal and you will see exactly what’s happening in the cache).
(in a separate terminal window) $ bin/memcached -vv
But if you just want to run in…
$ bin/memcached & (press enter to disconnect it from the terminal)
You can download the script from Pastie.