Is it possible to run homestead with an older version of PHP and Laravel 4.1? I need to set up my VM to replicate our production server, as closely as possible.
I find myself in 2021. According to the official docs and with the current Laravel homestead v10.17.0 you have the possibility to explicitly set the PHP version required right at the Homestead.yml file:
sites:
- map: homestead.test
to: /home/vagrant/project1/public
php: "7.1"
- map: project2.test
to: /home/vagrant/project2/public
php: "5.6"
- map: default.test
to: /home/vagrant/project1/public
Then, don't forget to apply the changes with
% vagrant provision
Moreover, you could change dynamically the PHP version used in your Laravel Homestead Ubuntu virtual machine
$ sudo update-alternatives --config PHP
$ php -i | grep "Loaded Configuration File"
$ php -v
But that only works for composer update, it doesn't seem to work for an application. So changing the Homestead.yml file is the way to go.
Homestead is just a prepackaged version of Vagrant with PHP5.6, ngnix, mySQL etc already installed and configurable.
If you need a specific environment that is "different" to Homestead, you just create your own Vagrant environment with a bashscript that installs the versions of software that closely matches your production environment.
This guide here provides specific information for Laravel - but any Vagrant guide will be able to help.
Related
I know this question may be overlapping but I have tried most of all answers in online that I could find. But no success so far. So, anyone please help me out.
I am new to both Homestead and Laravel. This is my configuration and details about installation below:
Homestead 7 installed
Vagrant 2.0.3 installed
Composer 1.6.4 installed
Oracle VM VirtualBox 5.2.8 installed
git bash 2.16.1.windows.4 installed
Windows 10 O/S is my Main base O/S
On VirtualBox Manager I got these data=> Name: homestead-7, O/S: Ubuntu (64-bit), Base Memory: 2048 MB, Boot Order: Hard Disk, Optical, Acceleration: VT-x/AMD-V, Nested Paging, PAE/NX, KVM Paravirtualization..... so on
In c:/Laravel_P folder I installed Laravel using Composer in Git Bash:
cd /c/Laravel_P
composer create-project --prefer-dist laravel/laravel wetest
After about command, i got 26.3 MB wetest folder in Laravel_P folder, which was successful installation of Laravel.
Then I backdown from folders to my root by cd command and go to Homestead folder by cd Homestead. After I enter the Homestead folder, I run command:
vagrant up
This runs my Homestead Vagrant successfully (I checked in VB) and when processing this command no any error was shown.
I change my homestead.yaml file to this as my system placements.
authorize: C:/Users/my_user/.ssh/id_rsa.pub
keys:
- C:/Users/my_user/.ssh/id_rsa
folders:
- map: C:/Laravel_P
to: /home/vagrant/code
sites:
- map: homestead.wetest
to: /home/vagrant/code/wetest/public
Also changed my host file and saved the change:
127.0.0.1 localhost
::1 localhost
192.168.10.10 homestead.wetest
Then i run another command:
vagrant provision
I have tried also vagrant reload --provision command also
Now, when i tried to access my Laravel project from
http://homestead.wetest
I got Error:
This site can’t be reached
homestead.wetest’s server IP address could not be found.
In my knowledge, I tried every step as found in web and documentation in Laravel, but why am I not getting the desired result? Please anyone help me in this.
folders:
- map: C:/Laravel_P
to: /home/vagrant/code
sites:
- map: homestead.wetest
to: /home/vagrant/code/wetest/public
should be to: /home/vagrant/code/public
I can't remember what version was installed and I want to see know but I don't know how. Probably there will be some command to the terminal but I can't figure out.
Can anyone tell me?
Thanks in advance.
For newcomers to Laravel, this depends on what instance of Homestead you're working with (how you've chosen to install Homestead).
Per-project installation
# From your project directory, run this
php vendor/bin/homestead --version
Global installation
# If you've already set homestead in PATH env
homestead --version
# If you haven't
php ~/Homestead/homestead --version
Hope this saves you some minutes.
you can use -v or --version
homestead --version
Versions:
Vagrant: Run vagrant -v to show the version.
Provider: Virtualbox, VMWare or Parallels and it's version.
Homestead: Run homestead --version to show the version.
If you want to check the version of Homestead repository you can check using following command on ~/Homestead
$ git branch -v
and the result would be something like this
* master 09fce4c Tag v10.0.2
and here it is v10.0.2
Whilst trying to use the php-7 version of Laravel Homestead in a per-project installation, I see this error during vagrant up:
php5-fpm: unrecognized service
I've tried vagrant destroy and reinstalling the Vagrant box, but it still comes back to this error.
I didn't get the error when using Homestead globally.
How might this be fixed?
The issue was that whilst box: laravel/homestead-7 was set correctly in Homestead.yaml, the composer dependency for laravel/homestead was still using the php-5 version. This meant that the provisioning scripts for Vagrant in vendor/laravel/homestead were those for php-5 and not php-7.
That can be fixed by using a specific branch of laravel/homestead for the composer dependency.
In composer.json, add a custom repository for laravel/homestead:
"repositories": [
{
"type": "git",
"url": "https://github.com/laravel/homestead"
}
]
And require the php-7 branch specifically for laravel/homestead:
"require-dev": {
"laravel/homestead": "dev-php-7"
}
Then composer update and re-provisioning the Vagrant box will fix the issue.
UPDATE
laravel/homestead now has PHP 7.0 by default, and the old php-7 branch no longer exists. To resolve this issue, you simply need to update to the latest version of laravel/homestead via composer.json.
For a quick fix, I found this answer from laracasts very helpful:
cd ~/Homestead && git pull && vagrant destroy && vagrant box update && vagrant up
To elaborate a bit more on the "just destroy it and build again" approach... I favour this over the various instructions for in-place Homestead upgrades from PHP 5.6 to PHP 7 that are floating around the web - it doesn't take very long and also everything feels "cleaner" when you've finished.
(Of course, if you've made changes to your php.ini or any of the other software, you'll need to do these again.)
Preparation
your projects should in a directory on your host computer that's shared with the Vagrant box, not on Vagrant box only, as that's about to be wiped
vagrant ssh into your VM and put a mysqldump of each site's database in the site directory, e.g. mysqldump -u root -p [dbname] > [dbname]-backup.sql (the default homestead MySQL root pw is secret.)
take a backup of everything (e.g. Mac Time Machine and/or do what I do and keep your projects in a Dropbox folder). You've got your git repository stored somewhere safely too, of course?
Virtualbox users: no harm in exporting the entire box in case you get stuck and want to go bac to it (taking a snapshot isn't enough as any will also be wiped when the VM is destroyed.)
Process
vagrant halt (if you haven't already)
vagrant destroy [VM id] Adding the ID is a precaution against destroying the wrong box. Use vagrant global-status to get a list of your boxes; use 7-character hex code in first column.
in ~/Homestead on your host PC/Mac git pull origin master (as mentioned in the other answer, there's no separate PHP7 branch now)
you can re-run the bash script to create a clean Homestead.yaml file etc. - bash init.sh, but the files it copies are all templates, so you can also not do this and keep your previous versions.
vagrant box add laravel/homestead (now we're back on the standard installation instructions. This'll take about 10 minutes on a VDSL connection.
edit ~/.homestead/Homestead.yaml on your Mac/PC.
Here's an example of the folder mapping if you're confused by the docs:
folders:
- map: ~/Dropbox/websites-homestead
to: /home/vagrant/sites
sites:
- map: site1.app
to: /home/vagrant/sites/site1/public
- map: site2.app
to: /home/vagrant/sites/site2/public
databases:
- site1
- site2
So... my actual code lives in ~/Dropbox/websites-homestead/site1 and /site2 on my computer, and I've mapped their common parent directory to /home/vagrant/sites on the VM. Homestead will create empty databases with the name(s) you list.
vagrant up (this'll provision it)
vagrant ssh
cd sites (you should be able to see your code)
restore databases with `mysql -u root -p site1 < site1-backup.sql
Providing you have /etc/hosts entries on your computer, you should be able to view your site. Check the .env file if it can't connect to the database.
You should now be able to do this:
$sudo service php7.0-fpm status
* php-fpm7.0 is running
$php -v
PHP 7.0.2-4+deb.sury.org~trusty+1 (cli) ( NTS )
[...]
open /etc/nginx/sites-available/your_site_conf then change this line:
fastcgi_pass: /var/run/php5-fpm.sock;
to:
fastcgi_pass: /var/run/php/php7.0-fpm.sock;
And then restart nginx.
Note: This is not a permanent solution, if you run provision command vagrant will try to setting up by itself and will overwrite with the first line.
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 custom one, which is customised to work with several proxies.
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'm running Homestead v2.1.7 on Mac
Thanks in advance!
I know it's an old question, but the problem is still accurate.
There are some circumstances when you have to run two instances of homestead at the same time. For example when you have app that is works with apache, and one that is freaking out when you enable apache on a server. When you enable it on one website in Vagrant.yaml it will redirect every page that is not using apache to the site that is using it, see example:
- map: presta.shop
to: /home/vagrant/htdocs/presta-shop
type: apache
- map: my.app
to: /home/vagrant/htdocs/my-app
In this situation when you will call my.app homestead will redirect you to presta.shop - because this site is using apache (PrestaShop needs to run under apache). See this link: Github NGINX and Apache conflict #555
My my.app will crash with apache enabled, or I just don't want to enable it on this app, or I just need one extra server just for testing or something. You have to follow those steps from install homestead. After the installation of first server you need to:
run VirtualBox (or other machine you are using)
find and rename added homestead box (homestead), to what ever you wish ie: apache_homestead
go to homestead dir (cloned from git)
find file: Homestead.yaml
in Homestead.yaml add new line after provider with name (this is the name of your
renamed box apache_homestead in this case), and ip for let say: 192.168.10.11
in this file you can configure many settings, including name:
ip: "192.168.10.11"
memory: 3072
cpus: 1
provider: virtualbox
name: apache_homestead
After that You may change name of a dir where homestead clone is (default name is homestead). If you rename it to homestead_apache and run vagrant up from this directory you will have completely independent server.
To run "normal" server just follow the instructions from install homestead again and run as many servers as You wish :) Run any just go to it homestead directory and run vagrant up. Remember the limitation of your host machine!
IMPORTANT NOTE!
You can have all files for all servers in one dir, but every server has it's own database!!. So before you will move application to another server export and import it's database!
I am trying to install Laravel for first time. I installed it on my desktop with the following composer command
composer create-project laravel/laravel laravel-app
The command completed successfully without any error but with some messages like
symfony/var-dumper suggests installing ext-symfony_debug ()
symfony/translation suggests installing symfony/config ()
I now did chmod -R 777 larvel-app to make whole folder writable by everyone. I now started php server with following command
cd laravel-app
php artisan serve
and it gave following message
Laravel development server started on http://localhost:8000
When viewed from web browser in address http://localhost:8000, there is nothing, only blank page. When I browse this address, the server seems to quit.
I have following environment:
OSX Mavericks;
MAMP with php 5.4.10 and apache2;
following extensions in php.ini file
extension=imap.so
extension=yaz.so
extension=mcrypt.so
extension=gettext.so
extension=pgsql.so
extension=pdo_pgsql.so
extension=pdo_mysql.so
;;;;;Following are added by me ;;;;no error when starting server
extension=openssl.so
extension=mbstring.so
When I run which php from command line, I get following.
/Applications/MAMP/bin/php/php5.4.10/bin/php
When I tried to run this in mamp ie localhost:8888, it gave 500 internal server error.
Please suggest me, where I might have made mistake.
As a OSX user i strongly recommend you to use Laravel Homestead to develop your applications.
http://laravel.com/docs/5.0/homestead
You only need to install:
Virtualbox
Vagrant
I have my projects in ~/code folder, so everytime i create a new project, i just:
Add project test domain to my local host file (my-project.app pointing to localhost 127.0.0.1)
ssh into the homestead virtualmachine (homestead ssh)
run built in serve command (serve my-project.app /path/to/project/public)
Voilà
The most common reason for this is that the web server process does not have write access to the storage folder and its subfolders.
Set the permissions on the storage folder so that the web server can create files.
You don't have to use php serve, mamp does that for you. Make sure you point your directory to public folder. You can also use custom domain for each of your projects.
Also for Mac there is laravel valet. Easy to get started with many php projects.
I think you should move your Laravel Application to
/Applications/MAMP/htdocs/
and then you can access it on
http://localhost:8888/laravel-app