简体   繁体   English

如何在没有 Artisan 的情况下运行 Laravel?

[英]How to run Laravel without Artisan?

I have PHP with Apache2 and I want to run Laravel Framework without Artisan but I can't?我有 PHP 和 Apache2 并且我想在没有 Artisan 的情况下运行 Laravel 框架,但我不能? Does anyone know how to run Laravel without Artisan?有谁知道如何在没有 Artisan 的情况下运行 Laravel?

I've solved the problem.我已经解决了这个问题。 The problem was in my htaccess and in mod_rewrite (Apache2).问题出在我的 htaccess 和 mod_rewrite (Apache2) 中。 Now I can connect to my application only by typing localhost/public..现在我只能通过输入 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"重命名根目录中的“server.php”文件,在“index.php”中
  • Move your .htaccess from public folder to root directory将您的 .htaccess 从公用文件夹移动到根目录
  • Make your directory accessible to Apache2 ( set correct file/folder permissions ).使 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).当与使用不同配置的其他开发人员一起工作时,这可能是一个大问题,因为他们将能够看到资产而您看不到(反之亦然)。

I am using xampp in mac我在 mac 中使用 xampp

  1. inside htdocs / run following command: $ laravel new myblog在 htdocs 中 / 运行以下命令: $ laravel new myblog

  2. After successfully creation run following and do following: sudo chmod -R o+w storage/成功创建后运行以下并执行以下操作: sudo chmod -R o+w storage/

  3. Change server.php to index.php (@ root directory)将 server.php 更改为 index.php(@根目录)

  4. copy .htaccess from public to root directory将 .htaccess 从 public 复制到根目录

  5. (optional) in resources / app.blade.php → Change to <link href="{{ asset('public/css/app.css') }}" rel="stylesheet"> (可选)在资源 / app.blade.php → 更改为<link href="{{ asset('public/css/app.css') }}" rel="stylesheet">

  6. run following http://localhost/myblog/运行 http://localhost/myblog/

Easy solution without any code alterations无需任何代码更改的简单解决方案

  • Point your domain to public/ folder of laravel project.将您的域指向 laravel 项目的public/文件夹。
  • Enjoy!享受!

~OR~ ~或~

  • Create .htaccess in project folder and add below code.在项目文件夹中创建.htaccess并添加以下代码。 This code will rewrite domain to public/ folder of your laravel project此代码将域重写到您的 Laravel 项目的public/文件夹
RewriteEngine on

RewriteRule ^(.*)?$ ./public/$1

