Accessing Lumen public folder from Vagrant - laravel

I'm currently experimenting with Lumen from inside an Homestead Vagrant box. My homestead box is up and running, and I accessed the machine with vagrant ssh.
I then created a new folder, and installed Lumen with: composer global require "laravel/lumen-installer". Then I created a new Lumen project with lumen new blog.
This created all the structure of the new Lumen project. My problem is that now, I want to access the project in the browser. So, following the tutorial on the Lumen website I could do this with PHP in built server, like php -S localhost:8000 -t public.
The problem is that I'm inside a Vagrant Homestead machine, so when I try to go to localhost:8000 I get a This site can't be reached. localhost refused to connect error.
Any idea on how can I fix this?

Related

How to setup laravel 7 on shared hosting?

I recently transposed an existing web site from symfony to laravel for which I am a newbie.
At the moment my site is running with Laravel locally using the embedded server.
I created a repo on github and pushed my site on it.
Then I connected to my site via ssh and cloned the github repo on the remote server (shared hosting).
I created a .env file from the .env-example remotly.
I created a subdomain that points to the public folder of the cloned site.
I modified a line in public/index.php to
$app = require_once __DIR__.'/bootstrap/app.php';
I launched a composer update command and then run
php artisan key:generate it returned success but I couldn't find any key in the .env file thus I used the same key I use locally.
When I visit the subdomain I get a page like this one:
Index of / Name Last modified Size Description cgi-bin/
2020-09-13 15:23 -
I very probably missed something

Xampp localhost not working

I am running laravel on xampp and I have problem with accessing pages,
http://localhost/laravel/public/ I get a login page which is good
however when I go for example http://localhost/laravel/public/smokeyard
I get 404 error with The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.
Route:
Route::get('smokeyard', 'GuzzleController#smokeyard');
Controller:
function smokeyard(){
return view('smokeyard');
}
All my views are located in resources folder.
if you want to access laravel project without running artisan serve, you need to change few settings,
copy the .htaccess file from the public folder and paste it in the root folder of your application
rename the server.php in the root directory to index.php
now go to localhost/your_project_name/smokeyard for the url you want to check
hope this helps
Run php artisan serve and access your server at http://localhost:8000. Your routes should work fine then.
You can't access your laravel application routes straight away through the folder structure with xampp. You need to setup the web root to point to the public folder and access localhost or run the laravel server and use it. This is because the url rewriting would fail when you access the routes in laravel the way you do.
I tried this in MX Linux 21.xx. My xampp got messed up after installing larvel on it.
check MySQL status with command
mysql service status
stop the service using the command
service mysql stop
you will be prompted to provide your password, Enter password.
start xampp using command
sudo /opt/lampp/lampp start
All should be back to normal

Moving Laravel project from Windows 7 to Raspbian Jessie

I created a Laravel webapp running on a homestead vm on my Windows 7 machine. I want to take this webapp and move it over to my raspberry pi so it's easily accessible from my other devices, since my decsktop doesn't have a direct connection to my router.
I have my pi setup with apache2 and Laravel all the way to the point that if I create a Laravel project in /var/www using
php ~/composer.phar create-project --prefer-dist laravel/laravel project
Then I can access it through the URL:
192.168.1.232/project/public
However, when I pull the webapp I created on the homestead machine through get and place it in /var/www on the pi, I get a page isnt working, currently unable to handle request error.
Does anyone know what files I would need to change/git ignore to develop Laravel on my windows machine and then pull certain versions to my pi without creating errors?
EDIT: I was able to fix this issue by looking at the git ignored files. Two necessary files, /vendor and .env were being ignored when I pushed my project to git. All I did was recreate the .env file in my project directory on my pi, and move a copy a vendor file over from a project I created on the pi, and my webapp started to work.

Lumen not working out of the box

Just installed Lumen framework.
hit the link http://localhost/lumen/public/ in my browser and got this following error, anyone got any idea about it?
Traced it back to the app.php file in bootstrap folder.
if You want to access lumen project without "php artisan serve"
$app->run(); replace with
$request = Illuminate\Http\Request::capture();
$app->run($request);
from this path yourlumenproject/public/index.php
Open your terminal in the root folder run the following command php artisan serve.
Lumen development server started on http://localhost:8000/
if you want to serve your app in local development you can do this :
php -S localhost:8000 -t public/
and it will serve in localhost in port 8000. hope this help.
Note : I'm using Laravel Framework version Lumen (5.2.4) (Laravel Components 5.2.*)
At the moment Lumen only runs in the domain root.
(I've submitted a PR that fixes this but it has yet to be merged)
You have to create a Virtual Host on your local webserver and point the document root of that to the public directory. After that you can access your app with something like: http://lumen.dev.
Guide for Virtual Hosts with nginx
Guide for Virtual Hosts with Apache
A simple alternative to setting this up manually is Laravel Homestead. It is an official Vagrant box made for Laravel, that allows you to easily get your development environment up and running.

Laravel Homestead- How to migrate an app into the same folder and connect the MySQL database?

I was able to do install Homestead and to create a new app within the virtual machine.
However, I do have apps that I created outside the virtual machine and I would like to connect my database now. It is editable under localhost/phpmyadmin, it is my mysql standard installation in port 3306.
I have the folder that I have from the Internet and the first app that I specified is called Laravel, how do I do that?
If I just copy it in the same directory, I get:
php artisan serve
PHP Fatal error: Class 'Barryvdh\Debugbar\ServiceProvider' not found in /home/vagrant/Code/foobooks/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php on line 157
PHP Stack trace:
PHP 1. {main}() /home/vagrant/Code/foobooks/artisan:0
PHP 2. require_once() /home/vagrant/Code/foobooks/artisan:30
PHP 3. require() /home/vagrant/Code/foobooks/bootstrap/start.php:68
PHP 4. Illuminate\Foundation\ProviderRepository->load() /home/vagrant/Code/foobooks/vendor/laravel/framework/src/Illuminate/Foundation/start.php:210
PHP 5. Illuminate\Foundation\ProviderRepository->compileManifest() /home/vagrant/Code/foobooks/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php:57
PHP 6. Illuminate\Foundation\ProviderRepository->createProvider() /home/vagrant/Code/foobooks/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php:121
{"error":{"type":"Symfony\\Component\\Debug\\Exception\\FatalErrorException","message":"Class 'Barryvdh\\Debugbar\\ServiceProvider' not found","file":"\/home\/vagrant\/Code\/foobooks\/vendor\/laravel\/framework\/src\/Illuminate\/Foundation\/ProviderRepository.php","line":157}}vagrant#homestead:~/Code/foobooks$
vagrant#homestead:~/Code/foobooks$ cd laravel
-bash: cd: laravel: No such file or directory
Move your database from your host machine into homestead:
Install laravel homestead
Copy your app into your shared folder (I guess you did that so far)
backup your database from your host machine
Migrate your database in homestead with artisan migrate if you want a clean and empty database structure.
OR: Rebuild it from your backup. Make sure the database user/password specified in your laravel config exists in homestead and has write access to your rebuild database.
Your homestead database is still accessible from your host machine at 127.0.0.1 and port 33060 (http://laravel.com/docs/4.2/homestead#daily-usage)
Here is a nice tutorial for homestead 2.0 in case you have problems to setup: https://laracasts.com/lessons/say-hello-to-laravel-homestead-two

Resources