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

4 kommentarer:

  1. Another great article. Thanks!

    SvarSlett
  2. Above all information is excellent and i learned few new points from this post,domain registration india

    SvarSlett
  3. How to configure with alias i mean with out virtual host

    SvarSlett
  4. great stuff...still useful.

    What are you up to now?

    SvarSlett