Log in using your webcam on Linux

Using pam-face-authentication, you can login using your face and webcam instead of typing a password. You can also use your face to authenticate when using commands such as su and sudo, and virtually all other applications that ask for your account passowrd, even if you are in text-only mode.

For more information visit their website.

Depending on the quality of your webcam, face recognition technology generally works best in environments with plenty of light and with no variations in light intensity. In other words, it will work better on a desktop in a well-lit room that on a laptop, which will generally be moved about a lot, and have poor webcams anyway. If you use a laptop, you may need to create more than one profile for each room of the house that has a considerable lighting difference, one for outside, etc. (And no, it will not work in poorly lit or dark rooms.)

Now for installation. First, you have to install the face-authentication PAM plugin. The exact procedure varies across distributions, but it is usually in a package called pam-face-authentication. For example, Ubuntu users can install it typing this at the terminal:

  1. $ sudo add-apt-repository ppa:antonio.chiurazzi/ppa
  2. $ sudo apt-get update && sudo apt-get install pam-face-authentication

Arch Linux users can find it in the package pam-face-authentication-svn in the AUR.

Users of other distributions should be able to find a package named pam-face-authentication or similar using their package manager. If not, you can find instructions on how to compile it from source here.

Now you have to train pam-face-auth to recognise you when you login. To open the face trainer, open a terminal and type qt-facetrainer. The face trainer is mostly self-explanatory, so I won’t go into detail here. To create multiple profiles, just repeat the capture process multiple times.

Now all we have to do is configure each service you want face login to work with. All these commands must be run in a terminal with root privileges (type sudo -i or su).

# ls /etc/pam.d/

This will give you a list of services and applications that can be used with face-auth. If you don’t know what each of these are, gdm, kdm, lxdm and lightdm are display managers (the login screen that appears when you start up), su, sudo and polkit-1 handle privilege escalation (the “Please insert your password to perform xyz” prompts that appears when you perform an administrative task), and login is the text mode login prompt. Beginner users should generally start of with the display manager, su, sudo and polkit-1.

Now, you have to open each file you want to configure with the text editor:

# nano /etc/pam.d/xyz

Add the following line to the top of the file:

auth sufficient pam_face_authentication.so enableX

