Redis does not start on boot on homestead vagrant server - laravel

I know that we can directly ssh into the VM & enable the redis service.
But i think there must be a way to enable redis using homestead.yaml.
I tried to search for docs but i couldn't find anything.
EDIT
I'm posting my homestead.yaml file.
ip: "192.168.10.10"
memory: 1048
cpus: 2
provider: virtualbox
authorize: C:\Users\stack\.ssh\id_rsa.pub
keys:
- C:\Users\stack\.ssh\id_rsa
folders:
- map: W:\sites\project
to: /home/vagrant/project
sites:
- map: project.test
to: /home/vagrant/project/public
databases:
- homestead
features:
- mariadb: false
- ohmyzsh: false
- webdriver: false
I have installed predis so the connection with redis is not an issue.
Everytime i boot my vm, I manually have to go & start redis by typing this command systemctl start redis-server.
Which is the reason i was wondering that there must be a way to enable redis server from inside the homestead.yaml so i don't have to do it manually.

If you want homestead's redis server to start automatically whenever homestead is up...
Log into homestead via ssh.
sudo systemctl enable redis-server
You should only need to run this once.

There was a Bug with this version of Homestead 10.0.1
Redis does not start on boot.
However this has been fixed if you check out the issue i have linked.
Still an issue?
Here is a quick fix while waiting for homestead box update
sudo service redis-server start

Redis is already included/installed thus enabled in Homestead. See included softwares of Homestead.
To test type redis-cli and ping in your command line (inside vagrant)
For predis just run composer require predis/predis.

Try adding services section to your homestead.yaml after features section, but I don't know if order matters.
services:
- enabled:
- "redis-server"
Then vagrant reload --provision

Related

Why Homestead is running apache by default even if not specified?

I have a Homestead VM with multiple nginx sites and a couple of apache sites too, everything configured through the Homestead.yaml file (short example below):
sites:
- map: site1.local
to: /home/vagrant/site1
php: "7.1"
#type: "apache <= (commented on purpose, not an error)
- map: site2.local
to: /home/vagrant/site2
php: "7.1"
I've been working turning On and Off the type: "apache" setting so the VM starts running apache (instead of nginx) or not, depending on the site that I need to work on at the specific moment.
My Issue now is that, after upgrading Vagrant and Homestead, it always keeps starting apache by default, no matter if it is specified or not, ALWAYS!; so everytime I start the machine, I need to ssh-it and flip the server.
I even tried using the services config directive as follows, without luck:
services:
- enabled:
- "nginx"
- disabled:
- "apache2"
Any thoughts? Please help!
Versions I am using:
Vagrant 2.2.7
Homestead 10.8.0
I had a similar issue. It turned out that I needed to log in the VM through SSH, and run the following command:
sudo systemctl enable nginx.service
When you look at restart-webserver.sh in the Homestead scripts directory, you will see that it verifies whether nginx is enabled, otherwise it always tries to restart Apache.

Laravel Homestead and vagrant don't create the folder inside vagrant box

