Installing Zend Framework on Debian 7.5

Zend Framework 2 is an open source framework for developing web applications and services using PHP 5.3+ using 100% object-oriented code and utilises most of the new features of PHP 5.3, namely namespaces, late static binding, lambda functions and closures. The components form a powerful and extensible web application framework and also offers a robust, high performance MVC implementation, a database abstraction that is easy to use, a forms component that implements HTML5 form rendering, validation and filtering as well as other components that provides authentication and authorization against common credential stores.

Downloading Zend Framework

To download the latest release of the Framework, we access it at http://framework.zend.com/downloads/.

Installing Zend Framework

Once downloaded, we can extract the archive to /usr/share/zend and re-use it in multiple applications.

Setting up Zend Framework

To use the shared Zend Framework library in our application, we set an environment variable in our virtual server to point to the installation directory of our library.

    SetEnv ZF2_PATH /usr/share/zend/ZendFramework-2.3.1/library

An alternative is to have the library on a per-application basis as per the skeleton application.

Advertisements

Installing Tomcat and Java Development Tools on Debian 7.5

Apache Tomcat is an application server that serves Java applications to its users and implements the specifications of Java Servlet and Java Server Pages developed by Sun Microsystems.

Installing Apache Tomcat

To install the basic application, we execute the following command in a “root” shell.

apt-get install tomcat7

To access the default page, we can access it at http://localhost:8080/.

To take advantage of additional functionality, we can install some packages that would allow us to control the application server from a web interface as well as have example applications and the documentation to Tomcat available. To install the additional packages, we execute the following command in a “root” shell.

apt-get install tomcat7-admin tomcat7-examples tomcat7-docs

Configuring Tomcat Web Interface

To enable access to some of the features, we need to set a username and password for Tomcat in the /etc/tomcat7/tomcat-users.xml file. To define a user “admin” with password “password”, we edit the file to contain the following.

<tomcat-users>
    <user username="admin" password="password" roles="manager-gui,admin-gui"/>
</tomcat-users>

Once we’ve defined the user, we will be able to access the management sections of Tomcat. For these changes to take effect, we need to restart the service by executing the following command in a “root” shell.

service tomcat7 restart

Testing Tomcat Web Interface

To view the Tomcat documentation, we can access it at http://localhost:8080/docs. This will provide us with extensive information on how to perform something with Tomcat.

To view the Tomcat example applications, we can access it at http://localhost:8080/examples. The examples implement a few different technologies that we can use for reference since the source code is included as well.

To view the Tomcat manager web application, we can access it at http://localhost:8080/manager/html, which will allow us to manage the Java applications (start, stop, deploy and reload applications) as well as enable us to find memory leaks in our running applications.

To view the Tomcat host-manager web application, we can access it at http://localhost:8080/host-manager/html, which will allow us to test, adjust and add virtual hosts in order to serve our applications.

Installing the Java Development Tools

To enable us to develop Java applications for Tomcat, we first need to install a compatible Java Development Kit by executing the following command in a “root” shell.

apt-get install default-jdk

This will install the openjdk-6-jdk package on our server. The documentation also suggests that we install Apache Ant, a build tool for Java applications, by executing the following command in a “root” shell.

apt-get install ant

Installing a Certificate on a Virtual Host

To enable the use of multiple secure virtual hosts, we use name-based as well as ip-based virtual hosts. To setup the secure virtual host, we use the following template.

NameVirtualHost 192.168.100.xxx
<VirtualHost 192.168.100.xxx:443>
    ServerName sitename
    ServerAdmin webmaster@sitename

    SSLEngine On
    SSLCertificateFile /etc/ssl/CA/certs/sitename.cert
    SSLCertificateKeyFile /etc/ssl/CA/private/sitename.key.nopass

    BrowserMatch "MSIE [2-6]" \
        nokeepalive ssl-unclean-shutdown \
        downgrade-1.0 force-response-1.0
    BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown

    DocumentRoot /home/www-data/sitename
    <Directory /home/www-data/sitename>
        Options SymLinksIfOwnerMatch
        AllowOverride AuthConfig
        Order allow,deny
        Allow from all
    </Directory>

    DirectoryIndex index.html
    ErrorDocument 404 /404.html

    ErrorLog ${APACHE_LOG_DIR}/sitename/error.log
    CustomLog ${APACHE_LOG_DIR}/sitename/access.log combined
