A free and open-source book on ZF3 for beginners


Установка веб-приложения Hello World

Теперь скачаем с GitHub архив с примерами приложений, который идет вместе с этой книгой.

Следующие команды оболочки создадут каталог для загрузок и сделают его текущим:

mkdir ~/downloads

cd ~/downloads

Скачайте идущий в комплекте с этой книгой архив примеров кода, набрав следующее:

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

Распакуйте архив командой unzip и переместите файлы в корневой каталог документов веб-сервера.

unzip master.zip

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

Затем задайте права доступа к каталогу, чтобы разрешить Apache доступ к файлам приложения Hello World на чтение и запись^

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

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

Создание виртуального хоста

Теперь мы почти готовы к выпуску нашего сайта! Последнее, что мы сделаем - настроим виртуальный хост Apache. Для этого изменим файл httpd.conf:

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

Если вы пролистаете этот файл вниз, вы можете обнаружить следующий закомментированный блок:

#
# 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>

Чтобы добавить виртуальный хост, нужно раскомментировать этот блок и добавить в него некоторые правила. После ваших изменений он будет выглядеть таким образом:

#
# 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>

Когда будете готовы, нажмите F2, чтобы сохранить изменения, и затем F10, чтобы выйти из Midnight Commander.

Перезапустите Apache, чтобы применить изменения:

sudo service httpd restart

Установка Zend Framework 3 с помощью Composer

Теперь мы используем Composer, чтобы установить код Zend Framework 3 и инициализировать автозагрузчик. Сперва перейдите в каталог, куда вы установили веб-приложение Hello World и введите команду самообновления, чтобы обновить Composer:

cd /var/www/html/helloworld

sudo php composer.phar self-update

После выполнения этой команды вы должны будете увидеть следующие строки:

Updating to version 604a65cc31f3e5d8a2b96802135ac24434e87678.
    Downloading: 100%

Затем введите команду install, чтобы Composer скачал и установил код Zend Framework 3:

sudo php composer.phar install

После ее выполнения вы увидите следующий текст:

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