I love WebFaction. It is a great, incredibily cheap hosting provider that provides nearly-VPS hosting accounts.
Why “nearly-VPS”? Because you have the possibility (to some extents) to compile your own applications and use them. Add a 24/7 great and lovely support service, lots of storage and bandwidth and you will surely find in love.
It is not news that WebFactioners are able to compile libraries, servers, and tools to be used in our memory slots. We often have the need to have our personal Apache httpd server and PHP stack, to fine tune the configuration and suit our needs.
A script to build Apache httpd, mod_fcgi, mod_fastcgi, mod_php, PHP, and PHP-FPM on WebFaction
I created a bash script, called build_httpd_php-fpm.sh. It is based on the one by Christopher Sebastian, WebFaction Support. That script was probably not written for x86_64. The majority of WebFaction users are now on Centos 6.0 x86_64. The current, updated Webfaction servers no more let the originary script build the libraries and the programs. Many compilation errors arise (example).
In order to simplify and speed up the compilation of software, I stripped down the originary script a lot. The following are the main strategies that I followed when I created the script:
- Minimize the compilation of libraries and software
- Maximize the features provided
- Maximize the use of WebFaction’s already installed libraries
- Provide updated software
- Let the user define configuration files
The script build_http_php-fpm.sh builds Apache httpd 2.22.2 with MPM worker mode and the most common modules. In addition, it installs mod_fcgid, and mod_fastcgi. I also have the need to have PHP compiled with imap and secure imap. Therefore, build_http_php-fpm.sh builds the latest openssl and libc-client to be used with PHP. PHP-FPM is enabled and used per default.
As of today (2012-05-14), my modified script compiles the software and installs fine on my Webfaction account.
I personally use it to build Apache httpd for some of my websites.
I heavily tested the script before publishing it.
The following is the software downloaded and installed by the script:
- OpenSSL 1.0.0j
- Apache httpd 2.2.22 with MPM worker (default) or prefork
- mod_fcgid 2.3.7
- mod_fastcgi latest developed version
- cURL 7.24.0
- libtidy CVS version
- libc-client version imap-2007f
- PHP 5.4.3
Compile chain and patches
The following is the order of compilation. For each item, I include details about particular fixes that I adopted.
- httpd against OpenSSL
- mod_fcgid against httpd
- mod_fastcgi against httpd
- cURL against OpenSSL
- sed -i "s@runinst_prefix=/usr/local@runinst_prefix=$INSTALL_DIR@" Makefile
- sed -i "s@devinst_prefix=/usr/local@devinst_prefix=$INSTALL_DIR@" Makefile (both taken from the originary build_php_worker.sh)
- sed -i "97 s/.*/CFLAGS += -fPIC/" Makefile to enable position independent code as shared library
- Creation of $INSTALL_DIR/ssl/include and $INSTALL_DIR/ssl/include to make it see OpenSSL
- sed -i "s@SSLDIR=/usr/local/ssl@SSLDIR=$INSTALL_DIR/ssl@" src/osdep/unix/Makefile (taken from the originary script)
- sed -i '57 s/.*/#define FD_SETSIZE 32768/' src/osdep/unix/os_art.c
- sed -i '57 s/.*/#define FD_SETSIZE 32768/' src/osdep/unix/os_sv2.c
- EXTRACFLAGS=-fPIC to enable position independent code as shared library
- I would like to thank sloop for his beautiful post, which helped me to compile this library
- PHP against OpenSSL, cURL, libtidy
./configure --with-apxs2=$INSTALL_DIR/bin/apxs --prefix=$INSTALL_DIR --enable-static --enable-shared --with-mysql --with-mysqli --with-pdo-mysql --with-mysql-sock=/var/lib/mysql/mysql.sock --with-pgsql=/usr/pgsql-9.1 --with-pdo-pgsql=/usr/pgsql-9.1 --enable-bcmath --enable-calendar --enable-exif --enable-ftp --enable-mbstring --enable-soap --enable-zip --with-curl=$INSTALL_DIR --with-freetype-dir --with-gd --with-gettext --with-gmp --with-iconv --with-jpeg-dir --with-png-dir --with-regex --with-xmlrpc --with-xsl --with-zlib-dir --with-kerberos --with-mhash --with-openssl=$INSTALL_DIR --without-pear --enable-sockets --enable-intl --with-imap=$INSTALL_DIR --with-imap-ssl=$INSTALL_DIR --with-tidy=$INSTALL_DIR --enable-cgi --enable-fpm
./configure --with-mpm=$MPM --with-ldap --enable-mods-shared="all ssl ldap cache proxy authn_alias mem_cache file_cache authnz_ldap charset_lite dav_lock disk_cache" --prefix=$INSTALL_DIR --with-ssl=$INSTALL_DIR/lib
Before running the script, create a “Custom app (listening on port)”. Take note of the port and the name of the app.
Suppose that you call the application custom_apache and that it listens at port 12345.
Then, you will run the script using
KEEP_SRC=1 ./build_httpd_php-fpm.sh /home/yourusername/webapps/custom_apache 12345
I encourage you to run the script by pre-pending
KEEP_SRC=1. This will let you keep the downloaded source code and speed up things if you need to run the script again.
You can append MPM=prefork to build A MPM prefork, but I have not tested it. It should work, by the way.
As soon as it finishes to compile and install the software, build_httpd_php-fpm.sh will tell you which files to modify. Here are some hints:
- Look in conf/httpd.conf for additional modules to enable. You will probably need to disable many modules as well. For example, if you are happy with PHP-FPM, you should disable mod_php (php5_module).
- The default directory to serve files is htdocs/
- PHP-FPM creates a socket called php5-fpm.socket in sockets/
- PHP-FPM configuration is in etc/php-fpm.conf
- The default php.ini is in conf/php.ini
- Edit conf/extra/httpd-mpm.conf to suit your needs
This is how PHP-FPM is used in conf/httpd.conf. Credits: this serverfault answer by user regilero
AddHandler php5-fcgi .php
Action php5-fcgi /fcgi-bin/php5.external
Alias /fcgi-bin/php5.external /php5.external
FastCgiExternalServer /php5.external -socket $INSTALL_DIR/sockets/php5-fpm.socket -appConnTimeout 30 -idle-timeout 60
Deny from All
Allow from env=REDIRECT_STATUS
I license build_httpd_php-fpm.sh under the WTFPL license.
I would be happy to hear some feedback from you or see that somebody extends it. ImageMagick would be a great inclusion.
If you’ve never heard of Webfaction and if you want to try it out, you can use my referral to buy an account.
(Featured Image credits: Metztli IT’s blog)