Should I use homestead for an exact Laravel replication? - laravel

My client is running Laravel 5.2 and PHP version 5.6 (all obviously several years old).
I tried to clone the git into Valet with relative success in that the application ran but a bunch of pages threw errors which I am certain is due to me running the latest version of PHP.
So, my question is it better to directly clone the project on Homestead?
Does Homestead offer a more "native environment" for a situation like I am in?

you should try to use an environment that is the closest possible to production.
If your customer uses apache, try xampp. Else adapt to his environment and PHP version, so you can concentrate on code production instead of keep the solution working on more than one environment.

One year later, I came across with the exact same problem; php 5.6.31 and Laravel 5.2.
I managed to simulate the environment with homestead 6, following these steps:
copy the project files to a new folder
Unzip php 5.6 to my local pc (remove php7)
run: composer update (must run with php 5.6 on local pc)
run: composer require laravel/homestead:~6.6.0
run: vendor\\bin\\homestead make
edit Homestead.yml as needed (.ssh path, add php: "5.6" one line below the site sync)
run: vagrant up
run: vagrant ssh
make appropriate changes (google them) according to problems faced on homestead.test (edit xdebug for 502 BAD GATEWAY, edit my.cnf for adding utf8, etc)

Related

using Doctrine in localhost works well but after uploading to C-panel, below error accrued

Uncaught Error: Class "Symfony\Component\Cache\Adapter\ArrayAdapter" not found,
but Symphony cache and Doctrine cache has been installed,
my composer.json:
"doctrine/orm": "^2.11.0",
"doctrine/dbal": "^3.2",
"doctrine/annotations": "1.13.2",
"symfony/yaml": "^5.4",
"symfony/cache": "^5.4"
This is most likely because of version differences between your local and hosted environments, e.g. you might be running PHP 7.x locally and PHP 8.x on your hosted environment. This can be a bit of a struggle. The key things you need to know are:
composer.json keeps a list of packages that you have said that your project needs. This is usually listed as point revisions, e.g. 1.x, 2.x, 3.x
composer.lock lists the EXACT versions of the package that was installed when the composer install (or composer upgrade) command was used, e.g. 1.2.3
vendor/ is the resulting folder that was installed as the result of running composer install
When there is no composer.lock file, or composer upgrade is run, then composer will fetch the latest version of the available libraries based on the current environment, e.g. your local machine. If you then pick up the vendor/ folder and upload it to your hosted environment, it may contain code that isn't compatible with the environment there.
I see people recommending to delete the composer.lock and vendor folder on the production machine, and then run composer install again. This is likely to resolve the issue, but it glosses over the fact that the code you're running in production is then different to what you were developing locally. On shared hosting it may not be immediately obvious how to run composer install as you may need access to a shell (e.g. SSH connection)
There are two ways forward - either:
use your control panel to change the PHP version for your site to a version that you are running locally
change your local dev environment to run the same version of PHP that your hosting environment is running
Be sure to always run the same version of PHP on dev and production to avoid these kinds of problems, and take the time to understand the purpose of composer.lock and how it is used to populate the vendor/ folder with the exact code based on your current PHP version.

DDEV/Laravel/PHPUnit: Problems with setup in PhpStorm

Using Laravel with DDEV/Docker on a Mac, I am stuck getting PhpStorm to run directly PHPUnit with coverage. I am following these instructions: https://ddev.readthedocs.io/en/stable/users/topics/phpstorm/
I started the setup with
curl -s "https://laravel.build/myproject?with=mysql,redis,memcached" | bash
Everything's is working fine, including debugging with Xdebug after I turned on Xdebug with
ddev xdebug on
PHPUnit works fine via console as well:
ddev exec phpunit
Composer version is 2.1.4.
Following the instructions named above, I am stuck at point 6.
What am I missing out? PHPUnit is located within the directory and it is composer-installed as well:
With composer version 2.2 the phpunit executable in vendor/bin is not a symlink anymore. It‘s a PHP file which includes the original executable with help of stream-wrapper, but including phpunit is not allowed: https://github.com/sebastianbergmann/phpunit/issues/4096#issuecomment-585900398
The bug is solved in composer:
https://github.com/composer/composer/issues/10387#issuecomment-1000246631
Use the following to get the latest dev version until this fix was official released:
composer self-update --snapshot
Further you can configure PhpStorm to use the original file instead:
vendor/phpunit/phpunit/phpunit
Thanks to all of you guys, I really appreciate your help.
Here is how I solved it:
I installed ddev-edge to avoid composer 2.1.x. I could not change it to 2.2 in config.yaml without failing ddev to restart when using stable version of ddev. It only worked on an active docker instance.
Then configurated ddev to use latest PHP-version 8.1 (for a new project from scratch, it makes sense anyway).
Then the error with PHPUnit changed to an error telling me that the PHP version is too old for the PHPUnit version. That was because PHPStorm automatically picked PHP 7.4 as default when connecting to Docker and checking the CLI remote interpreter.
So I changed the PHP executable from "php" to "php8.1"
See screenshots.
Now running PHPUnit from PHPStorm works fine, even with coverage.

Unable to configure Homestead per-project with Laravel 6 on PHP <7.1

I'm setting up a Laravel 6 project to use Homestead per-project, but running into a Catch-22 when cloning the repo on a machine without PHP 7.2 installed locally.
The issue is that Laravel 6 requires PHP 7.2 (I have 7.1 installed locally), which means composer update will not work locally:
This package requires php ^7.2 but your HHVM version does not satisfy that requirement.
which means I cannot vagrant up to get to the Homestead box (that includes PHP 7.2) without having run composer update:
Message: LoadError: cannot load such file -- /Users/.../.../vendor/laravel/homestead/scripts/homestead.rb
which means I cannot get anything working.
To get around this, I either have to a) upgrade my local machine to PHP 7.2 to be able to run composer update or b) install Homestead separately and run vagrant up from there, both of which bypass the benefit of a per-project set up.
Is there something I'm missing to get this configuration to work?

Is Laravel/Homestead can be used on other PHP frameworks?

I am not yet used Laravel and I am just curios if the Homestead can be used on other PHP frameworks like CodeIgniter?
Homestead runs on Ubuntu within a Virtual Machine. It comes with the following software installed:
Ubuntu 14.04
Git
PHP 7.0
HHVM
Nginx
MySQL
Sqlite3
Postgres
Composer
Node (With PM2, Bower, Grunt, and Gulp)
Redis
Memcached
Beanstalkd
Pretty much anything a webserver needs to run any kind of PHP framework. If there's something missing for the framework you're using, you can install it.
You can of course use it for any php related project. But be careful when configuring the Homestead.yaml file to correctly set the path to your projects.
sites:
- map: laravel.app
to: /home/vagrant/Code/laravel/public
- map: codeigniter.api
to: /home/vagrant/Code/codeigniter
You can also setup multiple databases if you need to.
Simply don't forget to run bash init.sh and vagrant provision each time you modify the config file.

Laravel installed but confusion remains

I have ubuntu 14.04 and LAMPP is installed. I was learning Laravel 4, but get a lot of confusion on it's documentation, below I list few of issue.
How to install laravel?
what I did :
copy github repository into /opt/lampp/htdocs/larva and run composer install, Laravel is installed and I can access it with http://localhost/larva
What is homestead? is that another way to install laravel or this is additional thing?
What is artisan? if I use artisan then do we need to use homestead also?
what I did ( in terminal )
cd /opt/lampp/htdocs/larva
php artisan serve
it started the service and I can access laravel with htpp://localhost:8000 BUT if i close this terminal then URL is lost
and there is one other way is using vagrant? do we need to use vagrant if we installed it already?
one more thing is Nginx?
overall these vagrant, Nginx, Homestead, artisan,and composer methods create such a mess.
Please clear the clouds and please do not mention what is vagrant Nginx and all. I just want to know that do I need to do something with Homestead and vagrant if i have installed using git repository and composer way?
Thanks
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.
Artisan is the name of the command-line interface included with Laravel. It provides a number of helpful commands for your use while developing your application. It is driven by the powerful Symfony Console component.
When you close the terminal, you are stopping the service on port 8000. You always can create a virtual host, and point its root to your larval installation /public directory
you dont have to use vagrant to run laravel. Vagrant is just your 'bridge' to Virtual Mashine.
If you installed LAravel via composer and you got it work on localhost:8000 then you dont need neither homestead or vagrant

Resources