fredag 6. mai 2011

Installing phpMyAdmin, Zend Framework Extras and setting up virtual hosts

Edit: Forgot to add ServerName and ServerAlias to the host-file. This has now been corrected.

 Who is this guide for


This tutorial is meant for those of you that followed my previous tutorial, Setting up Zend Server CE in Ubuntu 11.04. The two first parts of the tutorial specifically handles how to install phpMyAdmin and Zend Framework Extras for use with Zend Server CE, and requires Zend Server CE to be installed as a prerequisite. While it is possible to use phpMyAdmin and Zend Framework Extras without Zend Server, the installation process would probably be somewhat different. The last part of this tutorial explains how to set up a virtual host for the Apache2 server that comes with Ubuntu, and does not require Zend Server to be installed.

Installing phpMyAdmin


Now, installing phpMyAdmin for use with Zend Server CE is fairly easy. While it does require some terminal action, the installation should be straight forward. The first thing to do, is tell APT to install the phpMyAdmin-package from the Zend-repository added in the previous guide. Write the following line into the terminal, and write root password as needed:

sudo apt-get install phpmyadmin-zend-server

This should start the installation process. As usual, APT will prompt you for a confirmation on the installation. As before, type "Y" and press enter to continue.


After the installation process is complete, some configuration must be done. Among them, is to choose which web server to use (Lighttpd vs. Apache) and setting a password for the root user. We are going to use Lighttpd for phpMyAdmin as this is the web server the web based Zend Server-administration pages uses, and because it is safer to keep administration utilities away from your development server.

The first thing the configuration process will ask for is a password for the MySQL administrative "root" user. Now, while it's not strictly required to set a password for this user, it is highly recommended. Though, as long as lighttpd and MySQL is not configured to allow connections from outside your own computer, you should generally be safe.Re-enter your password, and the root password is set.


At this point, you have to choose which web server to configure phpMyAdmin for. As I mentioned before, we are going to use lighttpd for phpMyAdmin, so just push the down-arrow on you keyboard, and punch that enter key like a boss. All humor aside, when you've chosen lighttpd, some automatic configuration will occur. Though, after a short while, the package configuration script will ask you how you want to configure phpMyAdmin. We will use dbconfig-common package to configure phpMyAdmin, as this means that we don't have to set up phpMyAdmin manually. The installer will prompt you for the root user password, as well as ask you to provide a password phpMyAdmin can register with the MySQL database. Simply type in the password you chose (if you chose one), and then make a password for the phpMyAdmin user.


When you've provided the passwords, the phpMyAdmin installer will finish the installation process, and you should be done! To see if your new phpMyAdmin installation works, go to the Zend Server administration page in your preferred web browser:

http://localhost:10081
and there should be an Open phpMyAdmin-link right on the frontpage:


Installing Zend Framework Extras


Installing components for Zend Server is quite easy, given that the Zend Server repository is added to your package managers source list. Quite a few components are available for Zend Server CE, among them the Java Bridge, Zend Framework Extras, Dojo extension for Zend Framework and some other useful packages. To read more about them, please visit Zend Server CE home page. In this tutorial I will only install Zend Framework Extras, as this is really the only component I need. It also serves the demonstrative purposes needed for the guide. If you need to install any of the other components, the process should not be too different, and Google will ultimately be able to help. Just remember to use the right package manager and tools for the job.

To install the extras for Zend Framework, we are going to use the APT package manager to get the Zend Framework Extras package and install it. To do that, we are going to need the package name. A quick visit to the deb-installation guide for Zend Server CE will reveal all the package names of the components. The package name for the Zend Framework Extras is "zend-server-framework-extras", so we are going to use that. Enter the following line into the terminal to tell APT to install the package:

sudo apt-get install zend-server-framework-extras

It should look something like the following:


To check that Zend Framework Extras was correctly installed, go to the following location:

/usr/local/zend/share/ZendFramework/library