</VirtualHost>

From the above, it is clear that we can setup a secure as well as a non-secure virtual host, whereby the non-secure virtual host would host general information and the secure virtual host the information exchange that requires encryption, e.g. the non-secure hosting a product catalogue and the secure hosting the payment component.

To ensure that the user always access the secure virtual host, we use the following template.

NameVirtualHost 192.168.100.xxx
<VirtualHost 192.168.100.xxx:80>
    RewriteEngine on
    ReWriteCond %{SERVER_PORT} !^443$
    RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R,L]
</VirtualHost>

<VirtualHost 192.168.100.xxx:443>
    ServerName sitename
    ServerAdmin webmaster@sitename

    SSLEngine On
    SSLCertificateFile /etc/ssl/CA/certs/sitename.cert
    SSLCertificateKeyFile /etc/ssl/CA/private/sitename.key.nopass

    BrowserMatch "MSIE [2-6]" \
        nokeepalive ssl-unclean-shutdown \
        downgrade-1.0 force-response-1.0
    BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown

    DocumentRoot /home/www-data/sitename
    <Directory /home/www-data/sitename>
        Options SymLinksIfOwnerMatch
        AllowOverride AuthConfig
        Order allow,deny
        Allow from all
    </Directory>

    DirectoryIndex index.html
    ErrorDocument 404 /404.html

    ErrorLog ${APACHE_LOG_DIR}/sitename/error.log
    CustomLog ${APACHE_LOG_DIR}/sitename/access.log combined
</VirtualHost>

Setting up Apache Virtual Hosts

To enable the use of multiple virtual hosts, we use name-based as well as ip-based virtual hosts. To setup the virtual host, we use the following template.

NameVirtualHost 192.168.100.xxx
<VirtualHost 192.168.100.xxx>
    ServerName sitename
    ServerAdmin webmaster@sitename

    AccessFileName .htaccess
    DocumentRoot /home/www-data/sitename
    <Directory /home/www-data/sitename>
        Options SymLinksIfOwnerMatch
        AllowOverride AuthConfig
        Order allow,deny
        Allow from all
    </Directory>

    DirectoryIndex index.html
    ErrorDocument 404 /404.html

    ErrorLog ${APACHE_LOG_DIR}/sitename/error.log
    CustomLog ${APACHE_LOG_DIR}/sitename/access.log combined
</VirtualHost>

From the above template, we set sitename to the URL of the virtual host and create a directory for it, setting the ownership of it to www-data:www-data as well as granting the owner and group full access to it. We also create a directory under the main apache log files for the virtual host’s log files.

We create a phpinfo.php file in the root directory of the virtual host to ensure the availability and configuration of PHP on it. The content of the phpinfo.php file is the following.

<?php
phpinfo();
?>

To enable the virtual host, we execute the following command in a “root” shell.

a2ensite sitename

To reload the configuration, we reload the apache2 service by executing the following command in a “root” shell.

service apache2 reload

Installing Apache with PHP5 and SSL support on Debian 7.5

The web server component of our development server has multiple purposes in our environment and is used for

  • the development of client solutions;
  • the development of software products;
  • the hosting of version control software, namely Subversion and Mercurial; and
  • the hosting of project management software, including time and issue tracking, namely Redmine.

Installing Apache

We install the required packages by executing the following command in a “root” shell.

apt-get install apache2 apache2-doc

Installing PHP

To enable the processing of PHP scripts, we install PHP and the PHP Apache Module by executing the following command in a “root” shell.

apt-get install php5 libapache2-mod-php5 php-doc

Installing PHP Modules

To enable the use of some additional functionality in PHP, we install the PHP modules by executing the following command in a “root” shell.

Retrieving files

To enable the retrieval of files, we install the php5-curl package by executing the following command in a “root” shell.

apt-get install php5-curl

Handling graphics

To enable the handling of graphics, we install the php5-gd package by executing the following command in a “root” shell.

apt-get install php5-gd

The module supports the PNG, JPEG, XPM formats as well as Freetype/Truetype fonts.

Finding a Location

To enable the determination of the geographical location of an IP address, we install the php5-geoip package by executing the following command in a “root” shell.

apt-get install php5-geoip

Internationalisation

To enable internationalisation in PHP scripts, we install the php5-intl package by executing the following command in a “root” shell.

apt-get install php5-intl

Encryption

