In the tradition of A look at our Python setup, today’s post is all about WebFaction’s PHP setup. While some of our specialized installers get a lot of attention, we know that PHP is an important, if not glamorous, part of many web developers’ toolbox. So let’s take a closer look.
On our servers, PHP 5.2 is the default version. It’s not the newest and shiniest, but it’s hugely popular. For example, on Web310:
$ php --version PHP 5.2.17 (cli) (built: Jan 17 2012 13:19:44) Copyright (c) 1997-2010 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2010 Zend Technologies with the ionCube PHP Loader v4.0.10, Copyright (c) 2002-2011, by ionCube Ltd., and with Zend Optimizer v3.3.9, Copyright (c) 1998-2009, by Zend Technologies
But we’re not ignoring PHP’s development. PHP 5.3 is also available:
$ php53 --version PHP 5.3.9 (cli) (built: Jan 16 2012 15:27:59) Copyright (c) 1997-2012 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies with the ionCube PHP Loader v4.0.10, Copyright (c) 2002-2011, by ionCube Ltd.
We’ve tried to provide a lot of the more popular and useful compilation options. For example, we’ve enabled libcurl support so you can start making HTTP requests, right out of the box:
<?php $c = curl_init(); curl_setopt($c, CURLOPT_URL, "http://www.webfaction.com"); curl_exec($c); curl_close($c); ?>
Here’s a complete list of the our compilation flags on a CentOS 6 (64-bit) server:
--with-libdir=lib64 --with-pdo-mysql --with-pdo-pgsql=/usr/pgsql-9.1 --enable-bcmath --enable-calendar --enable-exif --enable-ftp --enable-mbstring --enable-soap --enable-zip --with-curl --with-kerberos --with-freetype-dir --with-gd --with-gettext --with-gmp --with-iconv --with-imap --with-imap-ssl --with-jpeg-dir --with-ldap --with-mcrypt --with-mhash --with-mysql --with-mysqli --with-openssl --with-pgsql=/usr/pgsql-9.1 --with-png-dir --with-pspell --with-regex --with-tidy --with-xmlrpc --with-xsl --with-zlib --enable-fastcgi --enable-sockets --with-libxml-dir
You can see all the details on your specific machine’s PHP setup by running
In case you missed it previously, you should also know that our PHP setup allows you to send email with PHP’s built-in
mail() function. There’s no requirement to use an SMTP library to send mail (though you’re welcome to do so, if you prefer). You can send email simply, like so:
<?php $message = "Just testing sendmail\n"; mail('email@example.com', 'Help me', $message); ?>
Of course, PHP in isolation isn’t so useful; we can plug it into the web with our corresponding Static/CGI/PHP applications. They’re more flexible than meets the eye. By default, a Static/CGI/PHP application uses a traditional
php-cgi deployment method, where each PHP script is loaded and run with each request. It’s simple, effective, and perhaps best of all, doesn’t count toward your account’s memory usage.
But if you’d like to tweak your PHP deployment method, you can choose FastCGI as an alternative. Although it consumes your account’s memory, it has better performance for some applications. To use FastCGI, create a
.htaccess file in your Static/PHP/CGI application directory containing this line:
<FilesMatch \.php$> SetHandler php52-fcgi </FilesMatch>
You can also replace
php52-fcgi6 to control the number of processes FastCGI will use to serve the site.
In addition to
.htaccess, you’re free to use your own
php.ini file to configure your PHP application. For example, you can use
php.ini to set the maximum size of file uploads. See our existing Configuring PHP docs for all the details.
Finally, we have some Static/CGI/PHP-derived installers for popular tools, like WordPress and Drupal. Under the hood, they’re PHP applications through and through, so you can use what you’ve learned here to extend or customize those applications too.
We hope this gives you a better picture of what our PHP setup is capable of and what you can do with your account. If you have any questions, let us know in the comments or join us on the Q&A Community.