As many people I started to learn PHP on computer which was running on Windows operating system. There is a lot of things to do before I could wrote my first PHP 'Hello world!' script (install web server, PHP, database server). Actually we don't need database for 'Hello world!' script but later we will for sure. So I found out that it is complicated to start write, test and run PHP application on my computer. Unfortunately there is several solutions which allows us to install complete stack which includes Apache web server, PHP, database (MySQL or PostgreSQL) and also PEAR and others (try to visit: XAMPP, WAMP).
This is what I did as well but later I realized that if you install whole stack at once you are loosing priciples of how is web server and database server running. And later when I wanted to upgrade only some part of it or when I was trying to include or use in application something what wasn't part of pre-installed stack I had problems or even got stuck (for example incorporate Smarty template engine).
This article is about one such a situation. I decided to start learn and use Zend framework and because I didn't want to mix my already created projects on localhost I needed create virtual host, then download and incorporate Zend framework application.
As I mentioned earlier in this article I will assume that we are running on Windows operating system and we have installed XAMPP package.
First thing what we need to do is to download Zend framework aplication. I downloaded Zend Framework 1.11.11 Full version and extracted the contents. Don't forget to make note where you extracted the contents of the package.
Then I coppied contents of /bin subdirectory containing the scripts "zf.php" and "zf.bat" into C:\Program Files\xampp\php\ directory where I have my XAMP package installation. I also coppied contents of /library subdirectory containing folder Zend into C:\Program Files\xampp\php\PEAR\ directory. I found that I already have Zend folder there so I overwrote it with newest version.
Then I needed to create virtual host. So I went to C:\Program Files\xampp\apache\conf\ directory where is configuration file of my Apache web server (httpd.conf) and at the end of the file I added this:
<VirtualHost *:80> ServerName zend.local DocumentRoot "E:/work/zend" SetEnv APPLICATION_ENV "development" <Directory E:/work/zend> DirectoryIndex index.php AllowOverride All #None !!! will make impossible to use .htaccess file Order allow,deny Allow from all </Directory> </VirtualHost>Folder E:/work/zend is document root of my localhost web server. To test if everything works I created and saved in this folder file index.php with this content:
<?php echo 'Virtual host works!'; ?>Then I launched web browser and typed into URL bar: http://zend.local/ to make sure that virtual host was created and is running correctly.
We also need to make sure that PHP folder of our installation is between system variables. Go to the My Computer folder and "right-click" mouse, choose "Properties" and you should see window "System properties". Go to the tab "Advanced" and there is button "Environment variables". In opened window find system variable "Path" and click "Edit". In variable's value there is list of paths. If there is no path into PHP folder of your XAMPP installation, just add it. I have there something like this: C:\Program Files\xampp\php. This path was propably created automatically during the installation of XAMPP package. But I don't remember honestly.
Next very important step is to add an entry in your hosts file corresponding to the value you place in your ServerName directive ("zend.local" in my case). On Windows, you'll typically find it in C:\WINDOWS\system32\drivers\etc. Open file "hosts" and add something like the following:
Then it is necessary start or restart your web server, to changes take effect.
And now last step is to create project itself. Now we will use beautifull script "zf.bat" which we have coppied earlier. Open a terminal (in Windows, Start -> Run, and then use cmd). Navigate to a directory where you would like to start a project. In my case let's say C:\Program Files\xampp\php\zend_project and write:
zf create project .
For better ilustration look at the following picture:
Running this command will create your basic site structure, including your initial controllers and views. Copy this basic site structure into "zend.local" virtual host (in my case E:/work/zend) and type into URL bar of your web browser: http://zend.local/public and you should see image like this:
So this is pretty much it. We have created virtual localhost, incorporated Zend framework into PEAR of our XAMPP installation and started our first zend project. For more information visit Zend framework quickstart