5

I have a question about deploying Zend project on a server. On localhost I used virtual host to set the document root to the public/index.php folder.

  • How should I deploy it now? I have copied whole my project on the server but it is not working as all my paths are wrong (as all are set up relative to the public folder).
  • What should I do? Is is possible to set all my paths relative to the my home path on the server? How can I redirect my application to any controller in this situation? Or maybe I just need to create virtual host on the server but I do not have permission to do it:/?

I need some advices, thank you


Application.ini :

[production]
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "Application"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 0
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"


resources.view[] =

resources.db.isDefaultTableAdapter = true
resources.db.adapter = PDO_MYSQL
resources.db.params.charset = "utf8"
resources.db.params.host = HOST
resources.db.params.username = "p"
resources.db.params.password = "***"
resources.db.params.dbname = "p"

[staging : production]

[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1

[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1

Index.php:

<?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'));

defined('DESTINATION_IMAGES') || define('DESTINATION_IMAGES', './usersImages/');
defined('TRUE_STORY_EMAIL') || define('TRUE_STORY_EMAIL', 'mmm@gmail.com');
defined('TRUE_STORY_NAME') || define('TRUE_STORY_NAME', 'True story team');

// 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();

.htaccss:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

phpinfo();

w Loaded Modules I have mod_rewrite so probably is enabled.

-----------------------------

--------EDIT 04.05.2011 -----

I have deployed the project once again on the server and I have set RewriteBase /~user2/Project2/public

And now the URL mapping is working (probably the first time was an error when I deployed it that is why it was not working).

But I still have problems with the project. When I go to the Auth controller :

public function indexAction() {
        // action body

        $form = new Application_Form_Login();
        $request = $this->getRequest();
        if ($request->isPost()) {
            if ($form->isValid($request->getPost())) {
                try {
                    if ($this->_process($form->getValues())) {
                        $userDT = new Application_Model_DbTable_User();
                        $idUser = Zend_Auth::getInstance()->getIdentity()->id;
                        if ($userDT->isConfirmed($idUser)) {
                            $this->_helper->redirector->gotoRoute(
                                    array(
                                        'controller' => 'index',
                                        'action' => 'index'
                                    )
                            );
                        } else {
                            $form->setDescription('Your account is not confirmed!');
                            Zend_Auth::getInstance()->clearIdentity();
                            $this->_helper->redirector->gotoRoute(
                                    array(
                                        'controller' => 'Registration',
                                        'action' => "step",
                                        'idUser' => $idUser
                                    )
                            );
                        }
                    } else {
                        $form->setDescription('There was an error. Try to log in once again please');
                    }
                } catch (Exception $e) {
                    echo $e->getMessage();
                }
            }
        }
        $this->view->form = $form;
    } 

On the page I can see only :  and I do not know what it means as I check that redirecting in different Controller is working what mean that my project see the zend libraries so I can not understand why it does not create the form in the view ?

The view:

<?php $this->headTitle('Login'); ?>
<h1>Login</h1>
<?php echo $this->form->setAction($this->url()); ?>
canimbenim
  • 659
  • 4
  • 10
  • 23

1 Answers1

2

Simply copy your project on your server and set the domain directory pointer to the public folder. In most cases that should do the job.

Another approach is to setup a vhost file and set the document root. You need this if you want a zf project to be accessible with a subdomain.

But this is more a server configuration question.

Application.ini:

[production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "Application"
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.modules = ''

resources.frontController.params.displayExceptions = 1
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"
resources.frontController.defaultControllerName = "home"
resources.frontController.params.prefixDefaultModule = "1"

//some db setup

[staging : production]

[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1

[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1

.htaccess:

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 hope you didn't change the index.php file because you shouldn't:

// 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();
DarkLeafyGreen
  • 69,338
  • 131
  • 383
  • 601
  • But where is the configuration of the domain directory pointer? Should I change my .htaccess file? But how to do it? As directory to my index.php is [http://] domain.uk/~user2/Project2/public/index.php How to set the domain directory pointer to this directory? If I will set it it will work like document root for the project2? – canimbenim Apr 04 '11 at 10:24
  • If you do not have configuration access to the server it will Be hard to get your project running. What Error message do you have? – DarkLeafyGreen Apr 04 '11 at 11:47
  • I do not have any error, I have problem with directories as all are set relatively to the [http://] domain.uk/~user2/Project2/public/index.php and it is not working as all links are wrong now. I do not know how can I set the directory root for my project to this: [http://] domain.uk/~user2/Project2/public folder On localhost I have virtual host to this folder and my zend project working but when I deployed it on the server I have problems with all directories :/ so I all the time have page not found error when I click any link and even my CSS has wrong directory :/ – canimbenim Apr 04 '11 at 15:39
  • I can not even go to any controller when I try to do it like: [http://] domain.uk/~user2/Project2/application/conrollername/index.php It looks like the files are only stored on the server but the zend framework is not working I have no idea what to do - for me is only one solution to create virtual host on the server for this project as it will not work I think:/ – canimbenim Apr 04 '11 at 15:44
  • I have a question: is any possibility to the zend project work on localhost without virtual host? – canimbenim Apr 04 '11 at 15:59
  • Don't you get a 404 error? It is possible that you haven't modrewrite activated on server, call phpinfo() and have a look if modrewrite is enabled. It is hard to resolve you problem because it is not obviouse if it is a wrong application or server setup. I edit my post with my application.ini setup – DarkLeafyGreen Apr 04 '11 at 18:28
  • When I go directly to the ../public/index.php I do not have 404 error but when I click for example login link which in helper looks like this:$loginUrl = $this->view->url(array('controller' => 'Auth', 'action' => 'index')); return "Login"; The path on the server looks like: ..../Project2/public/Auth it looks like url mapping is not working :/ – canimbenim Apr 04 '11 at 20:42
  • You were right it should work, I have created my own server and deployed there my project and now it is working. It was enough to set RewriteBase to my public folder, thanks – canimbenim Apr 06 '11 at 22:05