I'm not able to set up include paths for ZF library correctly on Bluehost server.
Here's the directory structure:
/root_directory
.htaccess
__/Zend
__Application(from ZF)
__library(from ZF)
__/public_html
__/public(the ZF public folder)
I removed the .htaccess from public folder and placed it in the root_directory.
contents of .htaccess:
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]
Contents of index.php in public folder:
// Define path to application directory
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
// Define application environment
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library'),
get_include_path(),
)));
/** Zend_Application */
require_once 'Zend/Application.php';
// Create application, bootstrap, and run
$application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);
$FrontController = Zend_Controller_Front::getInstance();
$Router=$FrontController->getRouter();
Zend_Layout::startMvc(array(
"layout" => "layout",
"layoutPath" => "layouts/scripts"
));
$plugin=new Zend_Controller_Plugin_ErrorHandler();
$plugin->setErrorHandler(array("controller" =>'ApplicationError',
"action"=>'index'));
$FrontController->registerPlugin($plugin);
$application->bootstrap()
->run();
Kindly help me deploying my project on server. If there is anything else I need to mention please let me know.
See if doing the following gets you up and running:
Move contents of public_html/public into public_html and delete the public folder
Delete root_directory/.htaccess
Create public_html/.htaccess
In public_html/.htaccess, put:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
Your index.php file looks fine, no need to change APPLICATION_PATH.
Basically, the only change is that instead of actually using the public folder that came with Zend Framework, you replace it with public_html instead since that is really your public folder.
Related
Hi i have a Zend installation in main domain.
Now i want to make a subfolder and run Zend for some testing purposes. I have copied all files from main site to subfolder named www2. But when i call the subfolder like domain.com/www2 i think the main Zend instance get invoked and produces a Message: Invalid controller specified (www2) error?
my .htaccess of main Zend is
SetEnv APPLICATION_ENV development
RewriteEngine on
RewriteCond %{REQUEST_URI} "/www2/"
RewriteRule (.*) $1 [L]
and Subfolder is like
SetEnv APPLICATION_ENV development
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
What i am doing Wrong. I have full access to server.
in subfolder Zend in file application/Bootstrap.php add LIKE this:
protected function _initRoutes()
{
$this->bootstrap('frontcontroller');
/**
* #var Zend_Controller_Front $front
*/
$front = $this->getResource('frontcontroller');
/**
* #var Zend_Controller_Router_Rewrite $router
*/
$router = $front->getRouter();
$router->addRoute('www2',
new Zend_Controller_Router_Route(
'www2/:controller/:action',
array('controller' => 'index',
'action' => 'index'))
);
}
But may be you need another route...
UPD1:
first .htaccess like this:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/www2*
RewriteRule ^.*$ www2/index.php [NC,L]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
You could create a subdomain www2.domain.com pointing the www2/public directory and restore all .htaccess files to their normal single-site state.
This way, the www2 copy is completely standalone app with the same url and file structure as the original www site.
I extend Zend_Controller_Router_Route_Abstract in Zend Framework to add custom routing to my application. My match method return false in cases it identify that the request path isn't ones of the paths it must process. So with paths, like statics resources paths, my custom routing class return false and the default Module router take care of.
My problem is that all work fine as far I have the document root of my site pointing to my public directory. When I change the document root to the directory in witch public folder is (parent directory), the following error appear when try to request an static resource like http://mysite.com/css/global.css:
An error occurred Page not found Exception information:
Message: Invalid controller specified (css) Stack trace:
Stack trace: ....
Request Parameters:
array ( 'controller' => 'css', 'action' => 'global.css', 'module' => 'default', )
That is just part of the message, the other part is irrelevant.
My questions is, how can I solve this problem? How can I have my custom routing logic and serving static content while having the document root in the parent of the public directory?
Here the .htaccess I uses when document root isn't pointing inside public dir:
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]
You should not server static files from PHP. It means you should use:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
I have a sub domain to which i have deployed my zend application, the problem is it points to the directory say abc and i cannot get it changed to point it to public directory is there a way i can put a .htaccess file on the root which will redirect to the public directory? can it be done? is there another way i can get it done
my index.php inside public dir
<?php
// Define path to application directory
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
// Define application environment
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library'),
get_include_path(),
)));
/** Zend_Application */
require_once 'Zend/Application.php';
// Create application, bootstrap, and run
$application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);
$application->bootstrap()
->run();
my .htaccess inside public dir
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
currently the directory structure looks like
/myroot
-.settings
-application
-docs
-library
-public
-tests
-.buildpath
-.proect
-.zfproject.xml
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]
no errors and no problems..
I hope I get your domain setup correctly. If you have this setup
sub.domain.net --> /myroot
you will need an .htaccess in that (/myroot) folder because it is the base of your http requests. It should look like this
RewriteEngine On
RewriteBase /public
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ public/index.php [NC,L]
The RewriteBase directive should find all request in the RewriteCond and applies mainly to the first RewriteRule. It basically sets (rewrites) the relative root for all HTTP path request. The second RewriteRule finally triggers your application which is a local path. (I hope I am not wrong about this last rule. If that doesn't work try without the public. I can't test it but I had got an app to work like this a few years back.)
I'm banging over the wall with this...
I need to establish a zend framework application inside a subdirectory.
i.e. the domain is tricell.ss and I want to use tricell.ss/tricell as application main directory.
Whate've done:
I've setted up in my config (application.ini) the:
resources.frontController.baseUrl = "/tricell"
I've made another var in my config
baseUrl = "/tricell"
In my Boostrap I've got this:
$router = new Zend_Controller_Router_Rewrite();
$frontController->setRouter($router);
$frontController->setBaseUrl($this->config->baseUrl);
$frontController->dispatch();
In my layout I'm trying to display image with using:
$this->baseUrl('/img/btn.png')
Here are my vhost configuration:
<VirtualHost *:80>
DocumentRoot "/HTDOCS/tricell/tricell/public_html"
ServerName tricell.ss
RewriteRule ^$ [L]
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?tricell.ss$
RewriteRule ^(/)?$ tricell [L]
</VirtualHost>
here is my .htaccess:
SetEnv APPLICATION_ENV development
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
The problem is when I'm trying to display image nothing happens. When I'm trying to get the image by URL:
http://tricell.ss//tricell/img/btn.png
I'm getting info about wrong controller. How I can make this right? I can (without any problems) make configuration for root domain like tricell.ss and then get image i.e. tricell/ss/img/btn.png, but I want to work on subdirectory, and I can't do that with images. What I am doing wrong here?
I think the easiest thing you can do to get this working is this:
Start with a fresh ZF project, or remove all of your zend routes, and any special configuration in .htaccess or httpd.conf/httpd-vhosts.conf that you created.
Get rid of the baseUrl options you set up in your config file.
Place the index.php file and the .htaccess file in your /HTDOCS/tricell/tricell/public_html/tricell folder.
Place the rest of your project (controllers, models, config etc) outside of your web root. In this example I will assume they are placed in /HTDOCS/tricell/tricell/zfproject.
Edit index.php and change:
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
// to:
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../../zfproject/application'));
Now your application will run with the base directory being yoursite.com/tricell
IndexController.php's URL is going to be http://yoursite.com/tricell/index
You do not need to do anything special to tell Zend your base URL is "tricell". Just make sure in your view scripts to use $this->baseUrl() for your paths so you don't need to worry about manually adding /tricell to the beginning of everything, and if you ever move your project to another directory/path, nothing needs to be changed to deal with the new paths.
I've just manage to resolve my issue... it's quite simple but I was very confused by all this rewriting rules.
As saying always tricell is confusing let's make some changes to that as well.
So to achive something like tricell.ss/sub I would need to:
Put my whole application inside /HTDOCS/tricell/tricell/sub
Change my vhost from this line: DocumentRoot "/HTDOCS/tricell/tricell/public_html" to: DocumentRoot "/HTDOCS/tricell/tricell/"
Insert yet another .htaccess in my /HTDOCS/tricell/tricell/sub directory:
RewriteEngine On
RewriteRule ^.htaccess$ - [F]
RewriteCond %{REQUEST_URI} =""
RewriteRule ^.*$ /sub/ublic_html/index.php [NC,L]
RewriteCond %{REQUEST_URI} !^/sub/public_html/.$
RewriteRule ^(.)$ /sub/public_html/$1
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.*$ - [NC,L]
RewriteRule ^public_html/.*$ /sub/public_html/index.php [NC,L]
This resolved my all issues.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} "/tour/"
RewriteRule (.*) /tour/index.php [L,END]
</IfModule>
The above code in the root folder domain.com/.htaccess worked for me. I placed it directly as the first thing in the htaccess before the "# BEGIN WordPress" parts.
having a Zend installation in the domain.com/tour/ subdirectory
wordpress running on the root domain.com/ level
The final knack was to have the RewriteRule point to the index.php of Zend if Request_URI matches /tour/
i am having trouble deploying my zend framework application to mediatemple GS hosting.
I uploaded my application folder to ~/domains and renamed it to mysite.net folder.
Inside it, i created a symbolic link html which points to public directory in zend framework application folder. But the application is not working so far. Generally, mediatemple points a host to ~/domains/host/html path so my domain mysite.net should point to ~/domains/mysite.net/html.
Am i doing something wrong or is there more to this ? I am getting a 403 error when trying to access mysite.net
Update: Following rewrite rules make the base url http://mysite.net loadable but controllers dont work now. accessing http://mysite.net/controller sends page not found error :S
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]
Update: Its solved now. The trick is to add above .htaccess file to the application root folder and also keep the original .htaccess in public directory. Together they do wonders.
I've found the solution myself:
create a .htaccess file in application root folder:
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]
Also keep the original .htaccess in the /public folder. I delete this at first which made things worse.