Basic Web Server On Ubuntu 9.04 With Zend Framework

Want to support HowtoForge? Become a subscriber!
 
Submitted by the_g_bomb (Contact Author) (Forums) on Tue, 2009-06-16 11:51. :: Ubuntu | Apache | PHP

Basic Web Server On Ubuntu 9.04 With Zend Framework

This is a brief description of the steps required to set up a basic Web Server with the Zend Framework installed.

As always I will be following one of Falko's Excellent guides as there is no point in re-inventing the wheel, so to speak. I will follow The Perfect Server - Ubuntu 9.04 [ISPConfig 3]. However as I require a Web Applications Server for pre-production testing, I do not require Mail or ISPConfig so I will follow the ISPConfig-3 Guide from Step 1 - 11 and begin my own version from there.

I won't install Postfix, Courier (no need for Mail or IMAP), Saslauthd (Authentication), I'm not going to install rootkit hunter or binary utilities either, so I'll leaving them out as well:

12 Install MySQL

We can install MySQL using the following command:

apt-get install mysql-client mysql-server

You will be asked the following questions:

New password for the MySQL "root" user: <-- yourrootsqlpassword
Repeat password for the MySQL "root" user: <-- yourrootsqlpassword

We want MySQL to listen on all interfaces, not just localhost, therefore we edit /etc/mysql/my.cnf and comment out the line bind-address = 127.0.0.1:

nano /etc/mysql/my.cnf

[...]
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address = 127.0.0.1
[...]

Then we restart MySQL:

/etc/init.d/mysql restart

Now check that networking is enabled. Run

netstat -tap | grep mysql

The output should look like this:

root@server1:~# netstat -tap | grep mysql
tcp        0      0 *:mysql                 *:*                     LISTEN      8474/mysqld
root@server1:~#

13 Install Apache2, Java and phpMyAdmin

I'm not installing PHP5 at this point as I have a couple of different ways to install it in the next section. Just know that if you are going to compile from source you may want to read the next section and think about not installing apache at this point. Otherwise all be installed as follows:

sudo su
apt-get install apache2 sun-java6-bin phpmyadmin

You will see the following question:

Web server to reconfigure automatically: <-- apache2
Java EULA <-- Tab to read EULA then OK
Do you agree with the DLJ license terms? <-- Yes
Configure database for phpmyadmin with dbconfig-common? <-- Yes
Password of your database's administrative user: <-- yourrootsqlpassword
MySQL application password for phpmyadmin: <-- [blank]

14 PHP5 Installations:

We have a number of ways to get php installed, depending on what you need. I have had varying success in getting the modules installed that I require, so I'm going to give you all the ways I have tried getting PHP installed and you can choose which one you need.

apt-get install from the ubuntu repository

We can just use Apt to get the PHP version from the ubuntu repositories. This will be the simplest way and will yield the easiest success and should be used if you have no specific requirements from PHP

apt-get install php5 php5-common php5-cli

apt-get install from a debian source

Debian have updated their repository to the latest PHP5 release and I believe it has the full PHP5 GD Library included, so that may be an easier route to success than compiling from Source, but it means that you are using a source that isn't a Ubuntu recognised source and you'll have to make the decision whether you are ok with that.

That decision made you have to add the debian repositories to your sources list, which you can do by editing your sources list as before.

We can just use Apt to get the PHP version from the ubuntu repositories.

echo deb http://packages.dotdeb.org stable all >> /etc/apt/sources.list

echo deb-src http://packages.dotdeb.org stable all >> /etc/apt/sources.list

Then run

apt-get update

After this you can choose to upgrade any other installations that debian have updated as well.

apt-get upgrade
apt-get install php5 php5-common php5-cli
reboot

Compile from repository Source

While successful it installed the ubuntu release of PHP5, which is fine for most installations, this will allow you to enable some extra things that don't come in the aptitude install. You can use ./configure --help to see what is available to enable as you compile.