And then save the file (Ctrl+O), and exit (Ctrl+x). Repeat this process for all of the applications that you want to configure.
To disable face-auth, just comment the line out (add a # to the beginning of the line).

Depending on your webcam and distribution, you may also have to add the following line:


To your /etc/ld.so.preload file.

If, when you are loging in with the webcam, you close the face-login window, you will be asked for your password instead.

If you have any problems setting this up, just leave a comment below.


The Most Useful Types of Phone Apps to Have

One of the biggest—and funnest—advantages to owning smartphone over a regular cell phone is all the apps available for every smartphone, Blackberry and even iPads and iPod Touch devices. And if the thousands of apps currently available aren't enough, don't worry: Hundreds more are developed every day. There are dozens of different types of phone apps, and what someone will choose depends on several personal factors, but overall, some apps are a little more versatile, helpful and just plain convenient than others. Here are only a few of users' favorite apps that help them stay organized, informed and sometimes safer.

WiFi Locators

Whether you own an iPhone, and Android or some other type, being able to find a free WiFi site can lower your cell phone bill, provide easy Internet access for your laptop, tablet, notebook or even your phone.

Many WiFi Locator apps are free downloads, which bolsters even the tightest of budgets. Free app for free WiFi—not a bad combination at all!

Bathroom Finders

Apple has the money-saving [read: free!] SitOrSquat app that helps you find the nearest available restroom, and Android lovers can download the app with the boring but effective name, Toilet/Bathroom Finder. Paired with an on-board GPS locator, never risk accidents again.

If a separate app for this purpose doesn't quite fit the bill, perhaps combine using a restaurant and a gas station-gas pricing app can help, but why juggle two or more apps when one will do? If you happen to spot a restaurant or a gas station en route to what the specialized app shows you, all the better. That's simply using technology for a good purpose.

Medical Reference

Never be without a first aid manual again. Medscape provides a free app for both the iPhone and Android. So does WebMD, Medscape's parent reference. From bandages to splints to CPR and more, always have first aid information at your fingertips.

Most first aid and medical reference apps have emergency facility locators within their programs. Medscape has received a few negative or downgraded user reviews for a security code requirement before facilities are listed. The developers are rumored to include that security step for a possible future upgrade: Facilities may be notified of an inbound emergency, and the security code requirement would help avoid the equivalent of “prank calls” or “pocket dials” to a nearby emergency facility.


Google Translator for both the iPhone and Android has received by far the greatest number of 5 and 4-star user reviews than any other app on the market. Able to translate 50 languages and provides dictionary services, Google Translator is not only one of the most comprehensive translation services available in an app, it's free for both types of smart phones! Speak into the phone, and the words are translated for others—or for you—to read and be understood! Did you catch that this app is free?

The author of this post is Holly Miller, a writer for Coupon Croc; the best place to find savings on all the latest gadgets when you shop online with an Argos voucher.


Modify the Windows Registry from Startup Repair

Many of you will probably be familiar with Windows Vista’s and Windows 7’s Startup Repair feature. It repairs the Windows boot files, checks the disk for errors, let’s you restore your computer using System Restore, and corrects incorrect registry values. Well, most of the time. There are some errors that Startup Repair hasn’t been programmed to detect. There have been many cases where people have made an incorrect change to the registry, preventing Windows from booting, and have had to reinstall Windows. Luckily, as long as you know which registry entry you messed up, you can manually modify it from Startup Repair.

  1. First, we have to start Startup Repair. If you have Windows Vista, insert your Vista installation disk, restart your computer, when prompted, press any key to start Windows from the disk, then choose your language settings, then click Repair your computer. If you have Windows 7, restart your computer, hold F8, and then choose Repair your computer.
  2. In the System recovery options menu, choose Command Prompt.
  3. At the command prompt, type: regedit.
  4. The Registry Editor will appear. Now you just edit the registry like any other time, right? Wrong. The registry displayed in regedit at the moment is Startup Repair’s limited diagnostics environment’s registry. Any changes you make to it will be undone when you restart your computer, by the way. Now we have to load your Windows installation’s registry hives.
  5. Click on any key (for example, HKEY_LOCAL_MACHINE), open the File menu, and click on Load hive…
  6. In the box that appears, click on Computer, and open the drive where Windows is installed. Note: it might not have the same drive letter as it usually has, and it definitely won’t be X: (that’s Startup Repair’s temporary drive).
  7. Go to “Windowssystem32config”. Here you will see a list of registry hives. You’ll probably want SOFTWARE or SYSTEM.
    Registry Hives
  8. Select the registry hive of your choice. When prompted, enter a key name for that hive, for example, “windows-system“. Now a new key with the name you chose will appear inside the key you clicked in step 5. All registry entries in the hive you selected will appear under this key.
  9. When you’ve finished editing the hive, click on its key, open the File menu and click unload key. You can also have multiple keys at once loaded too.

Note: If you want to import a .reg file, for example, to add some keys and values to HKLMSystem, and you’ve got the SYSTEM hive loaded under HKLMwindows-system, you’ll have to replace all occurrences of System in the file with windows-system. To do this, in the import window, right-click on the .reg file and click Edit. In the Notepad window that appears, you can use the Replace option to do this.


Create a custom Guest Article form for WordPress

At some point, you may want to add a Guest Article submission form to your WordPress site. To do this, you could use a plugin like TDO Mini Forms or Gravity forms. Only problem with these though is, in Gravity Forms’ case, you have to pay about $40 for a license to use it, and TDOMF, although it is a good plugin, it hogs resources (when I activated it, it took 20-30 more database queries to generate my homepage).

So I decided to create my own custom form, and after 3 or 4 Google searches and a couple of hours of work, I created something that I was happy with: a guest post form with client-side JavaScript validation, AJAX posting and, most important of all, a WYSIWYG (What You See Is What You Get) editor, namely, NicEdit.

So, let’s get down to business. First, we’ll create the actual form, then we’ll create the JavaScript functions and the server-side processing file.

First, create a new page, called “Guest Article”, or whatever. We’ll be working with custom page templates, so create a copy of your theme’s page.php template and call it page-post-slug.php, for example: page-guest-article.php. See detailed instructions on how to set up custom page templates here, and then move on to here.

Now, in your custom template, were the page content would normally go, add the form (see in-line comments for more details):

  1. <?php if ( is_user_logged_in() ) { /*If the user is logged in, display the form.*/ ?>
  2. <p>Hi, <?php global $current_user; /*this PHP block gets the current users username.*/
  3. get_currentuserinfo();
  4. echo $current_user->display_name; ?>.<br />So, you would like to write a guest article? Then just use the form below to submit your post. In 24 to 48 hours, an administrator will review your post. If he decides it meets our quality standards, it will be published on this site. If your post doesn‘t appear within 72 hours, it has probably been rejected. Don’t resubmit it, or you may be banned from the guest post creation system.</p> <!– An example welcome message. –>
  5. <div id=“postbox”>
  6. <form id=“new_post” name=“new_post” action=“”> <!– we don‘t set the action or method attributes, because they will be handled by the AJAX script –>
  7. <fieldset>
  8. <p><label for=”title”>Title:</label><br />
  9. <input type=”text” id=”title” tabindex=”1″ size=”20″ name=”title” /> <!– Post title input –>
  10. <label class=”error” for=”title” id=”title_error”>Please insert a title.</label> <!– Error message if user tries to submit the article without a title. The hiding and displaying is handled by javascript –>
  11. </p>
  12. <p><label for=”description”>Content:</label><br />
  13. <textarea id=”description” tabindex=”3″ name=”description” cols=”50″ rows=”10″></textarea><br /> <!– Post content box –>
  14. <label class=”error” for=”description” id=”description_error”>Please type a post.</label> <!– Error message if user tries to submit an empty article. The hiding and displaying is handled by javascript –>
  15. </p>
  16. <p><label for=”excerpt”>Summary:</label><br />
  17. <textarea id=”excerpt” tabindex=”5″ name=”excerpt” cols=”50″ rows=”4″></textarea></p> <!– Optional excerpt input –>
  18. <p><label for=”cat”>Category:</label><br />
  19. <?php wp_dropdown_categories( ‘show_option_none=Category&tab_index=4&taxonomy=category‘ ); ?></p> <!– optional category selection –>
  20. <p><label for=”tag”>Tags:</label><br />
  21. <input type=”text” id=”tag” tabindex=”5″ size=”20″ name=”tag” /><!– Optional tag input –>
  22. <p align=”right”><input type=”submit” value=”Submit” tabindex=”6″ id=”submit” name=”submit” class=”button” /></p> <!– submit button –>
  23. <input type=”hidden” name=”action” id=”action” value=”post” />
  24. <?php wp_nonce_field( ‘new-post‘ ); ?> <!– WordPress nonce, for security reasons –>
  25. <fieldset>
  26. </form>
  27. </div>
  28. <?php }
  29. else { /*If the user isn’t logged in, display a message offering them to either login or register.*/ ?>
  30. <p>So, you want to write a guest post?<br />Great! First though, you must <a href=“<?php site_url(‘/wp-login.php’, ‘http’); ?>”>login</a> or <a href=“<?php site_url(‘/wp-login.php?action=register’, ‘http’); ?>”>register</a> an account with us. Registering is simple, free and only takes 5 minutes.</p>
  31. <?php } ?>

Now that you’ve got the form done, you can now create the JavaScript file that validates the form and sends it of via AJAX. Create a file called “jquery.submit.js” and add the following (don’t forget to replace example.com with your domain name):

  1. jQuery(function() {
  2. jQuery(‘.error’).hide(); /*Hide the error messages*/
  3. jQuery(“.button”).click(function() {
  4. nicEditors.findEditor(‘description’).saveContent() /*For NicEdit, syncs the editor with the text area before submitting*/
  5. jQuery(‘.error’).hide();
  6. /*if title is blank, display error message */
  7. var title = jQuery(“input#title”).val();
  8. if (title == “”) {
  9. jQuery(“label#title_error”).show();
  10. jQuery(“input#title”).focus();
  11. return false;
  12. }
  13. /* If post is empty, display error message */
  14. var description = jQuery(“textarea#description”).val();
  15. if (description == “”) {
  16. jQuery(“label#description_error”).show();
  17. jQuery(“textarea#description”).focus();
  18. return false;
  19. }
  20. /* NicEdit sometimes adds line-breaks regardless of whether you type anything.*/
  21. var description2 = jQuery(“textarea#description”).val();
  22. if (description == “<br>”) {
  23. jQuery(“label#description_error”).show();
  24. jQuery(“textarea#description”).focus();
  25. return false;
  26. }
  27. var description3 = jQuery(“textarea#description”).val();
  28. if (description == “<br/>”) {
  29. jQuery(“label#description_error”).show();
  30. jQuery(“textarea#description”).focus();
  31. return false;
  32. }
  33. var description4 = jQuery(“textarea#description”).val();
  34. if (description == “<br />”) {
  35. jQuery(“label#description_error”).show();
  36. jQuery(“textarea#description”).focus();
  37. return false;
  38. }
  39. jQuery(‘#postbox’).append(‘<img src=”http://example.com/wp-admin/images/loading-publish.gif&#8221; alt=”Submitting” title=”Submitting” align=”right”>’); /* Display spinner when submitting */
  40. var dataString = jQuery(‘#new_post’).serialize()
  41. jQuery.ajax({
  42. type: “POST”,
  43. data: dataString,
  44. success: function() {
  45. jQuery(‘#post’).html(“<div id=’message’></div>”);
  46. jQuery(‘#message’).html(‘<h2>Guest Post Submitted!</h2>’) /*Displayed after post is submitted */
  47. .append(‘<p>Thank you for using this service.</p>’) /*Displayed after post is submitted */
  48. .hide()
  49. .focus()
  50. .fadeIn(1500, function() {
  51. jQuery(‘#message’).append(‘<br /><p><a href=”http://example.com”>Go back to home page.</a><br /><a href=”/guest-article/”>Make another guest post.</a></p>’);/*Displayed after post is submitted */
  52. });
  53. location.href = ‘#message’; /*Jump to here when post is submitted */
  54. }
  55. });
  56. return false;
  57. });
  58. });

Now save the file and upload it to your server. We need jQuery to make the form work, so include it by typing this just above your form:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js" type="text/javascript"></script>
Then, just bellow that, add this tag to include your JavaScript file in your page:

<script type="text/javascript" src="/path/to/javascript/file"></script>

You may want to add some CSS styling to your error messages. For example:

  1. .error {
  2. border: 2px solid red;
  3. font-weight: bold;
  4. font-style: italic;
  5. background-color: #ff6666;
  6. opacity: 0.7;
  7. color: white;
  8. }

You can add them to your themes style.css file, or include them in your page template by using the following HTML tag:

<style type="text/css">CSS rules here</style>

That’s the form done. Now it’s time to integrate NicEdit.

NicEdit is a lightweight WYSIWYG (What You See Is What You Get) editor.
First, download nicEdit from their download page, decompress the .zip file, and upload the contents to your server. Now include it and activate it by adding this just before all the other lines you added:

  1. <script type=“text/javascript” src=“http:/example.org/path/to/nicEdit.js/nicEdit.js”></script>
  2. <script type=“text/javascript”>
  3. bkLib.onDomLoaded(function() {
  4. new nicEditor({fullPanel : true}).panelInstance(‘description’);
  5. });
  6. </script>

You should now have a fully functional WYSIWYG text editor integrated into your Guest Article form.

All that’s left now is creating a PHP file to store (or publish) the article after it has been submitted. Create a new file called “guest-post.php” and add the following inside:

  1. <?php
  2. if( ‘POST’ == $_SERVER[‘REQUEST_METHOD’] && !empty( $_POST[‘action’] )) {
  3. $wp_load = realpath(“wp-load.php”);
  4. require_once ($wp_load);
  5. // Add the content of the form to $post as an array
  6. $post = array(
  7. ‘post_title’ => $title,
  8. ‘post_content’ => $description,
  9. ‘post_category’ => array($_POST[‘cat’]),
  10. ‘tags_input’ => $_POST[‘tag’],
  11. ‘post_status’ => ‘pending’, // Choose: publish, pending, draft, etc.
  12. ‘post_type’ => ‘post’, // Use a custom post type if you want to
  13. ‘post_excerpt’ => $_POST[‘excerpt’]
  14. );
  15. wp_insert_post($post); // Pass the value of $post to WordPress the insert function
  16. } // end IF
  17. // Do the wp_insert_post action to insert it
  18. do_action(‘wp_insert_post’, ‘wp_insert_post’);
  19. ?>

Upload the file to the root of your server and your done! You’ve now got a fully functional Guest Article form with a WYSIWYG editor, jQuery validation and AJAX submission.


Create a shell script to backup your site’s files, MySQL database, and server configuration files

In this article I will show you how to create a simple shell script that backs up your sites files, MySQL database tables, and server configuration files (nginx, varnish, etc.) and compresses them with Gzip, stores each backup in its own directory, and deletes the backups that are older that 14 days. Then we will set up a cron job that runs this script every 2 days.
First, open a new file in a text editor. If you use Windows or Mac, make the file directly on the server over SSH, because Windows and Mac use different line endings than every other operating system, and this doesn’t go down very well with bash.

We will call this script “backup.sh” First, set some variables that we will use later:

  1. #!/bin/sh
  2. DAY=“$( /bin/date +%Y%m%d )”
  3. STORE=“/root/backup”

The “DAY” variable on line 2 uses the date function to get the current day, so we can store the backups in date organised directories like “/root/backup/20110701/”. To see all the other ways you can format the date, type “/bin/date –help”. The “STORE” variable on line 3 is the directory where we will store our backups, and can be anything as long as your user has permission to write there and as long as IT IS EMPTY. Now let’s delete any backups older that 14 days, and create the directory where we’ll store today’s backup:

  1. find $STORE -name “*” -mtime +14 -delete
  2. mkdir -p $STORE/$DAY

Now, it’s time to make a MySQL dump of all your databases, and store it in a file called all_databases.sql:

mysqldump --add-drop-table -u username -p"password" --all-databases > $STORE/$DAY/all_databases.sql

For more information on the mysqldump command, see the MySQL official documentation.
Now we’ll add your website’s files to a .tar file. I’m assuming your document root is “/var/www”. Change below to the right path:

tar -cf $STORE/$DAY/website.tar /var/www/.

Repeat the line above with all the sites you want to add to the backup (and make sure each .tar file has a different name). If you have a wp-config.php file that is one level above your document root, you can use this command:

cp /var/wp-config.php $STORE/$DAY/wp-config.php

You can also copy server configuration files into the backup. Here are some examples for nginx and Varnish:

tar -cf $STORE/$DAY/nginx-config.tar /etc/nginx/. tar -cf $STORE/$DAY/varnish-config.tar /etc/varnish/.

Now we’ll add these files to an archive called “complete.tar“:

tar -cf $STORE/$DAY/complete.tar $STORE/$DAY/*

And compress it using gzip:

gzip -9 $STORE/$DAY/complete.tar

Finally, to save space, we’ll delete all the files we’ve just copied into complete.tar:

rm -f $STORE/$DAY/all_databases.sql $STORE/$DAY/website.tar $STORE/$DAY/wp-config.php

And so on…
Now save the file and test it by typing:


After it completes, there should be a directory called something like 20110701 in your $STORE directory, with a file called “complete.tar.gz” inside.

Backup file

You can also add to the script to make it email the backup as an attachment using a program like mutt (if the backup is small enough) or use a FTP client to upload it to a remote server. Now we’ll set up the cron job. Open your crontab file:

crontab -e

and insert the following at the bottom:

0 5 1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31 * * /path/to/backup.sh

This will run the shell script every odd day of the month at 5:00 AM. If you ever need to restore your backup, you just have to untar and unzip the files, then type “mysql < all_databases.sql” to import the database (more information here), then untar the other files and copy or move them to their proper directories.

Advanced operations with Google

You can use Google as a calculator, converter and dictionary. Here's how:


To use Google Search as a calculator, just type any of the following mathematical expressions into the search box:

Expressions Example and result
Add: + 4+2=6
Subtract: – 5-3=2
Multiply: * 4*2=8
Divide: / 6/3=2
Exponential: ^ 2^5=32
Square Root: sqrt(x) Sqrt(9)=3

These are only basic everyday expressions. You can also use parenthesis, etc…


Using the converter, you can change almost anything from one measurement unit to another. Here are some examples:

  • 1024 bytes in kilobytes
  • 34 days in weeks
  • 67 weeks in months
  • 345 calories in kilocalories
  • 45 kw in hp
  • 1997 in roman numerals
  • 24 centigrade in fahrenheit
  • 43 miles in kilometers

Just type any of the above in the search box and see for yourself.

When combined…

You can combine the use of the calculator and converter, like in these examples:

  • (1 terabytes + 3 megabytes) /2 in gigabytes
  • 5 miles + 3 kilometers in kilometers
  • 56 fahrenheit – 24 centigrade in centigrade
  • 5+3 in roman numerals
  • 10! watts in gw

By combining the two, you can do some powerful operations directly from the Google search box.


You can get the definition, pronunciation and syllable breakup of any word by just typing: define word , replacing word with whatever you want to look up.


Replace something in a web page using javascript

Using this code, you can replace all ocurrences of a element with another one:

  1. <script type=“text/javascript”>
  2. var replaceString = “me”;
  3. var myOldString = document.getElementById(“paragraph”).innerHTML;
  4. var myNewString = myOldString.replace(/test/g, replaceString);
  5. document.getElementById(“paragraph”).innerHTML = myNewString;
  6. </script>

In this case, it will replace every ocurance of test with me in the part of the page that has the ID paragraph. I wrote this code to use here at Terra-byte to remove port number 8080 (:8080) from some of the links. The reason the links have :8080 on them in the first place is because we use Varnish cache (see here), so our backend server is on port 8080, and that doesn't go down very well with the Disqus Comment System recent comments widget. The code we use is:

  1. <script type=“text/javascript”>
  2. var sanLink = “”;
  3. var myOldString = document.getElementById(“recentcomments”).innerHTML;
  4. var myNewString = myOldString.replace(/:8080/g, sanLink);
  5. document.getElementById(“recentcomments”).innerHTML = myNewString;
  6. </script>

And finally, if you want to replace a whole <div> element, use:

document.getElementById("paragraph").innerHTML = "new-html-or-text";

That's all for now.


Cool trick to edit the current page displayed

I've just stumbled across this cool trick. Go to any web page and type this in your address bar:

javascript:document.body.contentEditable='true'; document.designMode='on'; void 0

Now you can edit any page, just like you would in a normal text editor. To deactivate this, type:

javascript:document.body.contentEditable='false'; document.designMode='off'; void 0

Obviously, these changes aren't permanent, unless you use your browser's save function to save it to your hard disk. Still, quite a good trick to fool your friends.


Install PHP-FPM and configure it for nginx and WordPress

In this article we’ll install and configure PHP5 from source with FPM (FastCGI proccess manager), wich is a better alternative to standard FastCGI for 2 reasons: it’s faster, and it dynamical adjusts the amount of child processes as necessary. First let’s uninstall the old PHP (if you already have it installed, if not, skip ahead):

apt-get remove php5-common

And stop FastCGI:

/etc/init.d/php-fastcgi stop

Now let’s reinstall PHP 5.3.6 (make sure to visit php.net to see if 5.3.6 is still the latest version):

  1. sudo apt-get install autoconf2.13 libbz2-dev libevent-dev libxml2-dev libcurl4-openssl-dev libjpeg-dev libpng-dev libxpm-dev libfreetype6-dev libt1-dev libmcrypt-dev libmysqlclient-dev libxslt-dev
  2. mkdir ~/php5
  3. cd ~/php5
  4. wget http://us3.php.net/get/php-5.3.6.tar.gz/from/us.php.net/mirror/
  5. tar xzf php-5.3.6.tar.gz
  6. cd php-5.3.6
  7. ./buildconf –force
  8. ./configure —prefix=/opt/php5 –with-config-file-path=/opt/php5/etc –with-curl –with-pear –with-gd –with-jpeg-dir –with-png-dir –with-zlib –with-xpm-dir –with-freetype-dir –with-t1lib –with-mcrypt –with-mhash –with-mysql –with-mysqli –with-pdo-mysql –with-openssl –with-xmlrpc –with-xsl –with-bz2 –with-gettext –with-fpm-user=www-data –with-fpm-group=www-data –enable-fpm –enable-exif –enable-wddx –enable-zip –enable-bcmath –enable-calendar –enable-ftp –enable-mbstring –enable-soap –enable-sockets –enable-sqlite-utf8 –enable-shmop –enable-dba –enable-sysvmsg –enable-sysvsem –enable-sysvshm
  9. make
  10. sudo make install

Now it’s time to configure it:

  1. sudo mkdir /var/log/php-fpm
  2. sudo chown -R www-data:www-data /var/log/php-fpm
  3. sudo cp -f php.ini-production /opt/php5/etc/php.ini
  4. sudo chmod 644 /opt/php5/etc/php.ini
  5. sudo cp /opt/php5/etc/php-fpm.conf.default /opt/php5/etc/php-fpm.conf
  6. sudo cp -f sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
  7. sudo chmod 755 /etc/init.d/php-fpm
  8. sudo update-rc.d -f php-fpm defaults
  9. sudo touch /var/run/php-fpm.pid

Now let’s edit the initialization file and the FPM config file:

nano /etc/init.d/php-fpm

And change




Now the PHP-FPM config file:

nano /opt/php5/etc/php-fpm.conf

Now find and set and/or uncomment:

  1. pid = /var/run/php-fpm.pid
  2. user = www-data
  3. group = www-data
  4. pm = dynamic
  5. pm.max_children = 6
  6. pm.start_servers = 2
  7. pm.min_spare_servers = 2
  8. pm.max_spare_servers = 3
  9. pm.max_requests = 500

This should get you started, but read the explanations above each setting and change them to something else if necessary.

Now start PHP-FPM by typing:

/etc/init.d/php-fpm start

Now make sure the following appears in your nginx config file (and that it is uncommented):

  1. location ~ .php$ {
  2. fastcgi_pass localhost:9000;
  3. fastcgi_index index.php;
  4. include fastcgi_params; }

Now just restart nginx:

/etc/init.d/nginx restart

And that’s it!

Note: if you get:

Starting pfp-fpm ................................ failed.

when you start PHP-FPM, try typing:

sudo touch /var/run/php-fpm.pid


The amount of unnecessary data we download each month

Every time you load a web-page, unnecessary data (in the form of white-spaces, indentation and comments in the code) is downloaded with it. Each month, this data adds up to a staggering 23,000,000GB! That's the equivalent of downloading 2,555,555 DVDs, or 5,750,000,000 songs. It would take a single DSL connection 5,422,440 hours (619 years) to download that much data. See the original infographic (by GTMetrix) by clicking the image bellow.