Two More Apache Tweaks Required After Ubuntu 10.04 Upgrade

Posted on May 3rd, 2010 in Development, Linux | No Comments »

While I was troubleshooting why Apache stopped serving php apps from my home directory, I ran into two more annoyances that required attention. I figured I’d share them as well in case you run into them yourself.

Here’s what I saw when I reloaded Apache:

jkendall@san-diego:/etc/apache2$ sudo /etc/init.d/apache2 reload
  * Reloading web server config apache2
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
[Fri Apr 30 13:47:38 2010] [warn] NameVirtualHost *:80 has no VirtualHosts
                                                                                    [ OK ]

As you can see, Apache reloaded fine, but I don’t like seeing anything other than [ OK ] when I’m reloading my web server. Let’s tackle these one at a time.

Could not reliably determine the server’s fully qualified domain name

Why is Apache all of a sudden complaining about what’s worked for so long? I’m not sure exactly, but thankfully the fix was simple and easy. Simply adding “ServerName localhost” to /etc/apache2/httpd.conf took care of the first complaint (Big thanks to Mohamed Aslam for his clear instructions on how to get this fixed.).

NameVirtualHost *:80 has no VirtualHosts

The problem boiled down to having NameVirtualHost defined in more than one place. In my case, NameVirtualHost was defined both in /ect/apache2/ports.conf and /etc/apache2/sites-available/default. Commenting out the NameVirtualHost *:80 line in /etc/apache2/sites-available/default did the trick (Thanks to the guys in this Server Fault thread, especially to Ivan, for providing the necessary clues to track this one down.).

After making the above changes, reloading Apache didn’t throw any more warnings. w00t!

Share

Upgrading to Ubuntu 10.04 Breaks Serving php from Home Directories

Posted on April 30th, 2010 in Development, Linux | 5 Comments »

I upgraded to Ubuntu 10.04 this morning and immediately noticed I could no longer serve php applications from my home directory. When I tried to visit one of my projects, http://test.local for example, Firefox opened a download dialog with a message similar to “You have chosen to open index.phtml . . .”

After quite a bit of googling and forum searching, I went to Twitter asking for help. Many thanks to @sypherNL for helping me resolve this one.

It seems that something has changed in /etc/apache2/mods-enabled/php5.conf. If you’re experiencing this same issue, check your php5.conf and see if it matches mine.

