[英]How can i deploy my website on Heroku properly?
I've trying to deploy my website on Heroku, the implementation that i used for this it's Model View Controller with PHP.我正在尝试将我的网站部署在 Heroku 上,我用于此的实现是 Model I don't know what happend but when i try to access to the main page (or index) this works perfectly, when i'm trying to access other pages on mi website something occurs like this:
我不知道发生了什么,但是当我尝试访问主页(或索引)时,效果很好,当我尝试访问 mi 网站上的其他页面时,会发生如下情况:
enter image description here在此处输入图像描述
I know one reason which this is happening, i used in my Router the next:我知道发生这种情况的一个原因,我在路由器中使用了下一个:
$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;
}
So, i displayed global variable of PHP $_SERVER on my website and i noticed $_SERVER['PATH_INFO']
doesn't appear on it.所以,我在我的网站上显示了 PHP $_SERVER 的全局变量,我注意到
$_SERVER['PATH_INFO']
没有出现在上面。 So, i guess that the problem comes from Apache's configuration because i use Apache2 and PHP for this.所以,我想问题出在 Apache 的配置上,因为我为此使用了 Apache2 和 PHP。 So, i don't know how configure because it's my first time doing this, if you can help me, i'll really thank to you.
所以,我不知道如何配置,因为这是我第一次这样做,如果你能帮助我,我会非常感谢你。
Here is my directory: enter image description here这是我的目录:在此处输入图像描述
And, finally my procfile:最后,我的 procfile:
web: vendor/bin/heroku-php-apache2 public/
These are the general appliable steps of configuring an MVC-based web application.这些是配置基于 MVC 的 web 应用程序的一般适用步骤。 Presumed web server version for the settings below: Apache HTTP Server v2.4 .
假定 web 服务器版本用于以下设置: Apache HTTP Server v2.4 。
1) Block access to all directories and files: 1) 阻止对所有目录和文件的访问:
First of all, in the config file of Apache, the access to all directories and files should be blocked by default:首先,在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>
2) Allow access to a default directory: 2)允许访问默认目录:
The access to a default directory (here /var/www/
), supposedly used for projects, should then be allowed:然后应该允许访问应该用于项目的默认目录(此处为
/var/www/
):
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
My recommendation : For security reasons, this location should contain only a index.php
and a index.html
file, each of them displaying a simple "Hello" message.我的建议:出于安全原因,这个位置应该只包含一个
index.php
和一个index.html
文件,每个文件都显示一个简单的“Hello”消息。 All web projects should be created in other directories and the access to them should be set separately, as described below.所有 web 项目应在其他目录中创建,并应单独设置对它们的访问权限,如下所述。
3) Set access to a separate project directory: 3)设置对单独项目目录的访问:
Let's suppose that you create your project in another location (like in the directory /path/to/my/sample/mvc/
) than the default one ( /var/www/
).假设您在默认位置(
/var/www/
)之外的另一个位置(例如目录/path/to/my/sample/mvc/
)创建项目。 Then, taking into consideration, that only the subfolder public
should be accessible from outside, create a web server configuration for it, like this:然后,考虑到只有子文件夹
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>
Note that the above settings can be defined either:请注意,上述设置可以定义为:
In case a virtual host definition file is used, the settings must be included between the tags <VirtualHost>
and </VirtualHost>
:如果使用虚拟主机定义文件,则必须在标签
<VirtualHost>
和</VirtualHost>
之间包含设置:
<VirtualHost *:80>
... here come the settings ...
</VirtualHost>
Note: Don't forget to restart the web server after each change of the configuration settings.注意:每次更改配置设置后,不要忘记重新启动 web 服务器。
Some resources:一些资源:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.