Thursday, July 9, 2009

Installing Zend Server CE on Ubuntu

This article was first post at Johan Mares' Blog.

Just as I was finishing my review of the beta version of Zend Server CE, Zend proudly announced the release of Zend Server and Zend Server Community Edition (CE). So I had to start all over again with a fresh installation of Zend Server CE 4.0.1. I was pleased to see that they fixed some of the quirks and bugs I had encountered in the beta version, but oddly enough they introduced some new ones too.

Zend has made quite a lot of noise about their latest products, namely Zend Server and Zend Server CE (Community Edition) and I felt tempted to try it out for myself.
According to Zend, the Zend Server Community Edition (CE) is a free Web Application Server that is simple to install and easy to use. Well, you are about to find out, if you continue reading. It is intended as a community-supported product via the Zend support forums, and updates will be made available periodically. Still according to Zend, the Zend Server CE should be ideal for developing and running non-critical PHP applications. Replace free with commercial, non-critical with business-critical and add some extra features in the mix and you have the Zend Server. Since I do not need a commercial webserver I decided to try out the community edition.

Ubuntu server

At home I usually tinker with virtual Ubuntu servers, so I installed a basic virtual Ubuntu server (8.04 LTS) with OpenSSH server as the only extra software package, no LAMP. I already posted an article on how to install a virtual Ubuntu server on Mac OS X using VirtualBox, so I will not repeat it here. I christened this server zsce and assigned the static IP-address 192.168.1.83 to it. I didn’t bother installing the linux guest additions for VirtualBox.

Zend Server CE doesn’t install a DBMS and the manual doesn’t mention it either, but I thought it made sense to install MySQL before attempting to install Zend Server CE.

sudo aptitude install mysql-server mysql-client

You will be prompted to provide a root password for MySQL.

And now …

Installing Zend Server CE

I used the DEB installation method for installing Zend Server CE using aptitude. Installing on a Ubuntu server means using the command line only.

First you will have to add a repository to be able to download the Zend Server CE

sudo vi /etc/apt/sources.list

Add the following lines to the file:

# Zend Server CE
deb http://repos.zend.com/deb/ce ce non-free

Add Zend’s repository public key. If you did not use the sudo -s command earlier, like mentioned in the manual, you will get the following error:

johan@zsce:~$ sudo wget http://repos.zend.com/deb/zend.key -O- |apt-key add -
--10:31:23-- http://repos.zend.com/deb/zend.key
=> `-'
Resolving repos.zend.com... 93.188.130.102
Connecting to repos.zend.com|93.188.130.102|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1,673 (1.6K) [text/plain]

100%[========================================================>] 1,673 --.--K/s

10:31:24 (441.22 KB/s) - `-' saved [1673/1673]

gpg: no writable keyring found: eof
gpg: error reading `-': general error
gpg: import from `-' failed: general error

Lesson learned: follow the manual to the letter or place the sudo command before the apt-key command.

johan@zsce:~$ wget http://repos.zend.com/deb/zend.key -O- | sudo apt-key add -
--10:32:41-- http://repos.zend.com/deb/zend.key
=> `-'
Resolving repos.zend.com... 93.188.130.102
Connecting to repos.zend.com|93.188.130.102|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1,673 (1.6K) [text/plain]

100%[========================================================>] 1,673 --.--K/s

10:32:41 (104.95 KB/s) - `-' saved [1673/1673]

To follow the manual more closely I now ran the sudo -s command, which makes me root.

johan@zsce:~$ sudo -s
[sudo] password for johan:
root@zsce:~#

Update the package repository info.

aptitude update

Install Zend Server CE. I copied most of the installation messages so you can see which packages are installed with Zend Server CE.

