Archive

Archive for the ‘Programming’ Category

Zend Framework – All project’s files on DOCUMENT_ROOT

March 12th, 2010 Tommy No comments

You often have to publish the sites where, on the server, you have write access on the main public directory only, the DOCUMENT_ROOT of the site. This is always (or almost) on shared server. How to solve this problem?

Our goal is to have the same structure of a default Zend Framework in the DOCUMENT_ROOT folder, but allowing the user access only to the public folder. To do this we must create an .htaccess file in the DOCUMENT_ROOT, telling Apache to redirect all requests to the index.php file we have in the public directory.

The contents of the .htaccess file on DOCUMENT_ROOT, which we will use as default .htaccess (the same that you should put on the public folder, which you’ll can delete), will be the following::

SetEnv APPLICATION_ENV development

RewriteEngine On
RewriteRule ^\.htaccess$ - [F]
RewriteCond %{REQUEST_URI} =""
RewriteRule ^.*$ /public/index.php [NC,L]
RewriteCond %{REQUEST_URI} !^/public/.*$
RewriteRule ^(.*)$ /public/$1
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.*$ - [NC,L]
RewriteRule ^public/.*$ /public/index.php [NC,L]

The first line, as you should know, is to define the type of use (then, the different configurations) of the project.
The other set Apache’s mod_rewrite rules for redirect requests on public folder.

Categories: News, Zend Framework Tags:

Zend Framework and Zend Tool

June 23rd, 2009 Tommy No comments

Ok, this is my first tutorial in english, then sorry if my english is not more good :)

Few months ago, I started to know the Zend Framework (aka ZF), a library of PHP classes and components created by Zend. Despite its complexity, relactive to others frameworks, I chose this for several aspects, but mainly because I think it is the only one framework that has a future; Zend is the PHP’s company and is not possible that Zend will close the project.

At the time of writing, the last release is 1.8.3. With 1.8 have been introduced changes especially in the initial part of the creation of a project, and a very usefuf tool was integrated (Zend_Tool), wich allows us to initialize the project via shell. I tried it and it’s very useful!

Now we will see how to use Zend Tool. I use a test environment using a distribution of Debian in one of our web server, but can also be used on Windows and Mac.

Configuring PHP and Zend Framework

First, we must download the Zend Framework from http://framework.zend.com/download/latest, then:

[code lang="plain"]dev:~# wget http://framework.zend.com/releases/ZendFramework-1.8.3/ZendFramework-1.8.3.tar.gz
dev:~# tar zxvf ZendFramework-1.8.3.tar.gz
dev:~# cd ZendFramework-1.8.3[/code]

(change the version number with the actual or your version)

I decide to move the “ZendFramework” directory in /var/www, that isn’t the documentroot of Apache, because I have configured the Virtual Hosts. You can decide where move or copy the directory.
PHP allows you to set the “includes” directory, ie each time that a script uses the command include or require, PHP checks the directory of current script in the directories set with the include_path directive.

Then configure the php.ini in /etc/php5/cli and /etc/php5/apache2 (the first is the configuration that typically uses the shell, the second is that it uses the PHP used as a module in Apache 2):

[code lang="plain"]dev:~# nano /etc/php5/cli/php.ini
<pre>dev:~# nano /etc/php5/apache2/php.ini[/code]

and we have the following directives: safe_mode_include_dir and include_path including the path of the ZendFramework library:

[code lang="plain"]safe_mode_include_dir = &quot;.:/var/www/ZendFramework/library&quot;
include_path = &quot;.:/var/www/ZendFramework/library&quot;[/code]

Well, the ZendFramework is installed in our server, now we’ll install Zend Tool.

Installing Zend_Tool

Now, we must confoguring Zend Tool, so:

[code lang="plain"]dev:~# chmod 770 /var/www/ZendFramework/bin/zf.sh
dev:~# ln -s /var/www/ZendFramework/bin/zf.sh /bin/zf
dev:~# zf show version
Zend Framework Version: 1.8.3[/code]

Now everything should be ok! If you did everything right you should see something similar to the above. Now type:

[code lang="plain"]dev:~# zf ?[/code]

You should see a little guide with the available commands.

Next time I will explain how to create a basic project.