02 June 2010

Install Lighttpd, MySQL and PHP5 for my local development environment

  1. From the desktop, launch a new terminal session by selecting: Applications > Accessories > Terminal. A new terminal window will display.
  2. At the prompt (the blinking cursor), type: sudo apt-get update then press Enter.
  3. When prompted, type the sudo password then press: Enter. This is done to resynchronize the package index files with their sources, ensuring that your system is aware of new and updated packages. If updates are found, simply type: sudo apt-get upgrade then press: Enter. Otherwise, proceed to the next step.
  4. Once update/upgrade is complete, type: sudo apt-get install mysql-client mysql-server then press: Enter and follow the prompts to complete the installation.
  5. Next you will install the Lighttpd server and Lighttpd Doc (the documentation files). At the prompt, type: sudo apt-get install lighttpd lighttpd-doc then press: Enter.
  6. Once this installation is complete, open your web browser and navigate to either http://127.0.0.1/ or http://localhost/. If all went as planned, you should see: Placeholder page The owner of this web site has not put up any web pages...
  7. Next we will install PHP5. At the prompt, type (or copy/paste): sudo apt-get install php5 php5-cgi php5-common php5-imagick php5-intl php5-mcrypt php5-pspell php5-recode php5-memcache php5-memcached php5-librdf php5-ps php5-ming php5-mysql php5-imap php5-ldap php5-snmp php5-sqlite php5-svn php5-tidy php5-xmlrpc php5-xsl php5-curl php5-gd then press: Enter.
  8. We then need to modify the php.ini file to enable cgi.fix_pathinfo. At the prompt, type: gksudo gedit /etc/php5/cgi/php.iniA gedit window will open and display the php.ini file. Search (Ctrl+F) for the line: ;cgi.fix_pathinfo=1 and uncomment this line by simply deleting the leading ; (semi-colon).
  9. Save your changes then close gedit.
  10. At the prompt, type:gksudo gedit /etc/lighttpd/lighttpd.conf then press Enter.
  11. In the server.modules section, add "mod_fastcgi",
  12. Scroll to the bottom and paste the following fastcgi.server = ( ".php" => ((
    "bin-path" => "/usr/bin/php-cgi",
    "socket" => "/tmp/php.socket",
    "max-procs" => 2,
    "bin-environment" => (
    "PHP_FCGI_CHILDREN" => "16",
    "PHP_FCGI_MAX_REQUESTS" => "10000"
    ),
    "bin-copy-environment" => (
    "PATH", "SHELL", "USER"
    ),
    "broken-scriptfilename" => "enable"
    )))
  13. Save your changes then close gedit.
  14. Next we will create a PHP info file that will enable us to view details about our PHP installation. At the terminal prompt, type (or copy/paste): sudo sh -c "touch /var/www/php-info.php ; echo '<?php phpinfo(); ?>' > /var/www/php-info.php" then press: Enter.
  15. Open your web browser and navigate to either http://127.0.0.1/php-info.php or http://localhost/php-info.php. You should see something similar to: PHP Version 5.3.2-1ubuntu4.2.... You should also see: CGI/FastCGI in the: Server API row.

The installation is now complete. Here is a short list of additional tools that you may wish to add. Either click the apturl protocol link or use the terminal commands to install.

Here are a few useful commands for working with your Lighttpd server.
  • Stop Lighttpd:sudo /etc/init.d/lighttpd stop
  • Start Lighttpd:sudo /etc/init.d/lighttpd start
  • Restart Lighttpd:sudo /etc/init.d/lighttpd restart

No comments: