Creating A Web Server In Linux

Install & Configure PHP

PHP is a server-side scripting language that is specifically designed for web development and can be embedded into HTML documents. It is a great language with which to start your web development learning. You can find a great tutorial on beginning PHP at http://devzone.zend.com/6/php-101-php-for-the-absolute-beginner/.

Let's get started with the installation. We are going to install PHP along with three other packages: php-pear, php5-suhosin, and php5-mysql. PEAR is a repository of PHP code that combines many common functions into a library so developers do not have to continue re-inventing the wheel. Suhosin is an open source patch for PHP that will protect against some known and unknown development flaws. The last one is pretty self-explanatory: we need it for MySQL support in PHP.

Install PHP, Pear, Suhosin, & MySQL support
ben@pyro-dev:~$ sudo apt-get install php5 php-pear php5-suhosin php5-mysql

Next, we will modify a configuration file for PHP to enable more descriptive errors and logging since this is a development server and there are likely to be plenty of them. The path to this configuration file is /etc/php5/apache2/php.ini.

Configure PHP
ben@pyro-dev:~$ sudo vim /etc/php5/apache2/php.ini

This will open the configuration file in vim. Vim can be a little confusing for beginners but it is a powerful tool that is well worth learning to use. If you'd like to learn more about using vim, head over to http://www.oregonwebradio.net/backup_fedora/tutorials/vim_li/quickstart.html for a quick-start tutorial on it. We need to modify a few lines but you can follow the same steps for each line.

First, we will modify the error_log value to record errors to a log file on the system, specifically the file /var/log/php.log.

  1. Type /error_log\ = and hit ENTER to search for the line in the file.
  2. Press i to enter Insert Mode
  3. Modify the line to say error_log = /var/log/php.log (be sure to remove the semicolon ';' at the beginning)
  4. Press ESC to exit Insert Mode
  5. Type :w and hit ENTER to write the change to the file
Please Note: We are creating this server for development, meaning only we should have access to it. If you plan to use this server for production or want to allow public access to it, do not perform the next two steps.

Next, we will modify the error_reporting value to report any and all errors that occur. We want to see all the errors since this is a development server. However, if you plan to use this as a production server, it is recommended to set it to E_ALL & ~E_DEPCRECATED.

  1. Type /error_reporting\ = and hit ENTER to search for the line in the file.
  2. Press i to enter Insert Mode
  3. Modify the line to say error_reporting = E_ALL | E_STRICT
  4. Press ESC to exit Insert Mode
  5. Type :w and hit ENTER to write the change to the file

Last, we will modify the display_errors value to show errors when they occur. This setting should NOT be turned on if anyone but yourself has access to the server.

  1. Type /display_errors\ = and hit ENTER to search for the line in the file.
  2. Press i to enter Insert Mode
  3. Modify the line to say display_errors = On
  4. Press ESC to exit Insert Mode
  5. Type :w and hit ENTER to write the change to the file

All of our edits are done so let's exit the file.

  1. Type :q to exit vim

With all our configurations complete and support for MySQL installed, let's restart the Apache server.

Restart Apache
ben@pyro-dev:~$ sudo /etc/init.d/apache2 restart


;