Hope this is helpful.希望这是有帮助的。

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. Laravel 框架对于启动 PHP 的人来说太痛苦了,他们不太了解 Composer 是什么,.phar 文件来自哪里,它们是什么,以及为什么“Artisan”试图毁掉你的 PHP 生活. Most people are looking for a PHP framework where all you have to do is download, extract and code.大多数人都在寻找一个 PHP 框架,您只需下载、提取和编码即可。 Nevertheless to make things work, you just need to install Laravel through Composer:尽管如此,为了使事情正常运行,您只需要通过 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.通过 Composer 安装 Laravel 后,导航到本地服务器的目录。 You might want to use "CD" (Change directory) to do this.您可能希望使用“CD”(更改目录)来执行此操作。 (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: (我说的是 CLI,无论您使用的是 BASH(Linux)还是 CMD(Windows))然后通过在命令行中键入以下内容来创建您的第一个 Laravel 项目:

laravel new mywebsite1

Replace "mywebsite1" with your first project name.将“mywebsite1”替换为您的第一个项目名称。 And there you go, you're ready to hit the Laravel road.好了,你已经准备好踏上 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.就我而言,我在这样的开发中仍然使用 Windows XP,每当我想闻到 Linux 的味道时,我就会转回 Ubuntu Trusty。 So Composer installs "Laravel installer" in:所以 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 properly install Laravel: http://laravel.com/docs/5.0/installation毕竟,每个人还是最好阅读有关如何正确安装 Laravel 的文档: http ://laravel.com/docs/5.0/installation

Artisan is simply a command line interface. Artisan 只是一个命令行界面。 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.它用于创建和运行迁移以及在应用程序中自动构建某些对象等。本质上,它仅用于帮助创建和处理应用程序,而不是运行它。

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。

For Windows Users Its very easy to change and run laravel projects on your normal project urls :对于 Windows 用户,在您的普通项目 url 上更改和运行 Laravel 项目非常容易:
1. "server.php" to "index.php" . 1. "server.php" 到 "index.php" 。
2. copy ".htaccess" from public to root directory. 2.将“.htaccess”从公共目录复制到根目录。

there you go with your normal URL .那里你去你的正常 URL 。

localhost/project_name本地主机/项目名称

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.就我而言,我在 Mac OS 下使用 XAMPP。 These are the steps on how to achieve that:这些是如何实现这一目标的步骤:

  1. 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
  1. Add a new virtual host添加新的虚拟主机

$ sudo nano /Applications/XAMPP/xamppfiles/etc/extra/httpd-vhosts.conf

The add a new virtual host (eg: 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>

Note: /Users/your-username/newproject/public is the location of your project.注意:/Users/your-username/newproject/public 是你的项目所在的位置。

  1. Update your hosts更新您的主机

$ sudo nano /etc/hosts

Add this following setting:添加以下设置:

# 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 上找到

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

Just Follow 3 Step ;只需遵循 3 步;

  1. Change File Name : change serve.php to index.php inside your Project name folder.更改文件名:在项目名称文件夹中将 serve.php 更改为 index.php。
  2. Move .htaccess file Bring ".htaccess" file to main root [inside your Project name folder ].移动 .htaccess 文件将“.htaccess”文件带到主根目录 [在您的项目名称文件夹中]。
  3. Restart your local server .重新启动本地服务器 Your are just 1 click away .您只需点击 1 次即可。 Restart all services of xampp or wamp重启xampp或wamp的所有服务
  4. Enjoy享受

Well , the easy way is嗯,简单的方法是
1) create a new folder"Project" and copy all files except public folder content to project folder 1)新建文件夹“Project”,将除公用文件夹内容外的所有文件复制到项目文件夹
2) copy all files of public folder to root 2) 将 public 文件夹的所有文件复制到 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.并且你可以在没有 artisan 的情况下运行 laravel。如果你重命名 server.php 并复制 .htaccess ,当你尝试运行 auth artisan 命令时可能会触发一些错误。我遇到了 auth 命令的问题。

Laravel with Vue.JS Laravel 与 Vue.JS

If you are using vue.js with Laravel and your app is not working without php artisan serve , you need to create a virtual host.如果您在vue.js使用Laravel并且您的应用程序在没有php artisan serve情况下无法运行,您需要创建一个虚拟主机。 This is a simple two-step process for windows.对于 Windows,这是一个简单的两步过程。

Step 1: Update you hosts file at C:\\Windows\\System32\\drivers\\etc with,步骤 1:使用以下命令更新C:\\Windows\\System32\\drivers\\etc主机文件,

127.0.0.1       dev.example #You can rename according to your app

Step 2: Update you vhosts file with,第 2 步:更新您的 vhosts 文件,

I am using Apache which is installed in D:\\ so my path for vhosts file is at D:\\xampp\\apache\\conf\\extra我正在使用安装在D:\\ Apache ,所以我的 vhosts 文件路径位于D:\\xampp\\apache\\conf\\extra

<VirtualHost *>
    DocumentRoot "D:\xampp\htdocs\example\public" ##Your path 
    ServerName dev.example ##Your URL according to what you set in hosts file in step 1 
    <Directory "D:\xampp\htdocs\example\public">  ##Your path      
        Order allow,deny     
        Allow from all   
    </Directory> 
</VirtualHost>

That's it, now you can just visit your app at http://dev.example/就是这样,现在您可以在http://dev.example/访问您的应用程序

  1. Install and setup Laravel on your local (meaning your local machine).在您的本地(即您的本地机器)上安装和设置 Laravel。
  2. Once done, copy all files to your hosting.完成后,将所有文件复制到您的主机。
  3. Create a .htaccess file on your Laravel's root directory.在 Laravel 的根目录中创建一个 .htaccess 文件。 This is to access it without the "public" on the URL.这是在没有 URL 上的“公共”的情况下访问它。
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM