Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

BikashKatwal's avatar

How to use php artisan in vagrant/Homestead

I am using Homestead and I want php artisan command to execute but I don't know how to make it work in homestead/vagrant. In my case php artisan commands doesnot work in local server. Actually the project that I have doesnot compiles in local server, but using Homestead I can execute the project. Now I have to create model but I cannot create it because of php artisan command not working in local and Homestead envirenment. Can anyone please help me to understand and resolve it.

0 likes
9 replies
erikverbeek's avatar

You can use SSH to log into the virtual server. Run vagrant ssh from the folder where you installed Homestead.

From there you can navigate to your folder and run artisan commands.

bobbybouwmann's avatar

Another option is locally installing PHP and then you should be able to run php artisan commands as well. The only challenge you will have is the database. To make that work you need to set the database host to the IP of the vagrant box

DB_HOST=192.168.10.10
BikashKatwal's avatar

I got Laravel requires the Mcrypt PHP extension error. The project is in laravel 4 which I am not able to run in my local machine, but I could do it in the homestead.

bobbybouwmann's avatar

You have to install the mcrypt php extension to make this work locally. But it depends on your system. What do you run? Mac, Windows, Linux?

BikashKatwal's avatar

I am using Windows and I get the following index.php when I try executing the php artisan commands.

</html>vagrant@homestead:~/halls$ php artisan list
<!DOCTYPE html>
<!--[if lt IE 7]>          <html class="no-js ie lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
<!--[if IE 7]>             <html class="no-js ie lt-ie9 lt-ie8" lang="en"> <![endif]-->
<!--[if IE 8]>             <html class="no-js ie lt-ie9" lang="en"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js ie" lang="en"> <!--<![endif]-->
        <head>
                <meta charset="utf-8">
                <meta http-equiv="X-UA-Compatible" content="IE=edge">
                <title>Halls for Hire</title>
                <meta name="description" content="">
                <meta name="viewport" content="width=device-width, initial-scale=1">

                <link rel="shortcut icon" href="http://localhost/favicon.ico">
                <link rel="apple-touch-icon" href="http://localhost/apple-touch-icon.png">

                <link rel="stylesheet" href="http://localhost/styles/app.css">

                <script src="http://localhost/scripts/vendor/modernizr.min.js"></script>

                <script>
                        var _gaq = _gaq || [];
                                _gaq.push(['_setAccount', 'UA-32397342-1']);
                                _gaq.push(['_trackPageview']);

                        (function() {
                                var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
                                ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
                                var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
                        })();
                                        </script>

        </head>
        <body class="">
                <!--[if lt IE 7]>
                        <div class="alert-box error browsehappy" data-alert>You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience. <a href="#" class="close">&times;</a></div>
                <![endif]-->
                <header id="header">
                                        <h1 id="title"><a href="http://localhost" class="sprite logo-header">Halls For Hire</a></h1>
                        <div id="user" class="show-for-medium-up">
                                                <a href="http://localhost/login" class="login"><i class="fa fa-lock "></i> Log In</a>
                                <a href="http://localhost/register" class="button secondary radius"><i class="fa fa-bullhorn "></i> List Your Hall</a>
        </div>                          </header>

                <section id="main">


                        <div class="wrap center">
        <h3>Error occurred!</h3>
        <p>An unknown error has occurred.</p>
        <p><a href="http://localhost">Return Home</a></p>
</div>
                </section>

                <footer id="footer">
                        <div class="wrap">
                                <div class="row">
                                        <div class="medium-3 columns">
                                                <h6><i><strong>&copy;</strong></i> Halls for Hire</h6>
                                                <nav>
                                                        <a href="http://localhost/conditions"><i class="fa fa-list-alt "></i> Terms &amp; Conditions</a>
                                                        <a href="http://localhost/contact"><i class="fa fa-envelope-o "></i> Contact Halls for Hire</a>
                                                </nav>
                                        </div>
                                        <div class="medium-3 columns">
                                                <h6><i class="fa fa-list "></i> Navigation</h6>
                                                <nav>
                                                        <a href="/"><i class="fa fa-search "></i> Search Halls</a>
                                                        <a href="http://localhost/halls"><i class="fa fa-list-alt "></i> Browse Halls</a>
                                                        <a href="http://localhost/about"><i class="fa fa-question-circle "></i> About</a>
                                                        <a href="http://localhost/pricing"><i class="fa fa-money "></i> Pricing</a>
                                                        <!-- <a href="http://localhost/community"><i class="fa fa-users "></i> Community</a> -->
                                                </nav>
                                        </div>
                                        <div class="medium-3 columns">
                                                <h6><i class="fa fa-user "></i> Members</h6>
                                                <nav>
                                                        <a href="http://localhost/login" class="login"><i class="fa fa-lock "></i> Log In</a>
                                                        <a href="http://localhost/register"><i class="fa fa-bullhorn "></i> List Your Hall</a>
                                                </nav>
                                        </div>
                                        <div class="medium-3 columns">
                                                <h6><i class="fa fa-thumbs-up "></i> Get Social</h6>
                                                <nav>
                                                        <a href="https://www.facebook.com/" target="_blank"><i class="fa fa-facebook "></i> Facebook</a>
                                                        <a href="https://twitter.com/" target="_blank"><i class="fa fa-twitter "></i> Twitter</a>
                                                </nav>
                                        </div>
                                </div>
                        </div>
                </footer>

                <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
                <!--<script src="http://localhost/scripts/vendor/jquery.min.js"></script>-->
                <script>window.jQuery || document.write('<script src="http://localhost/scripts/vendor/jquery.min.js"><\/script>')</script>

                <script src="http://localhost/bower_components/foundation/js/foundation.min.js"></script>
                <script src="http://localhost/bower_components/foundation/js/foundation/foundation.clearing.js"></script>
                <script src="http://localhost/scripts/app.min.js"></script>
                        </body>
</html>vagrant@homestead:~/halls$
bobbybouwmann's avatar

It seems that you're dumping your website somewhere in your code! You should double check that for yourself!

Snapey's avatar

seems like error handling is returning an html response instead of realising its running at the command line.

You could look in storage/logs for the error?

BikashKatwal's avatar

@bobbybouwmann @snapey This is an existing project in laravel 4, so I am not sure what the developers have done for dumping or for error handling. I am new to the environment and learning laravel 5.8 in which artisan commands run easily, but following the same in this projects doesn't work. Could you please suggest me how website dumping is done or error handling is done for both responses.

Thank you for the help.

BikashKatwal's avatar
BikashKatwal
OP
Best Answer
Level 3

comminting //'Way\Generators\GeneratorsServiceProvider', in config\app.php fixed the issue.

Please or to participate in this conversation.