Install Zend Framework 2 In CentOS


Zend Framework 2 is a one of the popular (I think) PHP frameworks in the community. Because of sheer weight of the framework (weighs a whooping 8 to 10 MB), I thought of installing the said library for all projects in the machine. So, I would like to share the steps on how to install the Zend Framework 2.


This tutorial intends for the people who, at least, have knowledge on Linux server administration, Apache HTTP Server, PHP, and Zend Framework 2.

Step 1: Preparation

Login to your CentOS machine. Make sure that you have root access. It is up to you on how you gain a root access by logging in directly as root user or do an su - command.

Step 2: Installing the Framework

Once you are now a root user, go to /usr/share folder.

cd /usr/share

Then create a folder named zf2.

mkdir zf2

After creating the zf2 folder, get inside the directory.

cd zf2

Then download the latest stable version of Zend Framework 2.


Where release-2.2.5 is the latest version of the framework. For the purpose of having an example, I will use the version 2.2.5 of the said framework, which is, as of creating this article, the latest version.

After the download, unzip the file.

unzip release-2.2.5

Once the extraction of the file is complete, the folder will be created as zf2-release-2.2.5.

[root@hostname zf2]# ls -la
total 3024
drwxr-xr-x   3 root root    4096 Dec 24 16:31 .
drwxr-xr-x. 77 root root    4096 Dec 24 15:04 ..
-rw-r--r--   1 root root 3082130 Dec 24 16:31 release-2.2.5
drwxr-xr-x   5 root root    4096 Oct 31 23:48 zf2-release-2.2.5
[root@hostname zf2]#

Step 3: Setting an Environment Variable in Apache

Open the PHP configuration section of the Apache configuration file.

nano /etc/httpd/conf.d/php.conf

Then at the end of the line, add the following line of code.

SetEnv ZF2_PATH /usr/share/zf2/zf2-release-2.2.5/library

Then save and exit the text editor. Finally, restart the Apache HTTP server.

service httpd restart

Step 4: Testing

To test if the environment variable is present, use the phpinfo function.

<?php phpinfo() ?>

and save the file as phpinfo.php in your document root (in this case /var/www/html). When you browse phpinfo.php, the ZF2_PATH should be present.

Step 5: Setting the Environment Variable in System (Optional)

You may skip this step if you like. Now, set the environment variable.

export ZF2_PATH=/usr/share/zf2/zf2-release-2.2.5/library

In order to have the ZF2_PATH environment set every start-up of the machine, we have to create a shell script. To start, create a bash profile.

nano /etc/profile.d/

For example purposes, I use nano as text editor. You may use any text editor you like. Then, enter the following code in the text editor.

export ZF2_PATH=/usr/share/zf2/zf2-release-2.2.5/library

Then save and exit the editor. To verify that the environment variable has been added, key in the command:


You will see the list of environment variables in the system. If you can see the ZF2_PATH environment variable with the path, it means it works.


Well, hopefully, this tutorial will be useful for those who are new into the Zend Framework.