Plesk 12 comes with a range of pre-built installation wizards for a number of the most popular PHP CMS' on the market, such as Wordpress, Drupal and Joomla, but not for the frameworks, such as Zend Framework 2, Phalcon and Symfony.
So in today's tutorial, we're going to guide you through the process of setting up and deploying a basic Zend Framework 2 application, based on the ZF2 Skeleton Application, on Plesk 12.
Ok, so you have your hosting setup and you're ready to get to work. But you're not planning to use one of the pre-built installers which take care of just about all of the work for you. You're planning to deploy an application using Zend Framework 2.
The question is, how do you do it? Well, at the moment, there's no pre-built installers outside of these, so you need to install it by hand. But not to worry, this guide's here to guide you through the process, so that you'll be up and running in no time; right from creation of the sub-domain, through to viewing the running application.
By the time we're done, you'll see the site as in the screenshot below:
Thanks to the modern UI, and intelligent layout available in Plesk 12, it's a real no brainer, requiring only a few steps to have it live, which are as follows:
- Create a Sub-Domain
- Setup SSH Access
- Install the Code
- View The Application
Let's work through the process now.
1. Create a Sub-Domain
Ok, when you first login to your account, click the first tab: Websites & Domains. This will then show you the list of your websites & domains as in the screenshot below:
In our example, we have one existing. To keep this simple, we're going to create a new sub-domain to keep the example simple. In the top set of buttons, you'll see three, Add New Domain, Add New Subdomain, and Add New Domain Alias. Click Add New Subdomain which will allow you to enter the details of the new subdomain, as in the image below:
I've kept it simple and just added zf2 in Subdomain name. Clicking OK, this returns us to the Websites & Domains page, after auto generating a new subdomain of zf2.a93-91-167-253.ec.parallels-summit.com and a default site from the standard template.
In the screenshot above, you can see that it's inherited the rest of the configuration options from the primary domain. We can view the website's files by first clicking Show More, then clicking File Manager. This view will also give you the ability to quickly edit files if required also.
Adjust The Sub-Domain's Document Root
Zend Framework 2, like a host of the other PHP frameworks, uses a directory called public within the project source as the document root. However, the default sub-domain configuration serves files out of the root directory. We need to change this.
Next to the sub-domain's name, you'll see a link called Hosting Settings. Clicking this shows you the sub-domain's settings. Change the fourth option, document root, adding /public to the end of the string then click OK at the bottom.
2. Setup SSH Access
Right, that's the core of the work all done for us. Now we need to check that SSH access is setup properly, so that we can login and run a few command line scripts. If you're not too familiar with command line scripts, that's ok. The one's I've listed here are quite simple and have sufficient documentation, should it be needed.
Next to the sub-domain's name, you'll see a link called Web Hosting Access. Clicking this shows you the settings where you'll see the current system user and if and how they can access to the server over SSH, as in the screenshot below. Make sure that Shell is set to Bash, then click OK.
The reason for this is because these scripts need that environment to run in. Sh may work, but Bash works best for this example. Now you're ready to login and begin installing the application.
3. Install the Code
For this example, I'll assume that the username is parallels and the IP address is: 220.127.116.11, just to keep things simple. Ok, now open up a Terminal window (if you're on Mac OS X or Linux) or Putty if you're using Windows and ssh to your server with the following command:
From there, change to the sub-domain directory, with:
There, you'll see the files as in your File Manager previously. We need to move these out of the way so that we only have the ZF2 files here. So run the following command, which will create a new directory to archive the existing files, then move them there.
mkdir website_archive && mv ./* website_archive;
Right, now we need to install Composer, which will help us automate the rest of the commands.
But What Is Composer?
If you're not familiar with Composer, it's a dependency manager for PHP. In years gone by, many projects implemented common functionality, such as routing, database layers, caching interaction and logging, making it difficult to port applications to newer or different frameworks, or for them to be maintained.
Composer makes it almost painless for best of breed libraries for any specific purpose to be created, voted on, discovered and used in applications. To find out more about it, I encourage you to read this introduction to it or a walk through of [the Composer Cheatsheet I made for Sitepoint}(http://www.sitepoint.com/composer-cheatsheet/). You'll be up and running with it in no time.
Right, to install composer, run the following command:
curl -s https://getcomposer.org/installer | php --
This downloads Composer file, piping it through to PHP, in the process creating a self-contained file we can use. Now we need to install the code from the ZF2 Application Skeleton's source. To do that, run the following command:
php composer.phar create-project \ -sdev --repository-url="https://packages.zendframework.com" zendframework/skeleton-application zf2app
The command's been formatted for readability. But what it does is to automatically checkout the source code into a new directory called zf2app. It'll take a little while to run, depending on the capacity of your server, with the output looking a bit like that below.
Installing zendframework/skeleton-application (dev-master 67cbbbf61897831ef1feda323be9845aa7d79682) - Installing zendframework/skeleton-application (dev-master master) Cloning master Created project in zf2app Loading composer repositories with package information Installing dependencies (including require-dev) - Installing zendframework/zendxml (1.0.0) Downloading: 100% - Installing zendframework/zendframework (2.3.1) Downloading: 100% zendframework/zendframework suggests installing ext-intl (ext/intl for i18n features (included in default builds of PHP)) zendframework/zendframework suggests installing doctrine/annotations (Doctrine Annotations >=1.0 for annotation features) 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 0.5.* 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) Writing lock file Generating autoload files Do you want to remove the existing VCS (.git, .svn..) history? [Y,n]? Y
4. View The Application
Right, now that it's installed, let's have a look at the running app. It's not special, as there's no database, logging, or caching server connections. It's just a one page application, but it works.
So there you go. In just a few minutes, we've stepped through creating and configuring a sub-domain, to installing a sample application, based on the ZF2 Skeleton Application.
Now it'd be great if it was simpler, such as having an installer for Drupal, Joomla and Wordpress. But it's a bit hard to compare off the shelf applications, such as these, to frameworks which allow for creating nearly any kind of application.
What I'm hoping for is to have an installer which lays the foundation for this process, which may just be available in the future.
Till then, share your thoughts in the comments. Has this made it simpler for you to start creating applications with Zend Framework 2 on Plesk? I hope so. I'd love to hear how you feel.