The Zend Framework library folder should contain a ZendX folder. That's it. Installing the other components should not be much harder than that.

Setting up virtual hosts in Apache 2


Successfully setting up virtual hosts can be a bit tricky. What configurations you use for your virtual hosts is mostly determined by the needs you have. If you don't really need to configure it that much, and want it to act the same way as the localhost on port 80, it should be a pretty straightforward job. But the second you need something more, it starts getting a bit more difficult. Personally, I need a virtual host with mod rewrite enabled. What the mod_rewrite module of Apache does, is let you modify URLs requested by users. So if a user try to access a URL the website owner does not want the user to access, the rewrite module can be used to redirect the user to another URL, thus preventing the user from accessing restricted content on the server. This feature of Apache can be particularly useful if you want to keep your web application logic private on a public folder on a typical web server, and prevent others from accessing those valuable files. I also find it useful to enable this function on my local server, because I want to be able to synchronize the files between my computer and the web server.

The next few steps will follow Matthew Wittering guide pretty closely, so credit for these steps go to him. Since we've already got Apache2 installed and configured, we're going to skip the first step. The first thing we're going to do is to make sure mod_rewrite is enabled. While it should be, it does not hurt to make sure:

sudo a2enmod rewrite

This should yield the following result:

Module rewrite already enabled

Now head into the apache2 available sites folder:

cd /etc/apache2/sites-available

and use the copy command to copy the default virtual host-file to a new file. While the file name is not critical for the functioning of the virtual host, you should pick the same name you want the domain for the virtual host to be. In my example, I will use zfcms.local as my file name, because this is the domain name I'll choose.

sudo cp default yourpreferredname.dev




Now that you have created your new virtual host file, based on the existing default host file, it is time to make some changes. Open your hosts file with nano:

sudo nano yourpreferredname.dev

The new virtual hosts file should look something like this:

<VirtualHost *:80>
        ServerAdmin webmaster@yourpreferredname.dev
        ServerName yourpreferredname.dev
        ServerAlias www.yourpreferredname.dev

        DocumentRoot /path/to/site/root
        <Directory /path/to/site/root>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>

        ErrorLog /home/snorre/Dropbox/Sites/zf_cms/error.log

</VirtualHost>

The directory path should be the path to your sites root folder. If you want to open your sites public folder as default, you can either specify this folder as the document root, or make an addition in the .htaccess file we are going to make. If you want Apache to log errors for this virtual host to the standard error.log file, you can remove the ErrorLog line. If you want to work with several virtual hosts, separate error logs are a must. Though, it is always possible to add it at a later point.

As you might have noticed, the file was created in the folder available-sites. This directory contains all virtual hosts available to apache, but they are not necessarily enabled, or activated if you will. To enable a virtual host (or site), the file has to be available in the folder enabled-sites. To add the virtual host to apache, we will create a symlink (system link) and enable it in apache using the apache command a2ensite:

sudo a2ensite yourpreferredname.dev

When this command is run, the script will prompt you to reload apache2 to enable the new configuration. In this case, we will be good pandas and take the advice. Restart Apache 2 with the command specified:

sudo /etc/init.d/apache2 reload


While Apache2 is now fully aware of the new virtual host, Ubuntu is still blissfully ignorant. To change this, we will have to add the domain name to Ubuntu's hosts file. This is as straightforward as it gets. Open the /etc/hosts file with the following command:

sudo nano /etc/hosts

And enter the following line below the last ip domain-pair:

127.0.0.1       yourprefferedname.dev


Reload apache2 once more, using the same command as before:

sudo /etc/init.d/apache2 reload

If you did everything right, Apache 2 should reload without any troubles. To make sure that your page is up and running, add a simple index.html file in your sites document root, and open your new site in your preferred web browser. You might have to change the privileges for the root folder of your virtual site. To do this, use the following command:

sudo chmod -R 755 /path/to/site/root