To enable encryption in PHP scripts, we install the php5-mcrypt package by executing the following command in a “root” shell.

apt-get install php5-mcrypt

Memcached

To enable memcached functionality in PHP scripts, we install the php5-memcache package by executing the following command in a “root” shell.

apt-get install php5-memcache

MySQL

To enable MySQL functionality in PHP scripts, we install the php5-mysql package by executing the following command in a “root” shell.

apt-get install php5-mysql

PostScript

To enable PostScript functionality in PHP scripts, we install the php5-ps package by executing the following command in a “root” shell.

apt-get install php5-ps

XML-RPC

To enable XML-RPC functionality in PHP scripts, we install the php5-xmlrpc package by executing the following command in a “root” shell.

apt-get install php5-xmlrpc

XSL parser

To enable the XSL parser functionality in PHP scripts, we install the php5-xsl package by executing the following command in a “root” shell.

apt-get install php5-xsl

PHP Extension and Application Repository

To enable the PHP Extension and Application Repository (PEAR), we install the php-pear package by executing the following command in a “root” shell.

apt-get install php-pear php5-dev
MongoDB

To add the MongoDB extension to the repository, we install the mongo extension by executing the following command in a “root” shell.

pecl install mongo

Once the extension has been compiled and installed, we need to register the extension by executing the following command in a “root” shell.

echo 'extension=mongo.so' > /etc/php5/conf.d/mongo.ini

Enabling SSL support

To enable SSL support for our web server, we execute the following command in a “root” shell.

a2enmod ssl

Once all configuration has been done, we need to restart the web server by executing the following command in a “root” shell.

service apache2 restart

Setting up your own development server in Debian

In this series of articles, we will be setting up a new development environment under Debian 7.5. This will include a base server operating system, GUI Desktop Environment, Network Time Server, DNS server, Mail server, Database server and Web server. We will also be hosting our own Version Control System with integration into a Project Management and Issue and Time Tracking solution. We will also require our own Certificate Authority to request and sign digital certificates to use on our internal network and web server.

Operating System and Desktop Environment

As stated above, we will be making use of Debian 7.5 for our server operating system and either log in remotely to a shell over SSH or directly via a Desktop Environment.

Our Desktop Environment will be LXDE, due to the fact that it is designed to work well with computers on the lower end of the performance spectrum – in my case, I am running my Debian server on a Pentium IV 1.7GHz with 512MB of RAM and 2 drives of 40GB and 160GB each – the latter being used as my data drive and the former to host the operating system. We’ll also be installing Gnome and KDE as well, which are both very common Desktop Environments.

Network Time

For us to be able to broadcast Coordinated Universal Time on our internal network, we will be using NTP.

DNS Server

For us to be able to host domains on our internal network, we will be using Bind.

Mail Server

For us to be able to send and receive email messages on our internal network, we will be using Exim 4 with ClamAV, SpamAssassin and Greylistd enabled.

Data storage

For us to be able to provide data storage for our applications, we will be making use of

  • Relational databases;
  • In-memory object caching; and
  • NoSQL databases.

Relational database

MySQL Server 5.5 will provide our relational database back-end and we will be administering it through a web front-end making use of phpMyAdmin.

Object-caching

Memcached will provide our object-caching back-end and we will be administering it through a web front-end making use of phpMemcachedAdmin.

NoSQL database

MongoDB will provide our NoSQL database back-end and we will be administering it through a web front-end making use of RockMongo.

Web Server

The web front-ends will be hosted on Apache 2.2, with virtual hosts configured for each specific web front-end and SSL certificates securing the communication between the web front-ends and clients.

Java Application Server

Tomcat will provide our Java Application Server functionality.

Zend Framework

Zend Framework 2 is an open source framework for developing web applications and services using PHP 5.3+. Apigility provides the functionality to implement a WebAPI on top of the Zend Framework.

Version Control System

For us to provide our own version control system, we will be using Subversion and Mercurial and also enable access to it over the HTTPS protocol.

Project Management and Issue and Time Tracking

For us to provide our project management solution, we will be using Redmine and configure access to both Subversion and Mercurial as well as enable access to it over the HTTPS protocol.


The articles will be published in the order below and as these become available, I will update the list with the appropriate links.

At the end of this series, we will have a comprehensive development server for internal use. A note on this, we are setting up the server behind an existing firewall making use of the 192.168.100.x range of IP addresses.