尝试打开 Laravel Nova 但获取目录结构而不是主页:重复问题:#56732200
Trying to open Laravel Nova but getting directory structure instead of homepage: duplicate of the question: #56732200
我按照所有laravel nova 的说明,但仍然无法进入主页或登录页面,我得到的只是目录结构,我能够解决这个问题运行 php 在我的本地开发中使用 artisan serve 命令,但不确定这是否是进入生产环境的正确方法,nova 文档说一旦您完成基本说明,您就可以导航到应用程序的 /nova 路径在您的浏览器中,您应该会看到 Nova 仪表板,但不幸的是,我的情况并非如此,这是我的根目录结构:
有什么帮助吗?
这里是你如何配置你的服务器,如果你想使用 nginx。
server {
listen 80;
listen [::]:80;
root path_to_your_project/public;
index index.html index.htm index.php;
server_name your-domain.com;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
这对我有用:
注意 1:如果您使用 XAMPP 在本地开发中进行开发,那么您可能会遇到未加载 app.css 文件的情况,这是因为应用程序正在尝试在 localhost/vendor,而实际上路径需要是 localhost/myfolder/vendor,您在生产中可能不会遇到任何问题。
注意2:如果一切正常,那么您将能够顺利登录,但是在生产模式下,登录后会出现403错误,这是因为您需要指定您的管理员帐户在 NovaServiceProvider.php
中,类似于:
protected function gate(){
/**/
Gate::define('viewNova', function ($user){
/**/
return in_array($user->email, [
/**/
'admin@gmail.com' // <-- add as many logins as you want
/**/
]);
});
}
我从头开始构建 laravel nova 应用程序所遵循的步骤:
{
01. login to github using your personal account
02. navigate to: https://github.com/settings/tokens
03. create a new personal access token
04. cd subdomain.com
05. composer config -g github-oauth.github.com MY_PERSONAL_ACCESS_TOKEN
06. composer create-project laravel/laravel ./ (✔️)
07. navigate to: https://subdomain.com/public/ and make sure the laravel welcome screen is showing (✔️)
08. upload your nova folder to the root directory using FTP (✔️)
09. create an .htaccess file under your root directory and paste the following code: (✔️)
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ ^ [N]
RewriteCond %{REQUEST_URI} (\.\w+$) [NC]
RewriteRule ^(.*)$ public/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ server.php
</IfModule>
10. make sure navigating to https://subdomain.com/ takes you to the laravel welcome screen and your root structure looks like this: (✔️)
app
bootstrap
config
database
nova // <- the nova folder you just uploaded
public
resources
routes
storage
tests
vendor
.editorconfig
.env
.env.example
.gitattributes
.gitignore
.htaccess // <- the file you just created
.styleci.yml
artisan
composer.json
composer.lock
package.json
phpunit.xml
README.md
server.php
webpack.mix.js
11. open phpmyadmin and create a new database: (✔️)
database name: mydatabase
related site: subdomain.com
username: root
password: 123456789
12. edit the file: \.env (✔️)
APP_ENV=production
APP_DEBUG=false
APP_URL=https://subdomain.com/
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=mydatabase
DB_USERNAME="root"
DB_PASSWORD="123456789"
13. edit the file: \config\database.php (✔️)
"mysql" => [
"database" => env("DB_DATABASE", "mydatabase"),
"username" => env("DB_USERNAME", "root"),
"password" => env("DB_PASSWORD", "123456789"),
],
14. edit the file composer.json (https://nova.laravel.com/docs/1.0/installation.html#installing-nova) (✔️)
"minimum-stability": "dev", // make sure it's already there
"prefer-stable": true, // make sure it's already there
"repositories": [
{
"type": "path",
"url": "./nova"
}
],
"require": {
"laravel/nova": "*" // add this to the list of requires
},
15. composer update (✔️)
16. php artisan nova:install (✔️)
17. php artisan config:clear (✔️)
18. php artisan migrate (✔️)
19. in case it is not already there, add App\Providers\NovaServiceProvider::class to the list of providers in the file: \config\app.php (✔️)
20. php artisan nova:user (✔️)
name: admin
email: admin@gmail.com
password: 0000
21. add your admin email to the list of authorized emails in app\Providers\NovaServiceProvider.php (✔️)
protected function gate(){
/**/
Gate::define("viewNova", function ($user){
/**/
return in_array($user->email, [
/**/
"admin@gmail.com" // <-- add as many logins as you want
/**/
]);
});
}
22. php artisan nova:publish
23. php artisan view:clear
}
我按照所有laravel nova 的说明,但仍然无法进入主页或登录页面,我得到的只是目录结构,我能够解决这个问题运行 php 在我的本地开发中使用 artisan serve 命令,但不确定这是否是进入生产环境的正确方法,nova 文档说一旦您完成基本说明,您就可以导航到应用程序的 /nova 路径在您的浏览器中,您应该会看到 Nova 仪表板,但不幸的是,我的情况并非如此,这是我的根目录结构:
有什么帮助吗?
这里是你如何配置你的服务器,如果你想使用 nginx。
server {
listen 80;
listen [::]:80;
root path_to_your_project/public;
index index.html index.htm index.php;
server_name your-domain.com;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
这对我有用:
注意 1:如果您使用 XAMPP 在本地开发中进行开发,那么您可能会遇到未加载 app.css 文件的情况,这是因为应用程序正在尝试在 localhost/vendor,而实际上路径需要是 localhost/myfolder/vendor,您在生产中可能不会遇到任何问题。
注意2:如果一切正常,那么您将能够顺利登录,但是在生产模式下,登录后会出现403错误,这是因为您需要指定您的管理员帐户在 NovaServiceProvider.php
中,类似于:
protected function gate(){
/**/
Gate::define('viewNova', function ($user){
/**/
return in_array($user->email, [
/**/
'admin@gmail.com' // <-- add as many logins as you want
/**/
]);
});
}
我从头开始构建 laravel nova 应用程序所遵循的步骤:
{
01. login to github using your personal account
02. navigate to: https://github.com/settings/tokens
03. create a new personal access token
04. cd subdomain.com
05. composer config -g github-oauth.github.com MY_PERSONAL_ACCESS_TOKEN
06. composer create-project laravel/laravel ./ (✔️)
07. navigate to: https://subdomain.com/public/ and make sure the laravel welcome screen is showing (✔️)
08. upload your nova folder to the root directory using FTP (✔️)
09. create an .htaccess file under your root directory and paste the following code: (✔️)
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ ^ [N]
RewriteCond %{REQUEST_URI} (\.\w+$) [NC]
RewriteRule ^(.*)$ public/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ server.php
</IfModule>
10. make sure navigating to https://subdomain.com/ takes you to the laravel welcome screen and your root structure looks like this: (✔️)
app
bootstrap
config
database
nova // <- the nova folder you just uploaded
public
resources
routes
storage
tests
vendor
.editorconfig
.env
.env.example
.gitattributes
.gitignore
.htaccess // <- the file you just created
.styleci.yml
artisan
composer.json
composer.lock
package.json
phpunit.xml
README.md
server.php
webpack.mix.js
11. open phpmyadmin and create a new database: (✔️)
database name: mydatabase
related site: subdomain.com
username: root
password: 123456789
12. edit the file: \.env (✔️)
APP_ENV=production
APP_DEBUG=false
APP_URL=https://subdomain.com/
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=mydatabase
DB_USERNAME="root"
DB_PASSWORD="123456789"
13. edit the file: \config\database.php (✔️)
"mysql" => [
"database" => env("DB_DATABASE", "mydatabase"),
"username" => env("DB_USERNAME", "root"),
"password" => env("DB_PASSWORD", "123456789"),
],
14. edit the file composer.json (https://nova.laravel.com/docs/1.0/installation.html#installing-nova) (✔️)
"minimum-stability": "dev", // make sure it's already there
"prefer-stable": true, // make sure it's already there
"repositories": [
{
"type": "path",
"url": "./nova"
}
],
"require": {
"laravel/nova": "*" // add this to the list of requires
},
15. composer update (✔️)
16. php artisan nova:install (✔️)
17. php artisan config:clear (✔️)
18. php artisan migrate (✔️)
19. in case it is not already there, add App\Providers\NovaServiceProvider::class to the list of providers in the file: \config\app.php (✔️)
20. php artisan nova:user (✔️)
name: admin
email: admin@gmail.com
password: 0000
21. add your admin email to the list of authorized emails in app\Providers\NovaServiceProvider.php (✔️)
protected function gate(){
/**/
Gate::define("viewNova", function ($user){
/**/
return in_array($user->email, [
/**/
"admin@gmail.com" // <-- add as many logins as you want
/**/
]);
});
}
22. php artisan nova:publish
23. php artisan view:clear
}