Basic Web Server On Ubuntu 9.04 With Zend Framework

Channel: Linux
Abstract: 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 reposi
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:

[email protected]:~# netstat -tap | grep mysql
tcp        0      0 *:mysql                 *:*                     LISTEN      8474/mysqld
[email protected]:~#

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!

Ref From: howtoforge
Channels: ubuntuphpapache

Related articles