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

Php 如何在服务器上部署和运行zend项目?,php,zend-framework,hosting,deploying,Php,Zend Framework,Hosting,Deploying,我有一个关于在服务器上部署Zend project的问题。在localhost上,我使用virtualhost将文档根目录设置为public/index.php文件夹 我现在应该如何部署它? 我已将整个项目复制到服务器上,但它无法工作,因为我的所有路径都错误(因为所有路径都是相对于公用文件夹设置的) 我该怎么办?是否可以设置相对于服务器上“我的主页”路径的所有“我的路径”?在这种情况下,如何将应用程序重定向到任何控制器? 或者我只需要在服务器上创建虚拟主机,但我没有这样做的权限:/ 我需要一

我有一个关于在服务器上部署Zend project的问题。在localhost上,我使用virtualhost将文档根目录设置为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();

phpinfo()

w加载的模块我有mod_rewrite,因此可能已启用

----------------------------- --------2011年5月4日编辑-----

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

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

但我对这个项目仍然有问题。当我转到身份验证控制器时:

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;
    } 
在页面上,我只能看到:ï»?我不知道这意味着什么,因为我检查了不同控制器中的重定向是否正常工作,这意味着我的项目可以看到zend库,因此我无法理解它为什么不在视图中创建表单

观点:

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

登录

只需在服务器上复制您的项目,并将域目录指针设置为公用文件夹。在大多数情况下,这应该可以完成这项工作

另一种方法是设置文件并设置文档根。如果希望通过子域访问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();

旁注:研究像ApacheAnt这样的系统来自动化您的构建和部署过程。您是否将Zend库复制到项目的目录中?但是域目录指针的配置在哪里?我应该更改.htaccess文件吗?但是怎么做呢?my index.php的As目录是[http://]domain.uk/~user2/Project2/public/index.php如何设置指向此目录的域目录指针?如果我设置它,它将像项目2的文档根一样工作?如果您没有对服务器的配置访问权限,那么您的项目将很难运行。您有什么错误消息?我没有任何错误,我对目录有问题,因为所有目录都是相对于[http://]domain.uk/~user2/Project2/public/index.php设置的,并且由于现在所有链接都错误,因此无法正常工作。我不知道如何将项目的目录根设置为:[http://]localhost上的domain.uk/~user2/Project2/public folder我有这个文件夹的虚拟主机,我的zend项目正在工作,但是当我将它部署到服务器上时,我的所有目录都有问题:/所以我在单击任何链接时始终没有找到页面错误,甚至我的CSS也有错误的目录:/我甚至无法转到任何控制器,当我尝试像这样做:[http://]domain.uk/~user2/Project2/application/conrollername/index.php看起来文件只存储在服务器上,但zend框架不起作用我不知道该怎么办-对我来说,只有一种解决方案可以在服务器上为这个项目创建虚拟主机,因为它不起作用,我想:/我有一个问题:zend有可能吗没有虚拟主机的本地主机上的项目工作?
// 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();