<IfModule mod_php5.c>
    <FilesMatch "\.ph(p3?|tml)$">
        SetHandler application/x-httpd-php
    </FilesMatch>
    <FilesMatch "\.phps$">
        SetHandler application/x-httpd-php-source
    </FilesMatch>
    # To re-enable php in user directories comment the following lines
    # (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it
    # prevents .htaccess files from disabling it.
    <IfModule mod_userdir.c>
        <Directory /home/*/public_html>
            php_admin_value engine Off
        </Directory>
    </IfModule>
</IfModule>

If your php5.conf file looks like the one above, simply comment out the

<IfModule mod_userdir.c>

lines as instructed. Once that’s done, restart apache with the following command:

sudo /etc/init.d/apache2 reload

Clear your browser’s cache and try to visit your site again. I didn’t think the fix took at first, but after clearing cache everything worked just fine.

Related Links

Share

From Zero to Zend Framework Project in 10 Minutes

Posted on April 17th, 2010 in Development | 10 Comments »

I first started working with the Zend Framework in July of 2007. The framework has come a long way since then, and one of my favorite new components is Zend Tool. Until Zend Tool came on the scene, my least favorite part of any Zend Framework project was getting the project up and running, from zero to “Hello World,” if you will. I always left out some important piece of configuration, screwed up the directory structure, or made some other equally foolish, simple mistake that kept me chasing my tail until I finally got everything set up just right. No longer! Zend Tool does all of that work for me, allowing me to get to work on the meat of my project right away.

Of course, you can’t use Zend Tool until you’ve got the framework installed. Once the framework is installed, there are very specific steps required to fire up Zend Tool. Once Zend Tool builds the project for you, you’re going to need a virtual host set up so that you can actually run the thing. No problem, right?  Well, maybe not.

It can be really challenging for the new guy to get from zero to a Zend Framework project without wanting to chunk his computer out the window (headdesk anyone?). I know it was that way for me. In the interest of saving his sanity and helping the new gal get going, I’ve tried to put all the necessary steps together in one place.

Here’s what we’re going to do:

  • Install the Zend Framework
  • Get Zend Tool up and running
  • Create a new Zend Framework project
  • Get an virtual host up and running
  • Celebrate victory!

Disclaimer

While I’m going try to stay true to my “Zero to Zend Framework Project” thesis, I am making a few assumptions. This tutorial is written for Ubuntu, PHP 5, and Apache. While I’d love to be able to address Windows, Mac, and other *nix distros, I can only share what I know.  I’m also assuming PHP 5 (PHP 5.2.4 at minimum) and Apache are both installed and functioning correctly, and Apache’s mod_rewrite module is up and running. If that’s not the case, please refer to the resources section at the end of this post to find instructions on getting everything ready to go.

Installing the Zend Framework

Installing the Zend Framework is as easy as downloading a .zip or .tar.gz file (your choice) and extracting the contents onto your machine.

  • Create a directory named phplib in your home folder.
  • Head over to Zend Framework: Downloads and download Zend Framework <version_num> Full.
  • Double click on the downloaded file, choose “Extract,” navigate to the phplib directory, and click “Extract.”

As of this writing, the most recent version of the Zend Framework is 1.10.3, so the full path to my Zend Framework installation would be

/home/jkendall/phplib/ZendFramework-1.10.3

IMPORTANT: Make sure that you downloaded Zend Framework <version_num> Full.  That will be important later.

TIP: As new versions of the framework are released, I like to be able to switch between them easily.  I always make a soft link (symbolic link, symlink) to the latest release and name it Zend.  You can either right-click on the ZendFramework-1.10.3 folder and select “Make Link” (make sure to name the link “Zend”), or create a soft link from the command line like so:

~/phplib/ZendFramework-1.10.3$ ln -s ZendFramework-1.10.3 Zend

When a new version of the framework is released, I install the new version to its own folder and switch the soft link to target the directory containing the latest release.  That can come in handy down the road.

Get Zend Tool running

There are a few different ways to get Zend Tool running, perhaps better than mine, but I like to create a bash alias for zf.sh (For information on how to get bash aliases working, see this bash aliases tutorial.). My alias looks like alias zf='/usr/share/phplib/Zend/bin/zf.sh'.

Whichever method you use, make sure to test your alias by calling zf --help from the command line.

Creating a new Zend Framework Project

Now we’re getting to the good stuff.  First, head back to your home directory and create a new directory called public_html.  This is where you’re going to store your Zend Framework project (and any future web projects, for that matter).

Next, cd into the public_html directory and execute the following command:

~/public_html$ zf create project ZeroToZF

That’s all there is to it!  You’ve got your project structure in place, a default IndexController and ErrorController, your application config, the necessary view scripts, etc (See the Zend Application Quick Start for full rundown of what got created.).

IMPORTANT: While the full project structure is now in place, the Zend Framework is not included in your project for you.  Deciding how the framework should be included in the project is up to the developer.  I like to copy the library out of the Zend Framework install folder into the application’s library folder.  In our example, I would copy

/home/jkendall/phplib/ZendFramework-1.10.3/library/Zend

into

/home/jkendall/public_html/ZeroToZF/library

When done properly, the full path to Zend/Log.php in your application should be

/home/<username>/public_html/ZeroToZF/library/Zend/Log.php

Sweet!  We’re almost there.

Creating a Virtual Host

There are a decent number of steps here, but executing them is straightforward, so bear with me.  Also, a lot of these steps need to be executed from the command line.  Forewarned is forearmed and all that.

If you have not done so already, open the terminal application (Applications -> Accessories -> Terminal) and cd into /etc/apache2/sites-available.  Here you’ll find virtual host definitions.  Most likely you’ll see a file named default (or possibly 000-default).  Peek at that if you’d like to see an example of a virtual host, but what we’re going to put together is a lot simpler.

IMPORTANT: Since /etc and its subfolders are owned by root, you’ll need to run all of the following commands as root.  We’ll be using both the sudo and the gksudo commands to do that.

After using the command line to cd into /etc/apache2/sites-available, execute the following command to create your own vhost file:

/etc/apache2/sites-available$ gksudo gedit ZeroToZf.local

The file extension isn’t important, a lot of people use .conf, but I like to use .local for sites hosted locally.

Once you’ve got gedit open, the file’s contents should look like this:

<VirtualHost *:80>
        ServerName zerotozf.local
        DocumentRoot /home/jkendall/public_html/ZeroToZF/public
</VirtualHost>

Of course, jkendall should be replaced by your username.

Next we need to make your new virtual host file available to Apache.  You can do that by executing

/etc/apache2/sites-available$ sudo a2ensite ZeroToZF.local

If everything worked properly, you should see the following message:

Enabling site ZeroToZF.local.
Run '/etc/init.d/apache2 reload' to activate new configuration!

Next, edit your /etc/hosts file by adding zerotozf.local like so:

/etc/apache2/sites-available$ gksudo gedit /etc/hosts

Add the following line below the entry for localhost

127.0.0.1 zerotozf.local

NOTE: When adding a host to /etc/hosts, the case of the hostname is not important.  I like to add hostnames in lowercase, but you can add it as ZeroToZF.local if you like.

Save the file, close gedit, and execute

/etc/apache2/sites-available$ sudo /etc/init.d/apache2 reload

You should see the message

* Reloading web server config apache2                                          [ OK ]

Open up your browser and visit http://zerotozf.local.  You should see the Zend Framework welcome screen.

Congrats!  You did it!

Next Steps

Now that you’ve got your first project up and running, you’re probably going to want to actually do something with it.  I’d highly recommend heading over to Rob Allen’s site for his excellent Getting Started with Zend Framework tutorial.  It’s the same tutorial I followed when I first started with the framework (an earlier version, of course), and I’ve referred back to it many times since.

Wrapping Up

Getting started with the Zend Framework was a challenging proposition for me.  Just getting to the point where I could start working on a project was sometimes maddening as a result of all the steps involved, many of which had nothing to do with the framework, at least not directly.  I’ve tried, hopefully successfully, to lay out all the steps you might need to get from zero to a Zend Framework project in (about) 10 minutes.

Working with the Zend Framework has been a rich and rewarding experience for me.  I’ve learned almost everything I know about best practices, object oriented programming, *nix, and Apache (to name just a few) as a direct or indirect result of the Zend Framework.  I wouldn’t have been able to do that without the help of the Zend Framework community.  I won’t name names, as I’m sure to unintentionally leave out some great folks, so I’ll throw you a link to the Zend Framework Community Forum.  Head over there when you’ve got a Zend Framework problem you just can’t solve on your own.  You’ll meet some great folks and learn a lot in the process.  They’ve saved my bacon more than once.

If I’ve left out any steps or made some egregious error, please let me know in the comments.  I’ll be grateful and post updates and corrections as soon as possible.

Resources

Share

Mail Notification 5.0 with SSL in Ubuntu

Posted on February 14th, 2008 in Linux | 3 Comments »

The Problem

We recently began using SSL to connect to IMAP at work. Prior to switching to SSL I had been using the excellent Mail Notification to let me know if I had any messages in my inbox. As soon as we switched over to SSL, Mail Notification quit alerting me to the presence of new email.

I figured that all I had to do was change my preferences in Mail Notification and select SSL. Turns out I was right, except I couldn’t select SSL – all of the “SSL/TSL” options were grayed out. Why in the world would that be? After some research I discovered that:

  • SSL isn’t available if the package was built without SSL support (makes sense)
  • The OpenSSL license conflicts with the Debian license

Mail Notification is available in the Ubuntu repository, but without SSL support. Bummer.

Build it Yourself

The resolution is to build Mail Notification with SSL support enabled, but I quickly discovered that building Mail Notification was not as easy as I thought it would be. Although the installation is well documented in the INSTALL file, I still ran into a lot of problems with dependencies.

Dependencies Required

After a lot of troubleshooting and not a little frustration, I came up with a list of dependencies that I needed installed in order to configure and make Mail Notification 5.0 on Ubuntu Gutsy:

  • build-essential
  • gnome-core-devel
  • libnotify-dev
  • libgnome2-dev
  • libgmime-2.0-2-dev
  • libssl-dev

I used the Synaptic Package Manager to install each of these dependencies. Read on if you’re looking to troubleshoot a specific error that you’re running into.

Errors and Troubleshooting

The first time I ran

$ ./configure

I got this error:

checking for C compiler default output file name... 
configure: error: C compiler cannot create executables
See `config.log' for more details.

Installing build-essential took care of the C compiler issue, but I found a new one the next time I ran configure:

Error: checking for GNOME... no
configure: error: unable to find the GNOME libraries

This one drove me a little batty. What does it mean it can’t find the GNOME libraries? I’m running GNOME for Pete’s sake! After a decent amount of hair pulling and a seemingly endless amount of Googling, I finally found that gnome-core-devel, libnotify-dev, and libgnome2-dev resolved the

unable to find the GNOME libraries

error.

Next up was the GMIME error:

checking for GMIME... configure: error: Package requirements (gmime-2.0 >= 2.1.0) were not met:
 
No package 'gmime-2.0' found

At least by now I was making it most of the way through the

configure

process. I found that installing libgmime-2.0-2-dev resolved the issue, finally allowing me to complete the configuration.

Of course, the whole point was to build Mail Notify with SSL support. What do you think I found when configure finally ran all of the way through? Down at the bottom of the options list, I saw this:

--enable-ssl                 no (OpenSSL not found)

By now, I had started seeing a pattern: look up the dependencies, find their dev libraries, install their dev libraries, and voila, on to the next issue. With that in mind, I installed libssl-dev and ran

$ ./configure

one last time. Mail Notify configured without errors and with SSL support. A quick

make

and

make install

later and I had a Mail Notify 5.0 installation complete with SSL support.

Other Options

There seem to be a lot of different ways to skin this particular cat. The solution above is what worked for me, your mileage may vary. You may find it useful to refer to the discussion in this related bug report for background.

For another way to resolve this issue, you might try “How to make a small change to a Debian tool and repackage it.” I didn’t find this article until after I had resolved the issue myself, but it looks like it might be a lot simpler.

Share