A free and open-source book on Zend Framework for beginners


Installing the Hello World Web Application

To get the Hello World application code, we will download the code samples archive bundled with this book from GitHub.

The following shell commands will create directory for downloads and make it current:

mkdir ~/downloads

cd ~/downloads

Download the code samples archive bundled with the book by typing the following:

wget https://github.com/olegkrivtsov/using-zf3-book-samples/archive/master.zip

Unpack the archive with the unzip command and move the files to web server’s document root directory:

unzip master.zip

sudo mv using-zf3-book-samples-master/* /var/www/html

Next, set file and directory permissions to allow Apache read and write access to the Hello World application files:

sudo chmod -R 755 /var/www/html/helloworld

sudo chown -R apache:apache /var/www/html/helloworld

Creating Virtual Host

Now we are almost ready to get our Hello World website live! The last thing we are going to do is configuring an Apache virtual host. To do that, we will edit the httpd.conf file:

sudo mcedit /etc/httpd/conf/httpd.conf

If you scroll the file down to its end, you may encounter the commented text block as follows:

#
# Use name-based virtual hosting.
#
#NameVirtualHost *:80
#
# NOTE: NameVirtualHost cannot be used without a port specifier.
# (e.g. :80) if mod_ssl is being used, due to the nature of the
# SSL protocol.
#
 
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for requests without a known
# server name.
#
#<VirtualHost *:80>
#    ServerAdmin webmaster@dummy-host.example.com
#    DocumentRoot /www/docs/dummy-host.example.com
#    ServerName dummy-host.example.com
#    ErrorLog logs/dummy-host.example.com-error_log
#    CustomLog logs/dummy-host.example.com-access_log common
#</VirtualHost>

To add a virtual host, you’ll have to uncomment this block and add some rules in it. After your changes, this text block will look like below:

#
# Use name-based virtual hosting.
#
NameVirtualHost *:80
#
# NOTE: NameVirtualHost cannot be used without a port specifier.
# (e.g. :80) if mod_ssl is being used, due to the nature of the
# SSL protocol.
#
 
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for requests without a known
# server name.
#
<VirtualHost *:80>
    ServerAdmin yourname@yourserver.com
    DocumentRoot /var/www/html/helloworld/public
    <Directory /var/www/html/helloworld/public>
        DirectoryIndex index.php
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

When ready, press F2 to save changes and F10 to exit from Midnight Commander.

Restart Apache to apply your changes:

sudo service httpd restart

Installing Zend Framework 3 with Composer

Now we will use Composer to install Zend Framework 3 code and initialize autoloader. First, go to the directory where you installed the Hello World web application and type the self-update command to update the Composer:

cd /var/www/html/helloworld

sudo php composer.phar self-update

The expected output of this command is the following:

Updating to version 604a65cc31f3e5d8a2b96802135ac24434e87678.
    Downloading: 100%

Next, type the install command to make Composer to download and install Zend Framework 3 code:

sudo php composer.phar install

The expected output will look like as the following:

Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. Run update to update them.
  - Installing zendframework/zendframework (2.2.4)
    Downloading: 100%
 
    Skipped installation of bin/classmap_generator.php for package zendframework/zendframework: name conflicts with an existing file
    Skipped installation of bin/pluginmap_generator.php for package zendframework/zendframework: name conflicts with an existing file
    Skipped installation of bin/templatemap_generator.php for package zendframework/zendframework: name conflicts with an existing file
zendframework/zendframework suggests installing doctrine/annotations (Doctrine Annotations >=1.0 for annotation features)
zendframework/zendframework suggests installing ext-intl (ext/intl for i18n features (included in default builds of PHP))
zendframework/zendframework suggests installing ircmaxell/random-lib (Fallback random byte generator for Zend\Math\Rand if OpenSSL/Mcrypt extensions are unavailable)
zendframework/zendframework suggests installing ocramius/proxy-manager (ProxyManager to handle lazy initialization of services)
zendframework/zendframework suggests installing zendframework/zendpdf (ZendPdf for creating PDF representations of barcodes)
zendframework/zendframework suggests installing zendframework/zendservice-recaptcha (ZendService\ReCaptcha for rendering ReCaptchas in Zend\Captcha and/or Zend\Form)
Generating autoload files

Top