Using Laravel Homestead for PHP5.6 and PHP7 projects - php

Here at the office we are using Homestead as our local development environment. All projects we had so far were made in PHP5.6. Now we have a new project and we are going to use PHP7. I can't run PHP7 in my current PHP5.6 homestead machine. How can I achieve to run PHP5.6 and PHP7 projects? They do not have to run at the same time, so I if it's possible to change the Homestead.yaml to use a newer version, that would be fine.
What I have tried already was to run vagrant box add laravel/homestead --box-version 1.0.1. This added the 1.0.1 box but when I added version: 1.0.1 to my Homestead.yaml and started vagrant the PHP version was still on 5.6.

In case people find this post - the answer has changed.
If you run Homestead v6 or above - you automatically get multiple PHP versions installed by default.
In your Homestead.yaml file you can set the version:
sites:
- map: homestead.app
to: /home/vagrant/Code/Laravel/public
php: "5.6"
In addition, you may use any of the supported PHP versions via the CLI:
php5.6 artisan list
php7.0 artisan list
php7.1 artisan list
Check the Laravel docs for more info: https://laravel.com/docs/5.4/homestead#multiple-php-versions

The latest Laravel-Version with Homestead including PHP 5.6 is Laravel 5.6. See https://laravel.com/docs/5.6/homestead for details and installation instructions.
Use the following commands during installation to get this Homestead-Vagrant-Box:
vagrant box add laravel/homestead --box-version 6.4.0
git clone https://github.com/laravel/homestead.git .
git checkout v7.20.0
This Homestead-Version supports PHP 5.6 to 7.3.
(More details in german: https://blog.dmr-solutions.com/blog/homestead-vagrant-box-mit-php-56)

Found a solution! I followed this tutorial. I can run a PHP 5.6 and a PHP 7 Homestead. The only thing I had to do (I already have a PHP 5.6 homestead configured) was:
Clone the latest homestead version in a Homestead-7 folder (or a different name) by running git clone https://github.com/laravel/homestead.git ~/Homestead-7
Go into this directory and run bash init.sh and answer no to all questions.
That's it! You might have to upgrade your vagrant (mine was too old) but that's easy to do by just downloading the latest version on https://www.vagrantup.com/downloads.html (Do not forget to run vagrant provision in Homestead-7)

I like to add to Laurence answer.
After adding php5.6 to Homestead.yml, you cannot simply do "vagrant up --provision". It will not work. You have to actually destroy the vm by running command "vagrant destroy" and recreate back the vm.
So before destroying the vm, better to backup every database you have in there. I do this by dumping all the sql in Code folder. Later after I run the command "vagrant up" I can simply ssh to my vm and go to mysql and run "source dump.sql" in mysql command line again.

Related

Enquiries - Laravel website migration steps

I got a website running with laravel framework, this website will need to migrate to public cloud VM. However, I'm not quite familiar with laravel, any suggestion and advice would be appreciated.
I already created a remote VM, and installed Nginx.
Also, I move the root folder from on-prem /var/wwwroot to the cloud /var/wwwroot as well. Moreover, the Mysql database had been imported to the cloud Mysql too (using the dumped .sql file ).
laravel need PHP to run, should I install php5.6 or php5.6-fpm (or both)?
I need to install laravel framework, do I have to install the specific version of lavavel (5.1.46)?
After I install the laravel, do I need to conduct any laravel command such as
~#php artisan migrate ? or just put the wwwroot folder's file should be enough?
Here is more info about the on-prem VM:
~#php --version
PHP 5.6.32-1+ubuntu16.04.1+deb.sury.org+1 (cli)
~#nginx -v
nginx version: nginx/1.13.6
~# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.3 LTS
Release: 16.04
Codename: xenial
~# php artisan --version
Laravel Framework version 5.1.46 (LTS)
~# mysqld --version
mysqld Ver 5.7.20-0ubuntu0.16.04.1 for Linux on x86_64 ((Ubuntu))
Tony.
You want to use NGINX as webserver, so you need to install both packages.
If you install your code from git, you should install dependencies by running command:
php composer install
You should create your .env-file and edit it: set up db connection params and other settings:
cp .env.example .env
Also you should generate app key:
php artisan key:generate
If you copied last version of your db, you don't need to run up migrations, but I recommend you to run new migrations, to be confident that db structure wasn't changed since you make dump.
php artisan migrate

How Can I install OctoberCMS with PHP Version 5.x?

I have Windows 10, Xampp installed with PHP Version 5.x and I want to install OctoberCMS with Installation wizard https://octobercms.com/docs/setup/installation but I noticed that OctoberCMS requires PHP 7.0 or higher to achieve this and I have version 5.x.
So How can I install OctoberCMS with PHP Version 5.x ?
OK Guys, Eventually I have come up with the solution to install OctoberCMS with PHP Version 5.x.
Remember, these steps can be varied based on your operating system and the things which you have installed in your system.
First go to OctoberCMS Change log -
https://octobercms.com/changelog and find Build 419 has the php
version 5.x support.
Then go to OctoberCMS release list - https://github.com/octobercms/october/releases and click on the version you need to install which is v1.0.419. Install the zip to the root of xampp/htdocs and extract the folder.
Then inside the same folder which extracted, run this composer install.
After this, run php artisan october:env .. You can run C:\xampp\php\php.exe artisan october:env if you are having an error php is not recognized as an internal or external command.
After php artisan october:env, .env file is created. There you need to modify your database settings like database name, port (put 3306 for localhost etc) by opening this file which will be in same folder.
Then run php artisan october:up or C:\xampp\php\php.exe artisan october:up. It will create database tables and your admin user will be created with User: admin, Password: admin (You can change this after logging IN). And backend url will be something like http://example.com/backend.
Once its done, you can cut paste all your extracted folder files to root .. like from C:\xampp\htdocs\youproject\version419 to C:\xampp\htdocs\youproject\.
Hope this helps.

Laravel: How to install php7 with Homestead

I m a newbie and learning Laravel. I m having a trouble with install php and homestead.
As I read in Laravel Official Website:
Laravel Homestead is an official, pre-packaged Vagrant box that provides you a wonderful development environment without requiring you to install PHP, a web server, and any other server software on your local machine.
So I think I do not need to install php in my local machine ??? But when I install composer, it requires PHP.exe and I cannot browse that PATH. I misunderstand here. I have been stuck in this problem and research many websites for whole day, so I think better to ask (even if it is stupid question). Could anyone explain for me please...
---EDIT_NEW---
This is my completed steps to use Laravel:
Install git
Install virturalbox
Install vagrant
vagrant box add laravel/homestead
git clone https://github.com/laravel/homestead.git Homestead
cd Homestead, bash init.sh
Configure Homestead
add to Hosts file
Now I have to install laravel, it requires composer. Composer installation requires php.exe PATH. But if I dont use XAMPP or others local development environment, how can I install Composer ?
(Note: Maybe I misunderstand here "without requiring you to install PHP, a web server, and any other server software on your local machine").
Are you executing composer "inside" Homested vagrant VM or in windows "cmd"? In the first case it's strange in the second of course it doesn't work. You need to acces the Homestead VM via SSH
Thanks for help, with your answers and Laracast Video: https://laracasts.com/lessons/say-hello-to-laravel-homestead-two. Now I got the answer.
You need to follow some steps to running Laravel in your system (windows 10).
1) Install XAMPP or WAMPP, you can download XAMPP from Here.
2) Install composer, find it from Here.
3) Install GIT (optional).
Than go for create New Laravel App.
1) Open Terminal -> goto C:/xampp/htdocs/
2) composer create-project laravel/laravel <App_Name>
3) php artisan serve