root@zsce:~# aptitude install zend-ce
Reading package lists... Done
Building dependency tree
...
The following NEW packages will be installed:
apache2-mpm-prefork apache2-utils apache2.2-common libaio1 libapache2-mod-php5-zend-ce
libapr1 libaprutil1 libframework1-zend-ce libicu36 libmcrypt4 libmhash2 liboci-zend
libpng12-0 libpng3 libpq4 libpq5 libsqlite0 lighttpd-zend-ce openssl php-bcmath-zend-ce
php-bz2-zend-ce php-calendar-zend-ce php-ctype-zend-ce php-curl-zend-ce
php-data-cache-zend-ce php-debugger-zend-ce php-dev-zend-ce php-exif-zend-ce php-fcgi-zend-ce
php-ftp-zend-ce php-gd-zend-ce php-gettext-zend-ce php-imap-zend-ce php-intl-zend-ce
php-json-zend-ce php-ldap-zend-ce php-mcrypt-zend-ce php-mhash-zend-ce php-mime-magic-zend-ce
php-mysql-zend-ce php-mysqli-zend-ce php-oci8-zend-ce php-optimizer-plus-zend-ce
php-pdo-mysql-zend-ce php-pdo-oci-zend-ce php-pdo-pgsql-zend-ce php-pgsql-zend-ce
php-posix-zend-ce php-soap-zend-ce php-sockets-zend-ce php-sqlite-zend-ce php-tidy-zend-ce
php-tokenizer-zend-ce php-xmlreader-zend-ce php-xmlwriter-zend-ce php-xsl-zend-ce
php-zem-zend-ce php-zendutils-zend-ce php-zip-zend-ce php5-common-extensions-zend-ce sqlite
zend-base-ce zend-ce zend-ce-doc zend-extensions-ce zend-framework-ce zend-gui-ce
0 packages upgraded, 67 newly installed, 0 to remove and 10 not upgraded.
Need to get 48.5MB of archives. After unpacking 179MB will be used.
Do you want to continue? [Y/n/?] Y
...

This can take a while depending on your connection.

...
Setting up sqlite (2.8.17-4build1) ...
Setting up zend-extensions-ce (4.0.0-1+b60) ...
dpkg: dependency problems prevent configuration of zend-gui-ce:
zend-gui-ce depends on lighttpd-zend-ce; however:
Package lighttpd-zend-ce is not configured yet.
zend-gui-ce depends on php-fcgi-zend-ce; however:
Package php-fcgi-zend-ce is not configured yet.
dpkg: error processing zend-gui-ce (--configure):
dependency problems - leaving unconfigured
Setting up zend-framework-ce (1.7.8+b34) ...
Setting up zend-ce-doc (4.0.10+b20) ...
dpkg: dependency problems prevent configuration of zend-ce:
zend-ce depends on zend-gui-ce; however:
Package zend-gui-ce is not configured yet.
dpkg: error processing zend-ce (--configure):
dependency problems - leaving unconfigured
Processing triggers for libc6 ...
ldconfig deferred processing now taking place
Errors were encountered while processing:
lighttpd-zend-ce
php-fcgi-zend-ce
zend-gui-ce
zend-ce
E: Sub-process /usr/bin/dpkg returned an error code (1)
A package failed to install. Trying to recover:
Setting up lighttpd-zend-ce (1.4.18-1+b56) ...

Setting up php-fcgi-zend-ce (5.2.9+b36) ...
Setting up zend-gui-ce (4.0.16+b150) ...
Site zendserver_gui.conf installed; run /etc/init.d/apache2 reload to enable.
* Reloading web server config apache2

Setting up zend-ce (4.0.0-1+b60) ...
* Stopping web server apache2
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
httpd (no pid file) not running
...done.
Starting ZendServer 4.0.0 ..

apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
spawn-fcgi.c.206: child spawned successfully: PID: 7700
Starting ZendServer GUI [Lighttpd] [OK]
[08.04.2009 10:44:59 SYSTEM] watchdog for lighttpd is running.
[08.04.2009 10:44:59 SYSTEM] lighttpd is running.
ZendServer started...

This is a bug they fixed. In the beta version the installation stopped after ‘E: Sub-process /usr/bin/dpkg returned an error code (1)’. I then had to run the installation command again to get to the message ‘ZendServer started…’.

If you want to get rid of the ‘Could not reliably determine the server’s fully qualified domain name… ‘, just add a servername to the Apache configuration file.

vi /etc/apache2/apache2.conf
ServerName zsce

Restart all Zend Server Community Edition daemons.

root@zsce:~# /usr/local/zend/bin/zendctl.sh restart
Stopping ZendServer GUI [Lighttpd] [OK]
spawn-fcgi.c.206: child spawned successfully: PID: 8359
Starting ZendServer GUI [Lighttpd] [OK]

Check the Zend Server Community Edition status

root@zsce:~# /usr/local/zend/bin/zendctl.sh status
[08.04.2009 10:04:54 SYSTEM] Apache is running.
[08.04.2009 10:48:54 SYSTEM] watchdog for lighttpd is running.
[08.04.2009 10:48:54 SYSTEM] lighttpd is running.

Hurray!

Browsing, using Firefox, to https://192.168.1.83:10082 I got ‘Secure Connection Failed’ error; ‘192.168.1.83:10082 uses an invalid security certificate …’. So confirm the exception and you will get a prompt to provide a password for Zend Server CE.

Post-installation steps

Adding the /bin directory to the $PATH environment variable for all users.

Finding the directory for your Zend Server (linux). I already know that the zendctl.sh script is located in that directory, so all I have to do is to find it.

root@zsce:~# updatedb
root@zsce:~# locate zendctl
/usr/local/zend/bin/zendctl.sh

By the way, the location is also mentioned in the manual. Just showing off. :-)

root@zsce:~# vi /etc/profile

and add the following lines to the end of the file:

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

In order for the changes to take effect, run the following command:

root@zsce:~# source /etc/profile

I decided to install the extra extensions.

root@zsce:~# aptitude install php5-extra-extensions-zend-ce
Reading package lists... Done
Building dependency tree
...
The following NEW packages will be installed:
libgif4 libgmp3c2 libltdl3 libming0 libmssql-zend odbcinst1debian1 php-fileinfo-zend-ce
php-gmp-zend-ce php-imagick-zend-ce php-mbstring-zend-ce php-memcache-zend-ce
php-ming-zend-ce php-mssql-zend-ce php-odbc-zend-ce php-pcntl-zend-ce php-shmop-zend-ce
php-sysvmsg-zend-ce php-sysvsem-zend-ce php-sysvshm-zend-ce php-wddx-zend-ce
php-xmlrpc-zend-ce php5-extra-extensions-zend-ce php5-unix-extensions-zend-ce unixodbc
0 packages upgraded, 24 newly installed, 0 to remove and 10 not upgraded.
Need to get 4311kB of archives. After unpacking 10.4MB will be used.
Do you want to continue? [Y/n/?] Y

and also phpMyAdmin.

root@zsce:~# aptitude install phpmyadmin-zend-ce
Reading package lists... Done
Building dependency tree
...
Setting up phpmyadmin (4:2.11.3-1ubuntu1.1) ...
Lighttpd not installed, skipping
invoke-rc.d: unknown initscript, /etc/init.d/lighttpd not found.
Setting up phpmyadmin-zend-ce (4.0.0-1+b17) ...
...

I selected lighttpd as webserver for phpMyAdmin when prompted, this isn’t mentioned in the manual, but it produced a message stating that lighttpd is not installed. I ignored it and phpMyAdmin seems to be correctly installed and working. When you have ServerSpy installed in your Firefox browser you will notice that phpMyAdmin uses lighttpd as webserver. Strange, but it works, just keep going.

When I tried to access phpMyAdmin via my browser (still using my MacBook) I got the following message:

“For security reasons, the link to the phpMyAdmin interface from Zend Server is locked for remote access and is only accessible from localhost. “

Great, I am running Zend Server CE on a command line only linux server and must access phpMyAdmin from the localhost. Zend Server CE is also supposed to be for development environments, so where’s the harm in accessing phpMyAdmin from another computer? Despite being my first encounter with lighttpd it took me only a couple of minutes to figure out how to fix this, without RTFM. I added the IP-address of my home network (192.168.1) to the lighttpd configuration file.

vi /usr/local/zend/gui/lighttpd/etc/lighttpd.conf
...
$HTTP["remoteip"] !~ "127.0.0.1" {
$HTTP["url"] =~ "^/phpmyadmin/" {
url.access-deny = ( "192.168.1" )
server.errorfile-prefix = "//usr/local/zend/gui/lighttpd/share/lighttpd-custom-errors/errorcode-"
}
}
...

Restart all Zend Server Community Edition daemons.

root@zsce:~# /usr/local/zend/bin/zendctl.sh restart
Stopping ZendServer GUI [Lighttpd] [OK]
spawn-fcgi.c.206: child spawned successfully: PID: 8359
Starting ZendServer GUI [Lighttpd] [OK]

Don’t ask me to explain the change to the lighttpd config file, my first attempt to fix it worked. Hurray!

Now we get to the point were they included some new bugs.

I wanted to install the Dojo toolkit and the Zend Framework extras. But compared to the beta version the manual now contains some typos which will prevent you from installing them.

From the manual for version 4.0.1:

aptitude install framework-zend-dojo-ce

resulted in

Couldn't find any package whose name or description matched "framework-zend-dojo-ce"

and

aptitude install framework-zend-extras-ce

resulted in

Couldn't find any package whose name or description matched "framework-zend-extras-ce"

A quick search in the manual for the beta version revealed that the correct way to install the packages is:

aptitude install zend-framework-dojo-ce

and

aptitude install zend-framework-extras-ce

This way the packages installed without errors. Since I have never used the Dojo toolkit and the Zend framework I didn’t test them.

I did not install any other packages, so I do not know if there are more typos.

Tests

This is just a review about the installation of the community edition of the Zend Server. No tests, no benchmarks, no security audit, … Well, as it was installed separately, I did test the database connection to MySQL using the following 3 database extensions: MySQL, MySQLi and PDO.

I created a database (testdb), with 1 table (names) containing 2 fields (id and name), inserted some records using phpMyAdmin and tested the connection to the database and retrieval of the data using PHP-scripts.

The first 2, MySQL and MySQLi, worked flawlessly, but this was not the case for PDO. The following error was displayed in the browser, when testing PDO on Zend Server CE:

Error: SQLSTATE[HY000] [2002] Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2)

The solution for this problem (via Google) was to include socket information in the DSN (Database Source Name) as you can see in the script below. I never encountered this problem when using the default LAMP installation on Ubuntu or CentOS.

unix_socket=/var/run/mysqld/mysqld.sock',
'testusr', 'testpwd');
$sql = 'SELECT * FROM names';
foreach ($dbc->query($sql) as $row) {
echo $row['id'] . '. ' . $row['name'] . "
\n";
}
} catch (PDOException $e) {
echo "Error: " . $e->getMessage() . "
";
}
$dbc = null;
?>

Test PECL installation:

root@zsce:~# pecl list-all
All packages [Channel pecl.php.net]:
====================================
Package Latest Local
pecl/APC 3.1.2 Alternative PHP Cache
pecl/memcache 2.2.5 memcached extension
pecl/hidef 0.1.1 Constants for real
pecl/memcached 0.1.5 PHP extension for interfacing with memcached via libmemcached library
pecl/spidermonkey 0.1.2 JavaScript engine for PHP
pecl/selinux 0.2.1 SELinux binding for PHP script language
pecl/bloomy 0.1.0 Extension implementing a Bloom filter

OK

