Set up an Amazon Ubuntu server to run Zend Framework PHP Web Application

First of all, I am new to Ubuntu.

I am a Centos fan for last couple of years, but have heard of Ubuntu is a great system too, especially user friendly.

Today, one client asked me to rebuild a Amazon server for his Zend Framework PHP Web Application dut to its current stability issue. (Amazon Linux seems to have issue with MySQL which causes MySQL memory issue randomly). I figured it is a good time for me to try Ubuntu.

First, start up a new Amazon micro instance with Ubuntu LTS (LTS seems to be more stable and long term support).

Install Zend Server 6.0 Community Edition

Zend Server CE has made the installation so easy for us.

  1. SSH to server
  2. download Zend Server (DEB/RPM Installer Script)
  3. Unzip it and run the install script as root:
    ./ 5.3     or    ./ 5.4  if you need 5.4 version PHP
  4. Simply ‘y’ when prompt
  5. Done – navigate to http://<server ip> you will see “It works”
Install MySQL
  1. apt-get install mysql-server
  2. Please be noted the default MySQL sock is in here: /var/run/mysqld/mysqld.sock

Install phpMyAdmin

  1. Navigate to http://<server ip>:10081 and set up the Zend Server
  2. Deploy Application
  3. Follow this link to download phpMyAdmin package and install it via Zend Server
  4. Well, you may want to disable the auto login for security reason, change auth_type to http in this file:

Set up FTP

  1. Follow this link

Set up Zend Server and Magento on Centos 6

Finally got a chance to write up a quick guide on how to set up Magento running on Zend Server Community on Centos 6.

Server Hosting

I have been wondering around between Rackspace and Ninefold. My website is gonna be for Australian market only. Ninefold is clearly faster choice, but more expensive, especially when I don’t know whether my website can make money or not. I have been using Rackspace for a while and really enjoy their service. The only thing I am worry about is the SEO impact if I host an Australian website on U.S. After days of researching, I decided to give Rackspace a go, and I think if the website goes well, I may just move the website back to Australia eventually.

Install Zend Server

In here, I have to mention on Magento site, there is a bundle install script for Zend + Magento, however, I tried that and the script doesn’t work anymore. They should have updated that script more frequently. Anyway, let us do our own.

Change SELinux setting

setenforce permissive

Add Yum repos for Zend

vim /etc/yum.repos.d/zend.repo

Paste the content below into zend.repo

name=Zend Server

name=Zend Server - noarch

Install Zend Community Edition with PHP 5.3

yum install zend-server-ce-php-5.3


Normally I just simply open ports for: Zend Server, HTTP, HTTPS, FTP, SSH.
iptables -I INPUT 5 -p tcp --dport 10081 -j ACCEPT
iptables -I INPUT 5 -p tcp --dport 443 -j ACCEPT
iptables -I INPUT 5 -p tcp --dport 80 -j ACCEPT
iptables -I INPUT 5 -p tcp --dport 21 -j ACCEPT
iptables -I INPUT 5 -p tcp --dport 22 -j ACCEPT
iptables -L --line-numbers
/etc/init.d/iptables save
/etc/init.d/iptables restart


Browsing http://[server url or IP address]:10081 to set up Zend Server.


To restart Zend Server:

/etc/init.d/zend-server restart

To add Zend Server to server start up:

chkconfig zend-server on

Install MYSQL server and PhpMyAdmin

Install MYSQL client and server:

yum install mysql mysql-server

Start MYSQL server & Initialisation

/etc/init.d/mysqld start


Add MYSQL to server start up service

chkconfig mysqld on

Install PhpMyAdmin

rpm -Uvh

yum install phpmyadmin

Add your IP to allow list in phpMyAdmin apache conf file:

vim /etc/httpd/conf.d/phpMyAdmin.conf

/etc/init.d/zend-server restart

Install Magento

Download Magento Sample data

Use phpMyAdmin to create Magento database and import the sample database dump.

tar -zxvf magento-sample-data-

Move sample media files to web folder (I use /var/www/html as document root folder here):

mv magento-sample-data- /var/www/html/

Download Magento


tar -zxvf magento-

cp -r magento/* /var/www/html/

cp magento/.htaccess /var/www/html/

change folder permission

chmod -R o+w media var

chmod o+w app/etc

Set up FTP

I will need a FTP account to deploy my Magento skins to server. Proftpd is clearly a better choice.

yum install proftpd

service proftpd start

chkconfig proftpd on

useradd magento
 passwd magento

Need to change user's default login place:

vim /etc/passwd 

Give user written permission to Magento folder:

chown magento.magento /var/www/html/ -Rf 

Enable Web URL Rewrite to support SEO

vim /etc/httpd/conf/httpd.conf

Change AllowOverride All for your document folder, restart Zend Server.

Now proceed with Magento GUI installation by browsing: http://[server url]



I found folder permission is not enough for Magento Connect to use, on the other side, I need to make sure FTP user has permission to upload source files. Here is the steps I found works well without setting folder permission to 777.

#add apache to FTP user group: magento
#your magento folder should have magento.magento ownership
#while you are in magento folder, do following:
sudo usermod -G magento apache
sudo find . -type f -exec chmod 644 {} \;
sudo find . -type d -exec chmod 775 {} \;
sudo chmod o+w var var/.htaccess app/etc
sudo chmod 550 lib/PEAR
sudo chmod -R o+w media
sudo /etc/init.d/httpd restart

jQuery Ajax URL trick

Today I spent hours to get jQuery Ajax sending php emails works. It was just one tiny trick that I didn’t pay attention. I have to post it here just in case someone else had similar problem.

Environment: PHP 4, jQuery 1.44
Object: Ajax to send emails

First of all, here is a great tutorial: How to send email with php ajax and jquery

Now, I did the same thing as tutorial just modified some small parts (URL etc), and it didn’t work.
For instance, my main page is: http://<domain>/live/index.php/mail/index.php, and the PHP email file is in /live/ajax/mail.php  In $.ajax function, there is a variable URL to be specified, and here is the trick part.

URL I tried:

  1. ../ajax/mail.php  — It failed, because it was looking for http://<domain>/live/index.php/ajax/mail.php
  2. http://<domain>/live/ajax/mail.php — It failed, because something to do with the cross domain issue I think, wired thing is if Type = GET, it will work. If Type = POST, it won’t work.
  3. ../../ajax/mail.php — Worked.

So the URL levels should be based on the HTTP URL, not the folder levels.

Send Magento Email through Google App

To improve server security and performance, it is suggested to set up Magento to send email through external mail server.

Here I would like to share my experience of setting up Magento to send emails through Google App (GMail).

  1. Install this free extension: SMTP Pro Email
    By the time I writing this, the extension requires you set to Alpha mode to be able to install.
  2. Magento Admin -> System -> Configuration -> Left Menu: Advanced -> System -> SMTP Pro Email Settings:
    Enable SMTP Pro Email: Yes
    Authentication: Login
    Username: (Your Gmail or Google App account)
    Password: Your password here
    Port: 465
  3. Click: Save Config
  4. Do a test by click “Run Self Test”

If you are experiencing error messag:

Warning: call_user_func(Zend_Validate_Hostname_Com::getCharacters) first argument is expected to be a valid callback

It may be because your Magento is installed on Zend server and got libraries conflicts with the Zend library comes with Zend Server. To fix, please:

  1. Edit /usr/share/magento/lib/Zend/Validate/Hostname.php:
    Replace: if (Zend_Loader::isReadable($classFile)) {
    With: if (file_exists($classFile) && Zend_Loader::isReadable($classFile)) {

Hope you find this helpful. Let me know.

Zend Magento Installation Guide

For a successful e-commerce website, the speed is very important. That’s why we need to consider Zend Server + Magento.

Here is a quick installation guide to help you get started.

Environment: VPS from Rackspace (Centos 5.4)

  1. download zend+magento from Magento Download Page
  2. modify zend.repos.rpm in [ISV] section:  (This could be a bug in the installation script)
  3. run ./   (This will install everything for you. Apache2, Zend, MYSQL, Magento ….).
  4. Open Server firewall to allow access from port: 80 and 10081 (Zend Server Console)
    iptables -I RH-Firewall-1-INPUT 9 -p tcp –dport 80 -j ACCEPT
    iptables -I RH-Firewall-1-INPUT 9 -p tcp –dport 10081 -j ACCEPT
  5. visit http://<yourserver>:10081 to change zend server admin password
  6. Change MYSQL password:
    mysqladmin -u root password <new password>
    mysqladmin -u root -h <local hostname> <new password>
  7. Create a MYSQL user just for Magento:
    grant all privileges on magento.* to magentodbuser@localhost identified by ‘magentodbpassword*’
    vim /usr/share/magento/app/etc/local.xml
    to put new dbuser and dbpassword in Magento’s configure file
  8. I don’t know what’s default password to login to Magento Admin Panel, so I changed it directly in MYSQL:
    go to magento database to change password for admin user:
    update admin_user set password = MD5(‘temppassword’) where user_id = 1
  9. After login to Magento Admin Panel, you will get a warning message to change {baseurl}, and here we go:
    in admin panel, system configuration, web, UnSecure and Secure
    change {{base_url}} in Base URL (only) to http://yourdomainname
  10. Done.

Let me know if it helps. Thanks.

Centering Block Content in IE8

To Center a Block Content in CSS, margin: 0 auto and width: xxxpx works great in most cases.
Sometimes you may find Not working in IE8? Please follow below to fix this:

  1. HTML Declaration:
    <!DOCTYPE html
    PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN” “”>
  2. Don’t put any other code before the HTML Declaration, even Comments!