I use Laravel Homestead for one year it all was good before I had decided change php version.
Firstly I update vagrant. Secondly I executed all commands from updating guide
vagrant destroy
git fetch
git pull origin release
vagrant box update
vagrant up
After vagrant up I saw that my databases were not created and my folder was not mounted (http://joxi.ru/Vm66DpgF410M5m).
I tried to connet via vagrant ssh, but there is not folder "code"
My Homestead.yaml
ip: "192.168.10.10"
memory: 2048
cpus: 1
provider: virtualbox
authorize: ~/.ssh/id_rsa.pub
keys:
- ~/.ssh/id_rsa
folders:
- map: /home/ubuntu/PhpstormProjects/fntr
to: /home/vagrant/code/fntr
schedule: true
sites:
- map: fntr.test
to: /home/vagrant/code/fntr/public
php: "7.4"
databases:
- homestead
- testing
- imports
- prod_copy
I tried use vagrant destroy && vagrant up. I also tried vagrant reload --provision.
I have found the same issues in google and github, but this advices (http://joxi.ru/52a53oGUEBZMZ2 and other) did not help me.
I have the latest versions of vagrant and homestead.
I think that schedule: true not belongs to folders but to sites, try to remove it and run vagrant reload --provision.
I have found solution. But I am not sure that it is solution exactly.
I just reinstalled laravel homestead. Yes, I deleted homestead folder and went via instalation tutorial again.
Then I pasted my old Homestead.yaml and init vagrant box again.
Note if you want to try this method do not forget copy all of your after.sh, homestead.yaml and other files which can be lost

Laravel homestead 502 bad gateway

Everytime i go to my project I get a 502 bad gateway. When I refresh, the page works.. If I click a link to another page I get 502 bad gateway again. After the refresh the page loads. What could be the problem here.
Homestead.yaml
---
ip: "192.168.10.10"
memory: 2048
cpus: 1
provider: virtualbox
authorize: c:/Users/MyNameHere/.ssh/id_rsa.pub
keys:
- c:/Users/MyNameHere/.ssh/id_rsa
folders:
- map: c:/Users/MyNameHere/Desktop/sites
to: /home/vagrant/code
sites:
- map: spa.test
to: /home/vagrant/code/spa/public
databases:
- homestead
Got the latest version for virtualbox and vagrant.
My spa folder contains the newest version laravel.
Login to Laravel Homestead Server with PuTTY and Private Key File.
then...
cd /etc/php/7.4/mods-available
sudo nano xdebug.ini
Comment out the first line
;zend_extension=xdebug.so
xdebug.remote_enable = 0
xdebug.remote_connect_back = 1
xdebug.remote_port = 9000
xdebug.max_nesting_level = 512
Then restart PHP-FPM
sudo service php7.4-fpm restart
Had the same issue with the latest version of homestead.
After digging in log files and then github issues for homestead, I found this this.
There's an issue with xdebug that they're waiting for a fix for. The solution is to disable xdebug or use php 7.2. I opted for the latter. In that case, make the following change in your homestead.yaml and then running vagrant reload --provision will fix this.
sites:
- map: spa.test
to: /home/vagrant/code/spa/public
php: "7.2"
I was having the same problem and I couldn't change the PHP version or disable xdebug, but I could and did change for the Apache server.
sites:
- map: spa.test
to: /home/vagrant/code/spa/public
type: "apache"
I had a similar issue, got the 502 error. Refreshing the browser or reloading the virtual machine had no effect.
I solved disabling the Xdebug. Found the solution here: https://christattum.com/disabling-xdebug-in-laravel-homestead/
On prompt:
cd /etc/php/7.4/mods-available
sudo vi xdebug.ini
Commented all the lines of the file with ;
Run the vagrant reload --provision command to the Homestead file in the virtual machine, and then after vagrant up, enter with vagrant ssh. Your problem will be solved :)
You can change your ip post adress and write 127.0.0.1 in your host file.
You can enter it by adding 8000 next to the project name in the search engine.
For example spa.test:8000 and then running vagrant reload --provision will fix this.
I lost 3 days trying to solve the same issue.
My mistake was to have defined in my host file something like:
127.0.0.1 spa.test
The solution is to add instead, the same IP you specified in Homestead.yaml.
192.168.10.10 spa.test
to /etc/host (In case of Mac)
to C:\Windows\System32\drivers\etc\hosts (in case of Windows)
Even if you have multiple hosts defined in your global Homestead.yaml file.
For instance
folders:
- map: /Users/davidecasiraghi/Projects/my_laravel_project
to: /home/vagrant/code/my_laravel_project
- map: /Users/davidecasiraghi/Projects/spa
to: /home/vagrant/code/spa
sites:
- map: my_laravel_project.test
to: /home/vagrant/code/my_laravel_project/public
- map: spa.test
to: /home/vagrant/code/spa/public
Then in the host file:
192.168.10.10 spa.test
192.168.10.10 my_laravel_project.test
Then when you will do vagrant up you will be able to access to both of them.
For me this was related to Xdebug, which doesn't seem to yet be compatible with PHP 7.3.
To continue using 7.3, you can turn Xdebug off with
sudo phpdismod xdebug
restart php service
sudo service php7.3-fpm reload
For Chinese,
if you are using Clash for Windows,
then edit "Bypass Domain".
It's not relevant to this question,
but Google lead me here,
Do this inside your Homestead VM vagrant ssh
Check your php version
$ php -v
Edit your website config file
$ sudo nano /etc/nginx/sites-available/<laravel.app>
line
fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
change according to your php version
mine was php8.2-fpm.sock; then I change it to php8.1-fpm.sock; press ctrl+x to save, then
$ sudo service nginx restart
$ sudo service php<ver>-fpm restart
reload the page

Configure Laravel environment just once and use it for further app developments

I am pretty new to Laravel and just started with development of my first application in the framework. I had started learning it a while ago and faced n number of issues while configuring the test application. It had been a long time and I can't find all the notes I had made while I faced issues.
So my problem is this time I want to configure my environment and create a package or a container so that I get it up and running next time when I want to develop more apps in future. Is there any way to achieve it?
If you want a clean and complete development environment for laravel and spare yourself of configuring everything on your local OS and Be able to have the same configuration somewhere else on another machine, I'd recommend using homestead which you can find it's documentation Here.
Steps are easy you basically install vagrant and VirtualBox or VMWare. (I recommend VirtualBox). Then install homestead by following the Per Project Installation section of the docs and you're gonna have a Homestead.yaml file in your laravel installation. Which is going to look something like this :
---
ip: "192.168.10.10"
memory: 2048
cpus: 1
hostname: myhost
name: myhost
provider: virtualbox
authorize: ~/.ssh/id_rsa.pub
keys:
- ~/.ssh/id_rsa
folders:
- map: "/Path/To/Project/myapp"
to: "/home/vagrant/myapp"
sites:
- map: my.app
to: "/home/vagrant/myapp/public"
databases:
- mydatabase
# blackfire:
# - id: foo
# token: bar
# client-id: foo
# client-token: bar
# ports:
# - send: 50000
# to: 5000
# - send: 7777
# to: 777
# protocol: udp
Edit this file to your settings and save it for future use. Then just add my.app *Your.Ip.Add.ress* to your OS hosts file which you're gonna find the guide on how to do that in the docs as well.
Finally run vagrant up in your project root and have everything setup!
Just type my.app or whatever you set it up to be and your laravel website comes up.
You can ssh to this virtual server installation with vagrant ssh command.
Database username is homestead and password is secret by default. you can change all of this yourself in the virtual server.

Laravel Homestead 2.0 Adding New Sites

Homestead 2 is awesome, but I can't seem to get new sites to work without going through the following process.
I do homestead edit to setup the new site paths and domains etc
I edit hosts to set up the domain
I do homestead halt then homestead up to restart
This is when I think things should be working... but they don't. I have to run the additional step of
Running vagrant global-status getting the id and running vagrant provision <id>.
Everything works except running provision again wipes out all the databases! How do I add new sites without having to provision again?
Instead of step 3 use vagrant provision in your homestead directory (~/.composer/vendor/laravel/homestead/).
As I know Taylor is already planning a "provision" flag, until that you can feel free to use vagrant commands.
this works for me
homestead halt && homestead up --provision
Here is my ~/homestead/.Homestead.yaml file, it contains a configuration for two apps, one with HHVM enabled and one with HHVM disabled(default in homestead).
Homestead will create the database for you in MySQL and PostgreSQL server, when running homestead up.
---
ip: "192.168.10.10"
memory: 2048
cpus: 1
authorize: ~/.ssh/id_rsa.pub
keys:
- ~/.ssh/id_rsa
folders:
- map: ~/Projects
to: /home/vagrant/Projects
sites:
- map: jobs.app
to: /home/vagrant/Projects/jobs/public
- map: messages.app
to: /home/vagrant/Projects/messages/web
hhvm: true
databases:
- jobs
- messages
variables:
- key: APP_ENV
value: local
You can now run:
$ homestead up
and then:
$ homestead ssh
and then run byobu(for tmux):
$ byobu
and cd into the project:
$ cd Projects/jobs
and run composer:
$ composer update

Resources