Test documentation. The following chapters on the locally installed help for the Dashboard (https://192.168.1.83:10082/ZendServer/help/zend_server.htm#dashboard.htm) returned not found errors (404).

  • Administration Interface/Administration/Passwords
  • Tasks/Working with Zend Server

Review

Bugs / quirks / annoyances / missing / typos / remarks:

  • Missing: MySQL
  • Missing: PHP CLI. My mistake, it is present.
  • Typos (?): names of the packages Dojo and extras for Zend Framework are spelled wrong in the manual
  • Documentation: when to install your DBMS, what webserver to choose when installing phpMyAdmin, how to allow access to phpMyAdmin from outside localhost, the relationship between lighttpd and Apache, …
  • Bug: PDO, doesn’t work without including socket info in the DSN
  • Installation takes more time and effort than a default Ubuntu or Centos LAMP installation.
  • The installation of phpMyAdmin reported lighttpd not installed.
  • Bug: some broken links in the locally installed help

I can understand Zend not including MySQL in the installation, because not everyone uses MySQL and if they did include it, people would start complaining why PostgreSQL isn’t included. So, it’s no big deal. It would be a good idea though to include in the installation manual when you are supposed to install your DBMS. Most likely this will be before installing Zend Server, but it wouldn’t hurt mentioning this.

It isn’t that difficult to install Zend Server CE, but it takes more time and work than a default LAMP installation on Ubuntu.

Documentation is still a bit lacking: when to install your database (before seems logical to me), installation of phpMyAdmin (which webserver to choose, how to allow access from another computer), more information on the relationship between lighttpd and Apache … I am not asking for a complete manual on lighttpd and Apache here, it’s just the first time I am confronted with lighttpd (among other stuff) … or is all that supposed to be common knowledge.

Actually, I find it impressive. It’s quite an achievement to offer a product like this and making it free for home/development/non-critical use. No less than 5 installation methods: 1 for Microsoft Windows, 1 for Mac OS X and 3 for Linux (tarball, RPM and DEB). The list of software and packages is extensive, but I might not be the right person to appreciate all of this. I’ve never used a debugger, caching, … and I don’t know why they install 2 webservers (lighttpd and Apache) instead of just one. This is why I stick to reviewing the installation procedure. Let’s be honest; the list of bugs, remarks, … will not take a long time fixing.

Why would you use Zend Server CE ?

Speaking for myself, from a professional and personal perspective, I see no use for Zend Server CE in the near future. This may sound quite harsh, but let me explain.

At work we have a mixed server environment, Windows and Linux (CentOS, Scientific Linux) servers. I do not see us replacing the current webserver setups with Zend Server (CE). Although I do see that a mixed server environment might be the ideal place to use Zend Server; resulting in identical setups for your Windows and Linux webservers, which would make it possible to move sites easily. Especially if you start from a clean slate or want to restart with a clean slate. But this will require a lot of work and I don’t see it happen any time soon. It’s also no use to develop on Zend Server CE when you do not use Zend Server in your production environment.

I am also not impressed with the argument that Zend Server uses a very recent version of PHP (5.2.9) compared to Ubuntu 8.04 LTS (5.2.4) and CentOS / RHEL / SL (5.1.6). You choose an environment and you stick with it for a while and since security updates and bug fixes are backported I do not see a problem with this approach. I do admit that RHEL’s approach feels a bit like the other extreme compared to Zend Server.

It’s very unlikely that shared hosting sites will move en masse to Zend Server in the near future. So when I develop my personal site at home on a Zend Server CE installation and then upload my site to my webhost, there is a risk that there will be errors due to different PHP versions or different installed components, modules and packages. This is asking for trouble; you should always keep your development environment identical (or as identical as possible) to your production environment. The same goes if you work as an independent contractor. Of course, if Zend Server gains a lot of momentum this situation might change in the years to come, but I feel no need to be an early adopter.

I do not feel like I have wasted my time installing Zend Server CE even as I have no intention of using it in the near future. It made me realize that there are some areas where my knowledge is lacking: debuggers, caching, Zend Framework, lighttpd, … So my list of interesting things to study just got a bit longer.

Wednesday, June 17, 2009

HTML Email Marketing from MailChimp

I found this wonderful email marketing service from MailChimp when I was looking for a better newsletter system for myself.



The Features:
  • MailChimp tracks everything for you. See who opened, what they clicked, who bounced, how many times people forwarded your awesome campaign, who didn't open, and more.
  • If accountability and ROI are important to you, MailChimp keeps you on top of your email marketing performance with awesome reports. Show your boss you deserve that promotion!
  • Easily import existing lists from Excel, Salesforce, Highrise and more. We'll automatically handle duplicates, bounces, opt-ins and unsubscribes. Your subscribers can even change their email and manage their own preferences.
  • Built-in tools help you design and deliver great looking HTML email campaigns that actually work. No fugly templates here. We provide you with professional header graphics, fonts, and color palettes to customize the perfect email. If you're a professional designer, you can upload your own code.
  • Design snazzy signup forms with your own colors and logos, then embed them into your website or blog. We'll provide all the code you need. After that, we'll manage all subscriptions automatically for you.

Tuesday, May 26, 2009

Set up lighthttpd and PHP in Debian Etch

This article is from VPS Media

This article will explain how to install and configure lighthttpd with PHP5 and MySQL. lighthttd is a web server designed to be fast, secure, flexible and standards-complient while being optimized for speed-critical environments.

Its low memory footprint, light CPU load and speed make it the perfect web server for an environment such as a 384MB VPS. lighthttpd supports the FastCGI interface, which we will use to enable PHP5 support. This article assumes you have already updated your system with the latest fixes and DO NOT have a web server, such as Apache, already installed on your VPS. We will be installing all required applications with the apt-get utility in Debian.

Install MySQL

We begin by installing MySQL 5.0:

# apt-get install mysql-server mysql-client

This should install and start up the MySQL server. Let’s give the MySQL root account a password, such as:

# mysqladmin -u root password yourpassword

Now we have to check on which address MySQL is listening with netstat:

# netstat -tap | grep mysql

The output should look similair to this:

tcp 0 0 localhost:mysql *:* LISTEN 1695/mysqld

Which means MySQL is listening on localhost only. But lets say you see output such as:

tcp 0 0 *:mysql *:* LISTEN 1695/mysqld

That means anyone can access your database and modify data, so you should set a password for your hostname. For example:

# mysqladmin -h server1.domain.com -u root password yourpassword

Replacing sever1.domain.com with your domain name.

Install lighthttpd

We can install lighthttpd with apt-get, like this:

# apt-get install lighttpd

After installation finishes, open your web browser and type in your VPS’ IP and you should see the placeholder page. Lighttpd’s default document root is /var/www on Debian, and the configuration file is /etc/lighttpd/lighttpd.conf.

Install PHP5

PHP works on lighthttpd using the FastCGI interface. Debian provides a FastCGI-enabled PHP5 package, which we can install like this:

# apt-get install php5-cgi

To enable PHP5 in lighttpd, we must modify two files (/etc/php5/cgi/php.ini & /etc/lighttpd/lighttpd.conf). First we open /etc/php5/cgi/php.ini:

# nano /etc/php5/cgi/php.ini

Add the following line right at the end of the file:

cgi.fix_pathinfo = 1

Then we open /etc/lighttpd/lighttpd.conf and add “mod_fastcgi”, to the server.modules stanza:

# nano /etc/lighttpd/lighttpd.conf

server.modules = (
“mod_access”,
“mod_alias”,
“mod_accesslog”,
“mod_fastcgi”,
# ”mod_rewrite”,
# ”mod_redirect”,
# ”mod_status”,
# ”mod_evhost”,
# ”mod_compress”,
# ”mod_usertrack”,
# ”mod_rrdtool”,
# ”mod_webdav”,
# ”mod_expire”,
# ”mod_flv_streaming”,
# ”mod_evasive”
)

and then right at the end of the file, we add the following stanza:

fastcgi.server = ( “.php” => ((
“bin-path” => “/usr/bin/php5-cgi”,
“socket” => “/tmp/php.socket”
)))

Next, we restart lighthttpd:

# /etc/init.d/lighttpd restart

Testing Your Installation

The document root of the default web site is /var/www. To test if PHP was installed properly, create a test.php file in your web folder, as such:

# nano /var/www/phpinfo.php

Place the following code inside:

Now point your browser to http://ip.address/phpinfo.php and you should see your PHP configuration. As you can see on the Server API line, PHP5 is working through FastCGI. If you scroll further down, you will see all modules that are already enabled in PHP5. MySQL is not listed there which means we don’t have MySQL support in PHP5 yet.

Enable MySQL Support in PHP5

To get MySQL working with PHP5 all we have to do is install the php5-mysql package.

# apt-get install php5-mysql

Now restart lighthttpd:

# /etc/init.d/lighttpd restart

Reload the phpinfo.php file in your web browser and scroll down to the modules section again. You should now find lots of new modules there, including the MySQL module. That’s about it, congratulations on installing MySQL/lighthttpd/PHP5 on your VPS!