Quick Tip: How to Install and Configure PHP in Fedora Linux

Previously, I have discussed about how to install MySQL on Fedora Linux. In this post, I would like to elaborate PHP installation on Fedora. Even though the installation is simple by nature, I would like to provide some notes to help you troubleshoot some post-installation problems that may occur.

As usual, I will provide the screenshots of the installation along with the commands invoked on the terminal. For the environment, some important settings are written below:
OS : Fedora 13 64-bit
Web server : Apache HTTP Server
PHP version : PHP 5.3.2
Constraints : yum is installed, commands invoked in root shell, Apache is already installed and running

Note: Apache is installed by default in Fedora. You only need to configure and verify that the server is running. How to configure Apache is explained in the online documentation. If you want the server to be public, i.e. accessible from other computers in the network, you should not firewall the HTTP port, which is usually port 80. Also, if you enable selinux, you also need to properly set the flag of some security parameters related to http. I will explain about selinux and http in another post.

Now, let’s move to the installation. Basic installation steps are as follows:
1. Install PHP via yum
root# yum install php



2. Configure php.ini
root# vi /etc/php.ini

Minimal configuration:

-FIND:
;session.save_path = “/var/lib/php/session”
-CHANGE INTO
session.save_path = “/var/lib/php/session” (or other directory you want to store the session)

3. Configure httpd.conf
root# vi /etc/httpd/conf/httpd.conf

We need to hook PHP shared object into Apache so that the web server will recognize PHP code and parse it properly.
Minimal configuration:

- FIND:
DirectoryIndex index.html index.html.var
- APPEND index.php TO END OF LINE
DirectoryIndex index.html index.html.var index.php
- FIND:
AddType application/x-gzip .gz .tgz
- AFTER the line ADD:
AddType application/x-httpd-php .php

4. Restart Apache
root# service httpd restart

5. Test if PHP is properly working

a. Test from command line

root#php -r "phpinfo();"

If the installation was successful, you should be able to see the details of your PHP installation from the command line interface.

b. Test from the browser

Create a file named info.php and put it on the document root folder of your server.

info.php

Post-installation steps

In Windows, there is an ext directory containing dlls of PHP extensions that are bundled in the software package. However, this does not apply to Fedora Linux. Several PHP extensions are built as shared modules hence we should install them separately.

1. Installing some extensions that are extensively used in web development

Below, you can see the list of the extra extensions we will install after the basic PHP installation.

  • php-mysql : php extension for mysql (this will install php-pdo, an extension for native database abstraction in PHP called PDO, as dependency)
  • php-xml : php extension for XML-related functionalities
  • php-mcrypt : php extension for mcrpyt encryption library
  • php-mbstring: php extension for multibyte functionalities (used when working with various charsets)
  • php-gd : php extension for dynamic creation of images in PHP using GD library

root# yum install php-mysql php-pdo php-xml php-mcrypt php-mbstring php-gd

Note: if you want to find other PHP extensions installable via yum, you can simply invoke the yum list command.
root#yum list php* | more

2. Configuring the extensions

When an additional extension is installed, an extension-specific configuration file is also created in /etc/php.d/ directory. You can invoke the command phpinfo() from the command line to check what configuration files have been created using this command:
root # php -r "phpinfo();" | grep "/etc/php.d/" --color=always

Configure all the extensions properly so that you can get the extra benefit from their features

3. Restart Apache

Restart Apache so that the changes can take effect.
root# service httpd restart

That’s all. Have fun!!

Related posts:

3 Responses to “Quick Tip: How to Install and Configure PHP in Fedora Linux”


Leave a Reply