如何在服务器上部署和运行zend项目?

时间:2011-04-03 18:43:21

标签: php zend-framework hosting deploying

我有一个关于在服务器上部署Zend项目的问题。在localhost上,我使用虚拟主机将文档根目录设置为public / index.php文件夹。

  • 我应该如何部署它? 我已经在服务器上复制了整个项目但由于我的所有路径都是错误的(因为所有路径都是相对于公共文件夹设置的)所以它不能正常工作。
  • 我该怎么办?是否可以在服务器上设置相对于我的主路径的所有路径?在这种情况下,如何将我的应用程序重定向到任何控制器? 或者我可能只需要在服务器上创建虚拟主机,但我没有权限这样做:/?

我需要一些建议,谢谢


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已加载模块我有mod_rewrite可能已启用。

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

--------编辑04.05.2011 -----

我在服务器上再次部署了项目,并设置了RewriteBase / ~user2 / Project2 / public

现在URL映射正常工作(可能是我第一次部署它时出错,这就是它无法正常工作的原因)。

但我仍然遇到项目问题。当我去Auth控制器时:

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;
    } 

在页面上我只能看到:我不知道这是什么意思,因为我检查重定向在不同的Controller中工作是什么意思,我的项目看到zend库所以我不明白为什么它不在视图中创建表单?

观点:

<?php $this->headTitle('Login'); ?>
<h1>Login</h1>
<?php echo $this->form->setAction($this->url()); ?>

1 个答案:

答案 0 :(得分:2)

只需在服务器上复制项目并将域目录指针设置为公用文件夹。在大多数情况下应该执行此操作。

另一种方法是设置vhost文件并设置文档根目录。如果您希望使用子域可访问zf项目,则需要此项。

但这更像是服务器配置问题。

的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]

我希望你没有更改index.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();
相关问题