Installing multiple Laravel homestead environments

I was wondering how I would be able to run multiple versions of homestead without having VirtualBox crash.
I am currently running a default installation of the laravel homestead, but I need to install another older version, the reason is that in current version 0.4.0 the mysql server is 5.7 which is fine, but i need another environment with 5.6 because i have an old project which requires 5.6, so homestead version 0.3.0 would be fine.
Just to be clear: I know how to run multiple sites. That is not the issue. I just want to run a second, custom version of the Laravel Homestead Vagrant box, while still having the possibility to run my normal one.
Details: i managed to add both versions. Output of:
vagrant box list
laravel/homestead (virtualbox, 0.3.0)
laravel/homestead (virtualbox, 0.4.0)
so version 0.4.0 is running fine, now how i can run 0.3.0 ?
Thanks in advance!
Ok i managed it.
I will post the solution for those who faced this issue, because I was not able to find a step by step guide with a homestead related instructions.
Without too much theory the steps are:
Decide which box version you need from here (https://atlas.hashicorp.com/laravel/boxes/homestead), in my case it was 0.3.0 and run
vagrant box add laravel/homestead --box-version 0.3.0
Find on github the propper release of homestead (https://github.com/laravel/homestead/releases) in my case it was (v2.1.8)
and download and extract it to a directory for example Homestead2 in your home folder
Inside Homestead2 directory find scripts/homestead.rb file and edit it.
find lines
config.vm.box = settings["box"] ||= "laravel/homestead"
config.vm.hostname = settings["hostname"] ||= "homestead"
between them add line, in my case :
config.vm.box_version = "0.3.0"
you can also rename
vb.name = settings["name"] ||= "homestead"
if you wish
from within this directory run vagrant up
after this you can use it as usual.
I hope this helps somebody.
There's an option for running a box with version in Vagrantfile.
In your case you need to add box_version to your Vagrantfile similar to this:
Vagrant.configure('2') do |config|
// This line
config.vm.box_version = 0.3.0
end
You can check it out from documentation.

Homestead Installed PHP7 but I need PHP5

Homestead randomly stopped working for me, so I tried to remove the whole thing and reinstall, but it's not gone well.
I have it "running" after a day and a half of muddling my way through various issues. However, for reasons that I cannot understand, my Homestead box is now running PHP 7.
The instructions I was following had optional options for installing PHP 7, but I intentionally skipped that because we are on PHP 5.
For the life of me, I can't figure out how to fix this. Things I have tried:
I have destroyed and reinstalled the box multiple times.
I have deleted the VirtualBox box multiple times and redownloaded it.
I tried installing v0.3.3 of the box based on one suggestion. (I also updated the homestead.rb script accordingly.) At one point, something failed during the install process with php7.0-fpm: unrecognized service and the configured sites were returning 502 Bad Gateway errors.
After reinstalling with v.0.4.0, it has started "running" as I described (serves the sites as expected, etc.), but with PHP 7.
Searching for solutions has persistently led to a dead-end.
I'm just a dummy front-end developer. :) Laravel, Vagrant, Homestead, all this stuff makes my head hurt. I just want this to work again so I can go back to my actual work. Any advice or alternate avenues of pursuit for researching this problem would be appreciated.
I've been through this issue too and I solved it by installing an old homestead box v0.3.3 and I've used an old release of homestead installer, so I suggest that you remove your current box v0.4.0 and delete your homestead folder then do this:
$vagrant box add laravel/homestead --box-version 0.3.3
and then download an older version of Homestead installer from git, I'm using v2.1.8 it works fine.
Enjoy php 5.6 :)
I had a similar problem where I tried to upgrade Homestead to the most recent Homestead 7.0 box and configure it to run PHP 5.6 instead of PH7, which various sources said was possible via adding a line to the .yaml file specifying the PHP version.
sites:
- map: myproject.local
to: /home/vagrant/Code/craven/public_html
php: "5.6"
What actually happened when I tried that was that I got a 502 CGI gateway error. Here is a summary of the steps I had to take to fix it:
1) SSH into the Homestead virtual machine.
ssh vagrant#127.0.0.1 -p 2222
Taking a look at the nginx error log in /var/log/nginx/ reveals that the PHP 5.6 files the server is looking for don't exist.
You can get confirmation of this by having a look at the executables.
ls -la /usr/bin/php*
2) To install PHP 5.6, run
sudo apt-get update
sudo apt-get install php5.6-fpm
You can confirm that the php 5.6 service is running via the command
service --status-all
3) Once all this is working, refresh the web page for your site and it should now work. In my case, because I was running a Laravel 4.2 site, I then to install Mcrypt:
sudo apt-get install php5.6-mcrypt
4) In order to get my mysql database up and running, I also had to install mysql.
sudo apt-get install php5.6-mysql
And of course after all that, I had to re-import the database contents from the file I'd exported before upgrading the Homestead box.
Note that if you ever destroy and recreate the Homestead box, you will need to repeat all these steps again.

Categories