Wednesday, January 12, 2011

Installing Zend_Tool or the zf command in the console

The prerequisite of this tutorial is that you will have to install the Zend Framework. If you have not done so please install it. This link "Installing PHP5, MySQL and Zend Framework 1.11.2 in Ubuntu" should help you do it.

After you have installed Zend Framework you can use Zend_Tool from your console to create project and other components of Zend.

In order to do this you will have to make an alias of the zend framework bin folder in the .bash_aliases file.

sudo gedit /home/aabhushan/.bash_aliases

Then, add the following and save it

alias zf='/usr/share/php5/zend/bin/zf.sh'

You will also have to make sure the following code in .bashrc is uncommented so that the alias file is being read.

if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi

You can use the following command to open the .bashrc file.

sudo gedit /home/aabhushan/.bashrc

If the above process worked out fine then your Zend_Tool should be working. You can test it by opening a new window of the console and running the zf command. The following command will give you the version of the Zend Framework that you are using

zf show version

Installing PHP5, MySQL and Zend Framework 1.11.2 in Ubuntu

First of all, install PHP5 using the repository by typing the following command in the terminal.

sudo apt-get install php5

Go to an internet browser and type http://localhost. You should get an "It works" message if the installation is complete.

Otherwise you can edit the index.html file located at /var/www folder and rename the filename to index.php and replace the code with the following code.

<?php phpinfo(); ?>

Install MySQL using the following command

sudo apt-get install mysql-server

Also, install PHP module for MySQL by using the following command.

sudo apt-get install php5-mysql

You might want to install Phpmyadmin to help you access and run SQL commands on your databases. Run the following command if you want to install it. Otherwise, you can use MySQL from the terminal itself.

sudo apt-get install phpmyadmin

Now, download the Zend Framework Zip or Tar file from http://framework.zend.com/download/latest and extract the archive. In my case in the following way.

sudo unzip /home/aabhushan/Downloads/ZendFramework-1.11.2.zip

Now, move the extracted Zend Framework folder to the PHP folder.

sudo mv /home/aabhushan/ZendFramework-1.11.2/ /usr/share/php5/

Now,create a soft link for the Zend Framework folder so that you will not have to restart apache when you replace the old version of Zend with the new one.

cd /usr/share/php5/

sudo ln -s ZendFramework-1.11.2/ zend

Now, if you want to include the path to Zend by yourself in your application then you can do it by adding set_include_path in the following way,

set_include_path(get_include_path().PATH_SEPARATOR.'/usr/share/php5/zend');

Otherwise, if you want to add it by default then you can set it in the php settings by editing /etc/php5/apache2/php.ini. In my case in the following way,

sudo gedit /etc/php5/apache2/php.ini

Now, edit the line,

; include_path = ".;/usr/share/php5:/usr/share/pear"

to,

include_path = ".;/usr/share/php5:/usr/share/pear:/usr/share/php5/zend/library"

Now, you need to restart apache and Zend Framework is successfully installed to your computer.

sudo /etc/init.d/apache2 restart

In order to enable apache2 mode rewrite or mod_rewrite, to be able to call the controller action by using "/public/controller/action" instead of using "/public/index.php/controller/action" execute the following command in the terminal.

sudo a2enmod rewrite

Good luck!