aptitude install libmysqlclient15-dev libxml2-dev libcurl4-openssl-dev libjpeg-dev libpng-dev sendmail libmcrypt-dev libmhash-dev

This will allow you to install the ubuntu safe release with extras that may not be included in the standard release.

cd /usr/src
apt-get install build-essential debhelper fakeroot
apt-get source php5
apt-get install build-dep php5
cd php5-5.2.6.dfsg.1/
nano debian/rules

Find and replace

[...]
--with-gd=shared,/usr --enable-gd-native-ttf \
[...]

with

[...]
--with-gd=shared, --enable-gd-native-ttf \
[...]

dpkg-buildpackage -rfakeroot
cd ..
# Install the new php5-gd package
dpkg -i php5-gd_5.2.6-1ubuntu6.3_i386.deb

Full Compile from external Source

When I ran this last, I had to recompile apache2 as well to get my new version of php5 to be recognised. Not sure why or if it was just me so I will test a couple of more times and I will edit this post to update the methods if I can get success without apache2 install as well.

aptitude install php5-dev libmysqlclient15-dev libxml2-dev libcurl4-openssl-dev libjpeg-dev libpng-dev sendmail libmcrypt-dev libmhash-dev bzip2 libcurl3 curl libpng12-dev libfreetype6-dev libmcrypt4 libmcrypt-dev libmhash2 libxslt1-dev apache2-prefork-dev libjpeg62-dev freetype2 libxft libxft-dev libcurl4-gnutls-dev

cd /usr/src
wget http://apache.mirror.anlx.net/httpd/httpd-2.0.63.tar.gz
tar -zxvf httpd-2.0.63.tar.gz
cd httpd-2.0.63
./configure --help
./configure --prefix=/etc --enable-rewrite --enable-so --enable-ssl
make
make install
/etc/bin/apachectl start
/etc/bin/apachectl stop

cd /usr/src
wget http://uk.php.net/get/php-5.2.9.tar.gz/from/this/mirror
tar xzvf php-5.2.9.tar.gz
cd php-5.2.9
./configure --help
./configure --prefix=/etc/php5/apache2 --with-apxs2=/usr/bin/apxs2 --with-config-file-path=/etc/php5/apache2 --enable-zip --enable-calendar --enable-mbstring --with-mysql --with-mysqli --with-curl --with-curlwrappers --with-zlib --with-gd --with-jpeg-dir --with-png-dir --with-mcrypt --with-mhash --with-pdo-mysql
make
make install
./configure --prefix=/etc/php5/cli --with-apxs2=/usr/bin/apxs2 --with-config-file-path=/etc/php5/cli --enable-zip --enable-calendar --enable-mbstring --with-mysql --with-mysqli --with-curl --with-curlwrappers --with-zlib --with-gd --with-jpeg-dir --with-png-dir --with-mcrypt --with-mhash --with-pdo-mysql
make
make install-cli

I got some warnings about needing LoadModule statements in apache2.conf and httpd.conf, if you find that also, then you can add commented dummy statements and make install again and it should work.

nano /etc/apache2/apache2.conf

