Php 如何在Heroku上正确部署我的网站?
我一直在尝试在Heroku上部署我的网站,这是我用PHP实现的it的模型视图控制器。我不知道发生了什么,但当我尝试访问主页(或索引)时,这非常有效,当我尝试访问mi网站上的其他页面时,会出现如下情况:Php 如何在Heroku上正确部署我的网站?,php,apache,heroku,model-view-controller,deployment,Php,Apache,Heroku,Model View Controller,Deployment,我一直在尝试在Heroku上部署我的网站,这是我用PHP实现的it的模型视图控制器。我不知道发生了什么,但当我尝试访问主页(或索引)时,这非常有效,当我尝试访问mi网站上的其他页面时,会出现如下情况: ServerName www.my-sample-mvc.com DocumentRoot "/path/to/my/sample/mvc/public" <Directory "/path/to/my/sample/mvc/public">
ServerName www.my-sample-mvc.com
DocumentRoot "/path/to/my/sample/mvc/public"
<Directory "/path/to/my/sample/mvc/public">
Require all granted
# When Options is set to "off", then the RewriteRule directive is forbidden!
Options FollowSymLinks
# Activate rewriting engine.
RewriteEngine On
# Allow pin-pointing to index.php using RewriteRule.
RewriteBase /
# Rewrite url only if no physical folder name is given in url.
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite url only if no physical file name is given in url.
RewriteCond %{REQUEST_FILENAME} !-f
# Parse the request through index.php.
RewriteRule ^(.*)$ index.php [QSA,L]
</Directory>
我知道发生这种情况的一个原因,下一个原因是我在路由器中使用了:
$currentURL = $_SERVER['PATH_INFO'] ?? '/';
//var_dump($_SERVER);
$method = $_SERVER['REQUEST_METHOD'];
if($method === 'GET'){
$fn = $this->routesGET[$currentURL] ?? null;
} else{
$fn = $this->routesPOST[$currentURL] ?? null;
}
所以,我在我的网站上显示了PHP$\u服务器的全局变量,我注意到$\u服务器['PATH\u INFO']
没有出现在它上面。所以,我猜问题来自Apache的配置,因为我使用Apache2和PHP来解决这个问题。所以,我不知道如何配置,因为这是我第一次这样做,如果你能帮助我,我真的很感谢你
这是我的目录:
最后是我的程序文件:
web: vendor/bin/heroku-php-apache2 public/
这些是配置基于MVC的web应用程序的一般适用步骤。以下设置的假定web服务器版本: 1)阻止对所有目录和文件的访问: 首先,在Apache的配置文件中,默认情况下应该阻止对所有目录和文件的访问:
# Do not allow access to the root filesystem.
<Directory />
Options FollowSymLinks
AllowOverride None
Require all denied
</Directory>
# Prevent .htaccess and .htpasswd files from being viewed by Web clients.
<FilesMatch "^\.ht">
Require all denied
</FilesMatch>
我的建议:出于安全考虑,此位置应仅包含一个index.php
和一个index.html
文件,每个文件都显示一条简单的“Hello”消息。所有web项目都应该在其他目录中创建,并且应该单独设置对它们的访问权限,如下所述
3)设置对单独项目目录的访问权限:
假设您在另一个位置(如目录/path/to/my/sample/mvc/
)创建项目,而不是默认位置(/var/www/
)。然后,考虑到只有子文件夹public
可以从外部访问,请为其创建web服务器配置,如下所示:
ServerName www.my-sample-mvc.com
DocumentRoot "/path/to/my/sample/mvc/public"
<Directory "/path/to/my/sample/mvc/public">
Require all granted
# When Options is set to "off", then the RewriteRule directive is forbidden!
Options FollowSymLinks
# Activate rewriting engine.
RewriteEngine On
# Allow pin-pointing to index.php using RewriteRule.
RewriteBase /
# Rewrite url only if no physical folder name is given in url.
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite url only if no physical file name is given in url.
RewriteCond %{REQUEST_FILENAME} !-f
# Parse the request through index.php.
RewriteRule ^(.*)$ index.php [QSA,L]
</Directory>
ServerName www.my-sample-mvc.com
DocumentRoot“/path/to/my/sample/mvc/public”
要求所有授权
#当选项设置为“off”时,则禁止重写规则指令!
选项如下符号链接
#启动重写引擎。
重新启动发动机
#允许使用RewriteRule将pin指向index.php。
重写基/
#仅当url中未给出物理文件夹名称时,才重写url。
重写cond%{REQUEST_FILENAME}-D
#仅当url中未给出物理文件名时重写url。
重写cond%{REQUEST_FILENAME}-F
#通过index.php解析请求。
重写规则^(.*)$index.php[QSA,L]
请注意,上述设置可以定义为:
- 在Apache的配置文件中,或
- 在项目内的.htaccess文件中,或
- 在虚拟主机定义文件中
和
之间包含设置:
... 这里是设置。。。
注意:每次更改配置设置后,不要忘记重新启动web服务器
一些资源:
- (一)
- (二)
<VirtualHost *:80>
... here come the settings ...
</VirtualHost>