tirsdag 3. mai 2011

Setting up Zend Server CE in Ubuntu 11.04

Who is this guide for


Installing and configuring a lamp-stack (Linux, Apache, MySQL and php) can be a somewhat daunting task if done manually. There are many files to configure, and making sure everything works correctly together can take some work and experience. For those with little or no experience in setting up such a stack, especially when it comes to the Linux environment, there are alternatives. For use in development environments you've got software that pretty much sets up a LAMP-stack for you, such as LAMPP (Linux, Apache, MySQL, php, Pearl) and Zend Server (CE).

This guide intends to show you how to set up the latter, and is as much a guide for you, the reader, as it is a note for me, the author, who has the keen ability to forget about these kinds of things. I also wanted to make this guide because the installation manual provided by Zend is not updated for Ubuntu 11.04, let alone 10.10, and because it is not that beginner friendly. I've borrowed most of the steps in this guide from other guides, and citations are provided where such is the case. So let's start.

Installing Zend Server CE


If you clicked the nice little URL pointing to the Zend Server CE-page, you might have noticed that the download page offers you a DEB/RPM installer script. This script however, is made to work with aptitude (I suspect) which is the standard package handler for the deb-variant of Linux, and won't work with Ubuntu 11.04 as this version of Ubuntu use APT. We'll avoid the installer script, and instead install the application manually.


One important thing to note is that Ubuntu 11.04 (and other versions of Ubuntu) comes with both Apache, php and MySQL. In addition to these pre-existing pieces of software, Zend Server CE will install the lighttpd web server and it's own php version. You might wonder why you would need two webservers, both apache and lighttpd. The reason is quite simply that Zend wanted to run the admin panel for Zend Server on it's own server, so that the configurations needed for the admin panel would not interfere with the configurations wanted by the users, (Source: Jess Portnoy).

The first thing we need to do is add the Zend Server CE-repository to the sources list.
Open the terminal and enter the following line:
sudo nano /etc/apt/sources.list

This should open the sources.list file in the terminal text editor nano and look something like this:

Some guides tell you to use the gedit text editor via the command "sudo gedit /etc/apt....". However, this will produce errors because graphical (gnome) applications should be accessed with gnomesu via the terminal. For our purposes, nano should do the trick, so I will stick to that editor. (Source: opensuseforums).

Scroll down to the bottom of the document and insert the following line:
deb http://repos.zend.com/zend-server/deb server non-free
What this line does, is to tell APT (the package manager in Ubuntu) where Zend Server can be found. To save the change to the source.list file, press ctrl + O (the character, not the number). This keyboard shortcut promts nano to start the process of writing the data out to the file. To complete the save, press the return/enter key. If nano successfully wrote the file, you can exit the editor by pressing ctrl + x.

The next thing to do is to add the public key for the Zend Server repository to the package manager. Enter the following line into the terminal, and provide the root password as necessary:
wget http://repos.zend.com/zend.key -O- |sudo apt-key add -

If everything went ok, the terminal should display an "OK" line at the end of the text output. It should look something like this:



At this point the repository location (URI) of Zend Server CE should be added to the sources.list file of the APT package manager. APT should also have the public key to the repository. The last thing we have to do before we can start the installation process is to tell APT to update it's list of available repositories. Write the following line into the terminal and execute:

sudo apt-get update

If you've done everything right thus far, APT should be able to read the sources.list file without problems, and output something like this to the terminal:


Now that APT has updates it's repositories list, we can let APT handle the process of installing Zend Server CE. For someone like me, who barely grasps the fairly intricate architecture (if you will) of the Linux file system, having APT putting everything where it belongs is great stuff. To install Zend Server CE, simply write the following line into the terminal and enter root password as needed:

sudo apt-get install zend-server-ce-php-5.3

During installation, the terminal will prompt you for a yes/no-answer:

