我如何更改Laravel中的公共/目录名称9
从3个月前开始,我已经看到一个标题非常相似的问题,但没有答案。
经过新的Laravel 9安装后,将Laravel应用程序放入其自己的目录中的最低步骤是什么,还可以修改公共目录名称?拥有Laravel 9特定的逐步指南将很方便,因为我似乎在任何地方都找不到一个。
例如。以下根目录结构:
laravel-app/(包含所有Laravel文件,例如Resources/and Storage/)
public_html/(包含index.php和/js etc)
使用旧过程(类似于此 https://github.com/hannanstd/change-laravel-public )我一直使用不再起作用,这似乎与vite有关vite与laravel 9使用而不是laravel-mix有关。它可以工作到运行PHP Artisan Serve
的点,但是在使用Vite运行NPM运行
时失败。给出此错误:
$ npm run dev
> dev
> vite
(!) Could not auto-determine entry point from rollupOptions or html files and there are no explicit optimizeDeps.include patterns. Skipping dependency
pre-bundling.
node:internal/fs/utils:347
throw err;
^
Error: ENOENT: no such file or directory, open 'public\hot'
at Object.openSync (node:fs:594:3)
at Object.writeFileSync (node:fs:2207:35)
at Server.<anonymous> (D:\Websites\laravel9-admin\laravel-core\node_modules\laravel-vite-plugin\dist\index.js:122:34)
at Object.onceWrapper (node:events:627:28)
at Server.emit (node:events:525:35)
at emitListeningNT (node:net:1466:10)
at processTicksAndRejections (node:internal/process/task_queues:82:21) {
errno: -4058,
syscall: 'open',
code: 'ENOENT',
path: 'public\\hot'
}
因此,似乎在其他地方定义了默认的“ public/”,但是在我的项目中使用Ctrl+Shift+F搜索后,它似乎并不重要,因此真的不确定它从哪里获得。任何帮助都非常感谢,但实际上是关于如何实现Laravel 9的逐步指南,这是最终目标,因此它可以成为我和其他有相同问题的用户的参考:)
I have seen a question with a very similar title on SO from 3 months ago but it has no answers.
After a fresh laravel 9 installation what are the minimum steps to put the laravel application into it's own directory, and also modify the public directory name? It would be handy to have a step by step guide with laravel 9 specific one as I can't seem to find one anywhere.
eg. the following root directory structure:
laravel-app/ (contains all laravel files like resources/ and storage/)
public_html/ (contains index.php and /js etc)
Using the old process (similar to this https://github.com/hannanstd/change-laravel-public) I have always used no longer works, and this seems to have something to do with vite that laravel 9 uses instead of laravel-mix. It works up to the point of running php artisan serve
but fails when running npm run dev
with vite. Giving this error:
$ npm run dev
> dev
> vite
(!) Could not auto-determine entry point from rollupOptions or html files and there are no explicit optimizeDeps.include patterns. Skipping dependency
pre-bundling.
node:internal/fs/utils:347
throw err;
^
Error: ENOENT: no such file or directory, open 'public\hot'
at Object.openSync (node:fs:594:3)
at Object.writeFileSync (node:fs:2207:35)
at Server.<anonymous> (D:\Websites\laravel9-admin\laravel-core\node_modules\laravel-vite-plugin\dist\index.js:122:34)
at Object.onceWrapper (node:events:627:28)
at Server.emit (node:events:525:35)
at emitListeningNT (node:net:1466:10)
at processTicksAndRejections (node:internal/process/task_queues:82:21) {
errno: -4058,
syscall: 'open',
code: 'ENOENT',
path: 'public\\hot'
}
So it seems that yet somewhere else the default "public/" is defined, but after searching with ctrl+shift+F in my project it doesn't seem to be anywhere that matters so really unsure where it's getting it from. Any help is highly appreciated, but really a step by step guide on how to achieve this for Laravel 9 is the end goal so it can be a reference for myself and other users with the same problem :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我自己回答这个解决方案!
第一个选项:仅重命名公共/目录,对于Laravel 9:
public_html
(或任何所需的名称publicDirectory:'public_html'
laravel-core/vite.config.js
在插件/laravel对象中,例如。第二个选项:将Laravel Core文件分开为自己的目录,并重命名公共/目录,对于Laravel 9:
public_html
(或任何所需的名称)laravel核
目录,然后将所有文件和文件夹移动以外的所有文件和文件夹,public_html
添加到Laravel核心文件夹中。index.php
在public_html
文件夹中,查找/替换__ dir __。 laravel-core/
(3个情况)appserviceprovider.php
,并在注册方法中添加以下代码:publicDirectory:'public_html'
laravel-core/vite.config.js
在插件/laravel对象中,例如。Answering this myself as found the solution!
First Option: Just rename the public/ directory, for laravel 9:
public_html
(or any desired name)AppServiceProvider.php
and add below code in register method:publicDirectory: 'public_html'
tolaravel-core/vite.config.js
within the plugins / laravel object, eg.Second option: Seperate out the laravel core files into their own directory and also rename the public/ directory, for laravel 9:
public_html
(or any desired name)laravel-core
directory and move all files and folders exceptpublic_html
into the laravel-core folder.index.php
inpublic_html
folder and find/replace__DIR__.'/../
with__DIR__.'/../laravel-core/
(3 cases)AppServiceProvider.php
and add below code in register method:publicDirectory: 'public_html'
tolaravel-core/vite.config.js
within the plugins / laravel object, eg.对我来说,上面的解决方案部分工作。
这就是我使用Vite插件为Laravel 10制作的方式,因此它可以在服务器上使用,但也可以通过工匠在本地提供服务。
重命名
public
public_html
在
中vite.config.js
addpublicDirectory:'public_html'
in
appserviceprovider
:和某些原因出于某种原因
php Artisan Storage:link 在此之后停止工作,这样解决,请转到
/foo
以使SIMLINK或在终端中运行。For me the solutions above worked partially.
This is how I made it for Laravel 10 with the Vite plugin, so it works on the server but also to serve it locally through artisan.
Rename
public
topublic_html
In
vite.config.js
addpublicDirectory: 'public_html'
In
AppServiceProvider
:And for some reason
php artisan storage:link
stops working after this, solved it like this, go to/foo
to make the simlink or run it in the terminal if you have access.