php 如何在没有 Artisan 的情况下运行 Laravel?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28788285/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to run Laravel without Artisan?
提问by Syncro
I have PHP with Apache2 and I want to run Laravel Framework without Artisan but I can't! Does anyone know how to run Laravel without Artisan?
我有 PHP 和 Apache2,我想在没有 Artisan 的情况下运行 Laravel 框架,但我不能!有谁知道如何在没有 Artisan 的情况下运行 Laravel?
回答by Syncro
I've solved the problem. The problem was in my htaccess and in mod_rewrite (Apache2). Now I can connect to my application only by typing localhost/public..
我已经解决了这个问题。问题出在我的 htaccess 和 mod_rewrite (Apache2) 中。现在我只能通过输入 localhost/public 连接到我的应用程序。
If anyone wants to make the application public, the more easy and fastest way is:
如果有人想公开应用程序,更简单快捷的方法是:
- Rename the "server.php" file in root directory, in "index.php"
- Move your .htaccess from public folder to root directory
- Make your directory accessible to Apache2 (set correct file/folder permissions).
- 重命名根目录中的“server.php”文件,在“index.php”中
- 将您的 .htaccess 从公用文件夹移动到根目录
- 使 Apache2 可以访问您的目录(设置正确的文件/文件夹权限)。
Thanks to all users for help! :)
感谢所有用户的帮助!:)
Important Edit
重要编辑
Consider using Apache Virtual Hosts(pointing the virtual host to the /public Laravel folder) instead of renaming server.php to index.php because by doing this you will need to prefix "public/" when you use the Laravel's asset() function in your views.
考虑使用 Apache虚拟主机(将虚拟主机指向 /public Laravel 文件夹)而不是将 server.php 重命名为 index.php 因为这样做你需要在使用 Laravel 的 asset() 函数时添加前缀“public/”你的意见。
When working with other devs, who are using a different configuration, this might be a big problem because they will be able to see the assets while you will not (or viceversa).
当与使用不同配置的其他开发人员合作时,这可能是一个大问题,因为他们将能够看到资产而您看不到(反之亦然)。
回答by Vinod Joshi
I am using xampp in mac
我在 mac 中使用 xampp
inside htdocs / run following commadn $ laravel new myblog
After successfully creation run following and do following
- sudo chmod -R o+w storage/
Change server.php to index.php (@ root directory)
copy .htaccess from public to root directory
(optional) in Resources / app.blade.php --> Change to
run following http://localhost/myblog/
在 htdocs 内/按照命令运行 $ laravel new myblog
成功创建后运行以下并执行以下操作
- 须藤 chmod -R o+w 存储/
将 server.php 更改为 index.php(@根目录)
将 .htaccess 从 public 复制到根目录
(可选)在 Resources / app.blade.php --> 更改为
回答by Rohan Khude
Easy solutionwithout any code alterations
无需任何代码更改的简单解决方案
- Point your domain to
public/
folder of laravel project.
- 将您的域指向
public/
laravel 项目的文件夹。
OR
或者
- Create
.htaccess
in project folder and add below code. This code will rewrite domain topublic/
folder of your laravel project
.htaccess
在项目文件夹中创建并添加以下代码。此代码将域重写到public/
您的 Laravel 项目的文件夹
RewriteEngine on
RewriteRule ^(.*)?$ ./public/
In case, if you want to do this in local then create .htaccess
files as mentioned in above point with the given code and do the following
如果您想在本地执行此操作,请.htaccess
使用给定代码创建上面提到的文件并执行以下操作
$ cd your_project_path/
$ php -S localhost:8000
Hope this is helpful.
希望这是有帮助的。
回答by Allen Linatoc
Laravel framework is such a pain in the ass for startup PHP guys who are not much oriented about what the hell composer is, and where .phar files are coming from and what are they, and why "Artisan" is trying to ruin your PHP life. Most people are looking for a PHP framework where all you have to do is download, extract and code. Nevertheless to make things work, you just need to install Laravel through Composer:
Laravel 框架对于那些不太了解到底 Composer 是什么、.phar 文件从何而来、它们是什么以及为什么“Artisan”试图毁掉你的 PHP 生活的 PHP 创业者来说是一件很痛苦的事情. 大多数人都在寻找一个 PHP 框架,您只需下载、提取和编码即可。尽管如此,为了使事情正常运行,您只需要通过 Composer 安装 Laravel:
composer global require "laravel/installer=~1.1"
Anyway, you can download Composer from http://getcomposer.org/
无论如何,您可以从http://getcomposer.org/下载 Composer
After you install Laravel through Composer, navigate to your local server's directory. You might want to use "CD" (Change directory) to do this. (I'm speaking of CLI, whether you're in BASH(Linux) or CMD(Windows)) Then create your very first Laravel project by typing this in command line:
通过 Composer 安装 Laravel 后,导航到本地服务器的目录。您可能希望使用“CD”(更改目录)来执行此操作。(我说的是 CLI,无论您使用的是 BASH(Linux)还是 CMD(Windows))然后通过在命令行中键入以下内容来创建您的第一个 Laravel 项目:
laravel new mywebsite1
Replace "mywebsite1" with your first project name. And there you go, you're ready to hit the Laravel road.
将“mywebsite1”替换为您的第一个项目名称。好了,你已经准备好踏上 Laravel 之路了。
In my case, I'm still using Windows XP in such development and shifts back to Ubuntu Trusty whenever I feel like I want to smell Linux scent. So Composer installs "Laravel installer" in:
就我而言,我在这样的开发中仍然使用 Windows XP,每当我想闻到 Linux 的味道时,我就会转回 Ubuntu Trusty。所以 Composer 将“Laravel 安装程序”安装在:
%userprofile%\Application Data\Composer\vendor\bin
So I make a backup copy of this directory so the next time I use Laravel on other unit with no internet connection, I just have to extract it, and run:
所以我制作了这个目录的备份副本,以便下次我在没有互联网连接的其他设备上使用 Laravel 时,我只需要解压它,然后运行:
laravel new [myprojectname]
within the same directory and copies the resulting folder to my XAMPP's htdocs or WAMP's www folder.
在同一目录中,并将生成的文件夹复制到我的 XAMPP 的 htdocs 或 WAMP 的 www 文件夹。
Anyway I'm just sharing my approach for those with no 24/7 internet connection at home :p
无论如何,我只是为家里没有 24/7 互联网连接的人分享我的方法:p
After all it's still best for everyone to read the documentation on how to properlyinstall Laravel: http://laravel.com/docs/5.0/installation
毕竟,每个人还是最好阅读有关如何正确安装 Laravel的文档:http://laravel.com/docs/5.0/installation
回答by Homesh Paul
For Windows Users Its very easy to change and run laravel projects on your normal project urls :
1. "server.php" to "index.php" .
2. copy ".htaccess" from public to root directory.
对于 Windows 用户在你的普通项目 url 上更改和运行 Laravel 项目非常容易:
1. "server.php" 到 "index.php" 。
2.将“.htaccess”从公共目录复制到根目录。
there you go with your normal URL .
那里你去你的正常 URL 。
localhost/project_name
本地主机/项目名称
回答by cchapman
Artisan is simply a command line interface. It is made to do things like create and run migrations and automate building certain objects within your Application, etc. Essentially, it's only made to help facilitate creating and working on your Application, not run it.
Artisan 只是一个命令行界面。它用于创建和运行迁移以及在应用程序中自动构建某些对象等。本质上,它仅用于帮助创建和处理应用程序,而不是运行它。
If you are having issues actually getting the Application to run, it is likely a problem with either your PHP or Apache, not Artisan.
如果您在实际运行应用程序时遇到问题,则可能是 PHP 或 Apache 的问题,而不是 Artisan。
回答by antonifs
For an aternative maybe you can run it under a virtual host. All you need is just create a new virtual host with your project/public directory as a DocumentRoot.
对于替代方案,您可以在虚拟主机下运行它。您所需要的只是创建一个新的虚拟主机,并将您的项目/公共目录作为 DocumentRoot。
In my case, I am using XAMPP under Mac OS. These are the steps on how to achieve that:
就我而言,我在 Mac OS 下使用 XAMPP。这些是如何实现这一目标的步骤:
- Enable virtual host config
- 启用虚拟主机配置
Ensure virtual host config was enabled, else you can enable it through this file: /Applications/XAMPP/xamppfiles/etc/httpd.conf
确保启用了虚拟主机配置,否则您可以通过以下文件启用它:/Applications/XAMPP/xamppfiles/etc/httpd.conf
$ sudo nano /Applications/XAMPP/xamppfiles/etc/httpd.conf
Remove the hash "#" of this following line
删除以下行的哈希“#”
# Include /Applications/XAMPP/etc/extra/httpd-vhosts.conf
- Add a new virtual host
- 添加新的虚拟主机
$ sudo nano /Applications/XAMPP/xamppfiles/etc/extra/httpd-vhosts.conf
$ sudo nano /Applications/XAMPP/xamppfiles/etc/extra/httpd-vhosts.conf
The add a new virtual host (e.g: newproject.dev)
添加一个新的虚拟主机(例如:newproject.dev)
# Virtual host of newproject.dev
<VirtualHost *:80>
ServerName newproject.dev
DocumentRoot "/Users/your-username/newproject/public"
<Directory "/Users/your-username/newproject/public">
Options Indexes FollowSymLinks Includes execCGI
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
# Virtual host of newproject.dev
<VirtualHost *:80>
ServerName newproject.dev
DocumentRoot "/Users/your-username/newproject/public"
<Directory "/Users/your-username/newproject/public">
Options Indexes FollowSymLinks Includes execCGI
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Note: /Users/your-username/newproject/public is the location of your project.
注意:/Users/your-username/newproject/public 是你的项目所在的位置。
- Update your hosts
- 更新您的主机
$ sudo nano /etc/hosts
$ sudo nano /etc/hosts
Add this following setting:
添加以下设置:
# Host of newproject.dev
127.0.0.1 newproject.dev
# Host of newproject.dev
127.0.0.1 newproject.dev
Restart your Apache, go to your browser and your project should be available on http://newproject.dev
重新启动 Apache,转到浏览器,您的项目应该可以在http://newproject.dev 上找到
回答by ccs
I got mine to work by adding the following block to my apache vhost conf file
我通过将以下块添加到我的 apache vhost conf 文件来使我的工作
<VirtualHost *:8003>
ServerName myproject
DocumentRoot "/path/to/myproject/public"
</VirtualHost>
and running sudo chown -R daemon storage
from my project root
并sudo chown -R daemon storage
从我的项目根目录运行
回答by munna ss
Well , the easy way is
1) create a new folder"Project" and copy all files except public folder content to project folder
2) copy all files of public folder to root
and you can run laravel without artisan.If you rename server.php and copy .htaccess , it may make trigger some error when you try to run auth artisan command.I experienced problem with auth command.
好吧,简单的方法是
1)创建一个新文件夹“Project”并将除公共文件夹内容之外的所有文件复制到项目文件夹
2)将公共文件夹的所有文件复制到根目录
,您可以在没有artisan的情况下运行laravel。如果您重命名server.php并复制 .htaccess ,当您尝试运行 auth artisan 命令时,它可能会触发一些错误。我遇到了 auth 命令的问题。
回答by M Abdullah
Just Follow 3 Step ;
只需遵循 3 步;
- Change File Name :change serve.php to index.php inside your Project name folder.
- Move .htaccess fileBring ".htaccess" file to main root [inside your Project name folder ].
- Restart your local server. Your are just 1 click away . Restart all services of xampp or wamp
- Enjoy
- 更改文件名:在项目名称文件夹中将 serve.php 更改为 index.php。
- 移动 .htaccess 文件将“.htaccess”文件带到主根目录 [在您的项目名称文件夹中]。
- 重新启动本地服务器。您只需点击 1 次即可。重启xampp或wamp的所有服务
- 享受