Just enter a big Y and press the return/enter-key. APT will then start downloading the necessary packages from the repositories, and do the installation. If the installation succeeded your terminal should look something like this:


As you might have noticed, Apache2 will give the following output error:

apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName

To fix this problem, we'll have to add the "ServerName" property into the httpd.conf file, which tells Apache2 what name the server goes by. Open the text document with nano (like we did with the sources.list file):
sudo nano /etc/apache2/httpd.conf
and enter the following line and save (ctrl + O, enter/return and then ctrl + x):
ServerName localhost




If you restart the Apache2 server, the error message should be history. You should restart Zend Server as well and check it's status, to make sure everything is ok. Before that can be done, you should know that Apache requires a text-based browser to display it's status in the terminal, (Source: Serverfault). As it seems Ubuntu 11.04 does not provide such a browser, you'll have to install one. There are several text-based browser available, but lynx is probably as good as anything else for our use. Install lynx by writing the following line in the terminal (enter Y + enter/return key on prompt the same way as before:

sudo apt-get install lynx

To restart the server, enter the following lines into the terminal:

sudo /etc/init.d/apache2 restart
sudo /usr/local/zend/bin/zendctl.sh restart

This should yield the two respective results:


To check Zend Server CE's status, write the following line into the terminal:

/usr/local/zend/bin/zendctl.sh status

This should display the status of the Apache2 and lighttpd server.




When you've come this far, Zend Server has installed it's components. That is, lighttpd (webserver), configured the Apache2-webserver and the MySQL-server that comes prepackaged (so to speak) with Ubuntu. To make sure the webserver is working, open localhost in your browser of choice by typing in the following URI:

http://localhost/

If it worked it should display the following text:
It works!

This is the default web page for this server.

The web server software is running but no content has been added, yet.

If you are positively sure that you are not going to use Perl, pecl (PHP extensions community library), Zend Framework or any other such tools, you may skip the next step in this guide. Though, it would probably not hurt to do it, especially if you change your mind later on. Now, before you can lean back and relax, there are some final post-installation steps to be done. The first thing we need to do is to add the Zend Server CE binary folder to the $PATH environment variable for all users on your Linux-machine. When the binary folder is added to the $PATH environment variable, it tells the OS to look for executable files in the Zend binary folder. To do this open the profile file in the etc-folder with nano like so:

sudo nano /etc/profile

Add the following two lines to the end of the file and save the file in the usual manner (ctrl + O, enter/return-key and ctrl +x):

PATH=$PATH:/usr/local/zend/bin
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/zend/lib

It should look like this:


As this guide is not going to use the terminal to execute any of the binaries in the Zend application folder, the following step is not necessary. But if you want to start using the binaries, it is required. To make the shell (terminal) reload the configuration file, the easiest solution is to just close and reopen the terminal. You could also use the following line:

source /etc/profile


The last thing to do now, is go to the following link:

http://localhost:10081

This will take you to the registration and set-up process for the Zend Server. Just follow the simple instructions, and you're done!


In a later blog post, I will go trough the process of installing phpMyAdmin, a web-based mySQL-client that let's you manage your mySQL-database. In addition the post will handle the process of setting up a virtual host, and how to install Zend Server components. I hope this little tutorial has been helpful for those that wanted to set up Zend Server. I realize that most of these steps can be found on the Internet. But none of the guides I've stumbled upon (or rather searched for in a brave effort on Google) have been adapted for the newest versions of Ubuntu (10.10 and 11.04), and that warranted a new tutorial. I've also taken care to not assume to much knowledge on the part of the user, because there might be people who are completely new to Linux and Ubuntu. Things like using the right package manager, avoiding cryptic errors when using GUI-enabled applications without proper security privileges, and so on, can be quite confounding for a new or inexperienced user, such as myself. Feel free to point out any errors in this post. I'm not an expert Linux-user, and as a result I am prone to making errors.

So long, and happy computing.