LAMP and Zend Framework on Ubuntu 10.04 (Lucid)

I got my main development tools setup on Ubuntu this weekend. My workstation has 64 bit Ubuntu installed and I did not want to have to install the 32 bit libraries (used by XAMPP). So I opted for installing all the components from the ubuntu repositories.

Ubuntu makes it super easy to install ALL the required components using 1 single command! You no longer have to go into Synaptic and check all the required software!

Open up a terminal and type

sudo tasksel

Select LAMP from the options presented and follow the prompts. Seriously.. It could not get any easier!

Ok.. so now, you have Apache2, PHP and Mysql server setup. The default web directory is /var/www.

You should now be able to navigate to http://localhost on your browser and see the “It Works!” default page. Now, if you try to add any of your own scripts/pages to this folder, you will get a “insufficient privileges” error. This is because the var/www by default belongs to user ‘root’ and group ‘root’.

I have noticed so many websites/blogs suggesting granting super cow rights to ALL to this directory to get around this.. I strongly recommend against doing that. Instead, I suggest creating a group named ‘web’ with rwx permissions to /var/www. Then, if you want other users to be able to author pages, add them as members of the ‘web’ group.

  1. Click on ‘System’->’Users’->’Manage Groups’->’Add’

Go ahead and enter the new group name ‘web’ and make yourself a member like so:

2. Next, setup ‘web’ as the group for /var/www

sudo chgrp -R web /var/www
sudo chmod -R g+rwx /var/www

The first command changes the group ownership from ‘root’ to ‘web’
The second command adds read, write and execute permissions to the group (web)
(the -R signifies recursive flag.. so files and subfolders inside /var/www will inherit these settings as well)

At this point, this is what “ls -l /var” should look like:

3. log out and log back on (Group membership is only processed on login) . You should now be able to save to the /var/www folder. Also, if you need any other shared user to have web permissions, simply add them to this group ‘web’.

Go ahead and create a “phpinfo” page in /var/www:

Point your browser to http://localhost/phpinfo.php and confirm that php is successfully installed.

The next task is to install the Zend Framework. Download the most recent version from the Zend Framework website and extract it to the /opt folder. To enable us to easily switch out different versions, we will create a symbolic link to this folder (just right click and select the ‘Make link’ option.. name it ‘Zend’)

Next, we will tell php to include the zend framework in the include_path.

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

Add/Change the include_path in to :

include_path = “.:/opt/Zend/library”

Note that I used the symbolic link in the include path.. This way, when there is a new version of ZF, we can just switch out the symlink without having to edit the ini file!

In order to use the zend framework command line tool (/opt/Zend/bin/zf.sh), we need to install the php command line interface (php5-cli).

sudo apt-get install php5-cli

Note that the CLI uses a different version of the php.ini file (NOT the one in the apache2 folder but in the cli folder!). We need to tell CLI also where the zend framework directory is located.

sudo gedit /etc/php5/cli/php.ini
and set:
include_path = “.:/opt/Zend/library”

The final step is to include the path to /opt/Zend/bin in the unix PATH variable (this way, you can use zf.sh instead of /opt/Zend/bin/zf.sh). Edit file named ~/.bashrc (an easy way to get to this is to click on ‘view’->’show hidden files’ in nautilus in your home directory). Add the following line at the end:

PATH=/opt/Zend/bin:”${PATH}”

The Zend Framework relies on the apache “rewrite” module. So, go ahead and enable the “rewrite” module using the following command:

sudo a2enmod rewrite

Restart apache.. and you should be all set 🙂

Netbeans 6.9 beta includes a plugin to create Zend Framework projects (using the zf.sh tool).. I have it installed, and it works great!

Advertisements

15 thoughts on “LAMP and Zend Framework on Ubuntu 10.04 (Lucid)

  1. Quite newbie here, and I expect no post edition still, what about the virtual hosts configuration? Shouldn’t we have them into consideration?

    Thanks a lot,
    mem

  2. Hi,
    I am a bit confused by your query..Zend Framework is a collection of php libraries that are web-server accessible (not a service). Since you have a working setup, I presume you would like to upgrade ZF?? It is as simple as downloading the latest version and referencing the directory from your php.ini (Include_Path).

  3. Thanks for the effort, nice article, but
    creating a group to edit the /var/www directory is so unnecessary, it will be better to put your site file under your personal directory and use the virtual host to access the site.
    also, the zend framework has been added to the ubuntu repositories since Ubuntu Hardy (8.04)
    sudo apt-get install zend-framework

    Any way thanks for the post 🙂 keep it up.

  4. It works like a charm , i was looking for a Ubuntu+LAMP+Netbeans+Zend Framework for weeks now
    Thanks a lot 🙂

  5. Not work on Natty! When try to use zf command, an error says The program ‘zf’ is currently not installed. You can install it by typing: apt-get install zend-framework-bin

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s