[...]
    # Include module configuration:
    Include /etc/apache2/mods-enabled/*.load
    Include /etc/apache2/mods-enabled/*.conf

    # Dummy LoadModule directive to aid module installations
    #LoadModule dummy_module /usr/lib/apache2/modules/mod_dummy.so
[...]

15 Testing PHP and the GD Library / Getting Details About Your PHP5 Installation

As we have PHP-CLI instaled, we can test the installation of the GD Library with:

php -r "var_dump(function_exists('imagecreatefromjpeg'));" <-- will output true if GD Library is installed
php -r "var_dump(function_exists('imagerotate'));" <-- will be false if the limited library is installed

The document root of the default web site is /var/www. We will now create a small PHP file (phpinfo.php) in that directory and call it in a browser. The file will display lots of useful details about our PHP installation, such as the installed PHP version.

nano /var/www/phpinfo.php

<?php
phpinfo();
?>

Now we call that file in a browser (e.g. http://192.168.0.100/phpinfo.php):

Now you should see, PHP5 is working, scrolling down, you will see all modules that are already enabled in PHP5. You should also see MySQL listed there.

16 Configure the installations

We need to make sure that rewrite_module is enabled in apache2 for the Zend Framework to work properly, so lets check:

a2dismod

Hopefully you should see rewrite listed in the list of modules that are currently enabled. If not, press enter to disable nothing and then issue:

a2enmod rewrite

Then we need to enable AllowOverride All in the default site file

nano /etc/apache2/sites-available/default

[...]
  DocumentRoot /var/www/
        <directory>
                Options FollowSymLinks
                AllowOverride All
        </directory>
        &ltdirectory var="" www="">
                Options FollowSymLinks 
                AllowOverride All
                Order allow,deny
                allow from all
        </directory>
[...]

After this we need to secure phpMyAdmin by deleting the /etc/phpmyadmin/htpasswd.setup file...

rm -f /etc/phpmyadmin/htpasswd.setup

... and remove or comment out the following section in /etc/phpmyadmin/apache.conf:

nano /etc/phpmyadmin/apache.conf

[...]
## Authorize for setup
#<Directory /usr/share/phpmyadmin/setup>
#    <IfModule mod_authn_file.c>
#    AuthType Basic
#    AuthName "phpMyAdmin Setup"
#    AuthUserFile /etc/phpmyadmin/htpasswd.setup
#    </IfModule>
#    Require valid-user
#</Directory>
[...]

Restart Apache afterwards:

/etc/init.d/apache2 restart

17 Install Zend Framework

Although Zend Framework is available in the Ubuntu 9.04 repositories, it's the 1.7.5 version and I want to have the latest release so I will download it through SVN, but first we need to install it:

aptitude install subversion

Now we can get the latest version of the Zend Framework

cd /opt
mkdir ZendFramework
cd /ZendFramework
svn co http://framework.zend.com/svn/framework/standard/tags/release-1.8.3/

Next what we will do is create a soft link called "current" to that release folder that way if we change the Zend Framework version, we can do so without restarting Apache:

ln -s release-1.8.3 current

So that we don't have to manually add the include path into your PHP scripts using set_include_path. I want the current Zend Framework included automatically, by adding the path to the /etc/php5/apache2/php.ini.

nano /etc/php5/apache2/php.ini

Change:

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

to:

include_path = ".:/opt/ZendFramework/current/library:/usr/share/php5:/usr/share/pear"

The Restart Apache again:

/etc/init.d/apache2 restart

When a new version of the Zend Framework is released, all we need do is check out the SVN directory and change the soft link.

cd /opt/ZendFramework
svn co http://framework.zend.com/svn/framework/standard/tags/release-1.8.4/
rm current
ln -s release-1.8.4 current

18 Configure the Zend Tool

We now need to set up the paths for the command line so we'll make the same changes we just made above to the PHP CLI.

nano /etc/php5/cli/php.ini

include_path = ".:/opt/ZendFramework/current/library:/usr/share/php5:/usr/share/pear"

Before we drop out of the Super User we have one last thing to do so that you can use the tool in under your username rather than superuser, you'll need to set permissions on the /var/www folder

chown username:usergroup /var/www

Now at this point you will need to come out of the super user:

exit

nano ~/.bashrc

and add the line

[...]
PATH=/opt/ZendFramework/current/bin:"${PATH}"
[...]

Nearly there, we'll just test the install, but first we should probably restart.

sudo reboot

When you log back in don't sudo su but instead:

zf.sh show version

And you should get

Zend Framework Version: 1.8.3

19 Using the Tool

Browse to the directory where you want your new project:

cd /var/www
zf.sh create project yourProject

And you should find that the tool will create your basic site structure, including your initial controllers and views.

Last of all you will probably want to copy the Zend folder into your new project

cp -r /opt/ZendFramework/current/library/Zend /var/www/yourProject/library/Zend

And you can test the Zend installation by going to: http://192.168.0.100/yourProject/public/

Enjoy!


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by Kartika (not registered) on Wed, 2009-12-30 10:22.

Hello,

Thanks for this tutorial. It is easy to understand because drill down step by step, and easy to follow too. I get better understanding because typing it one by one.

Sincerely,

Kartika :)

Submitted by Sathish (not registered) on Fri, 2009-10-30 09:35.
5 Stats for this! Its a great tutorial. I was lost for last 3 days in search of installing ZF in ubuntu. Now I am able to install and run it. Its a great one and I thank You once more!
Submitted by alphadelta (not registered) on Thu, 2009-09-03 18:16.

Thanks so much for this great guide!

 Keep up the good work.

Submitted by Azizur Rahman (not registered) on Tue, 2009-07-28 17:09.
Something that I am not sure why we are checking out the entire ZF? I'd not advise doing this in production.
Submitted by Andrea (not registered) on Thu, 2009-06-18 14:21.

Hi at all,

  good guide. but i have a problem to compile php5 source. when i put the command:

./configure --prefix=/etc/php5/apache2 --enable-zip --enable-calendar --enable-mbstring --with-mysql --with-mysqli --with-curl --with-curlwrappers --with-zlib --with-gd --with-jpeg-dir --with-png-dir --with-mcrypt --with-mhash --with-pdo-mysql --with-config-file-path=/etc/php5/apache2

 i receive the follow error:

 Configuring extensions
checking whether to enable LIBXML support... yes
checking libxml2 install dir... no
checking for xml2-config path...

 

any help ?

Submitted by Andre (not registered) on Fri, 2009-06-19 09:12.

Remove php&co end reinstalling...it works ;)


 

Submitted by the_g_bomb (registered user) on Fri, 2009-06-19 20:10.

You got there on your own. I have re-vamped the tutorial a bit, as I wanted the Full GD Library and have moved the installation of the ***-dev files closer to the configure which should hopefully help others.

Submitted by Anonymous (not registered) on Wed, 2009-06-17 12:53.
I think faster way to do this would be to simply install Zend Server Community Editon:)
Submitted by the_g_bomb (registered user) on Fri, 2009-06-19 20:10.

Where is the fun in Simple Solutions?

Submitted by srini (not registered) on Mon, 2009-07-13 16:51.

Hi,

When issued command zf.sh show version, i got the below message:

/opt/ZendFramework/current/bin/zf.sh: 44: php: not found

But when i have manually browsed to the folder zf.sh file is present. Pls help....

Regards,

Srini

Submitted by the_g_bomb (registered user) on Sat, 2009-07-25 23:30.

Check your soft link called current is actually pointing at the zf directory, in the tutorial I have included what to do if and when zf if updated, you shouldn't follow that instruction until the framework is actually updated. You could rm your 'current' ln -s and redo the command:

ln -s release-1.8.3 current

making sure that you are in the ZendFramework directory and that the release version is correct.

You could also check permissions on the file, it might be that you current user doesn't have permission to execute the zf.sh file, a quick chmod could fix that.

Submitted by rob ganly (not registered) on Sun, 2009-09-13 19:47.

no it is that php isn't being found on the command line.

try running 'php -v' and if you get 'php: command not found' then try and install the cli by running the command:

sudo aptitude install php5-cli

then restart apache and try again. hope that helps.

rob ganly

Submitted by Gast78 (not registered) on Fri, 2009-11-20 04:27.
Thanks Rob, it helped me.
Submitted by Anonymous (not registered) on Thu, 2010-10-28 13:00.

hi when i checked the version

zf.sh show version

this give me the error

The program 'zf.sh' is currently not installed.  You can install it by typing:
sudo apt-get install zend-framework-bin

please help