How to use different versions of Laravel (4 to 9) on Laragon
Published: 2022-11-02 08:50:40

I am going to share how I managed to get an existing Laravel 4 project up and running on Laragon 6 on Windows.

**PROBLEM**
I have a website created long time back using Laravel 4 and another website created in Laravel 9. While the new website worked fine on Laragon 6, the old one wouldn't work due to the following reasons:

1. Laravel 9 uses php 8+ but Laravel 4 can only use up to php 7.0.
2. The bundled composer in Laragon 6 wouldn't run for php lower than 7.2
3. MySQL 8.0 that comes with Laragon 6 by default uses *caching_sha2_password* instead of the older *mysql_native_password*.

**SOLUTION**
**Step 1. Install the latest version of Laragon:** 
Take backup of your existing Laravel 4 project and completely uninstall any previous version of Laragon. Install Laragon 6 [Download Link](https://github.com/leokhoa/laragon/releases/download/6.0.0/laragon-wamp.exe).

**Step 2. Move your existing Laravel 4 project to Laragon:**
Create a new Laravel project in Laragon with the same name as the existing Laravel 4 project (menu > quick app > Laravel). This will create a Laravel 9 project along with setting up its corresponding database and other necessary plumbing. Replace the contents of the folder with that of the existing Laravel 4 project.

**Step 3. Add php 7.0.33 for the Laravel 4 project:**
1. download php-7.0.33-Win32-VC14-x64: [Download Link](https://windows.php.net/downloads/releases/archives/php-7.0.33-Win32-VC14-x64.zip)
2. Extract the contents in **laragon\bin\php** . This is what my folder looks like.
![New Php installation](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/slk9vkrw88mpm33ndlrh.jpg)
3. We also need to install a compatible Apache to work with php 7.0. Download httpd-2.4.41-win64-VC14.zip [Download Link](https://home.apache.org/~steffenal/VC14/binaries/httpd-2.4.41-win64-VC14.zip)
4. Extract the contents in **laragon\bin\apache** . This is what my folder looks like.
![New Apache installation](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rrf3ntjqn1tapxs4na12.png)
5. You now have PHP 7 as well as PHP 8. To run your laravel 4 project you must switch to PHP7. To switch to PHP 7 open Laragon and select Menu > Php > Version > php-7.0.33-Win32-VC14-x64 and now change Apache Menu > Apache > Version > httpd-2.4.41-win64-VC14

Change PHP
![Change PHP in Laragon](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k1a15dse10xz20rtz3dc.png)
Change Apache
![Change Apache in Laragon](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1htl67h2mfu19dxa8t2k.png)

After switching to PHP7 if you run `composer -v` in the terminal you'll be greeted with the following message: `Composer 2.3.0 dropped support for PHP <7.2.5 and you are running 7.0.33, please upgrade PHP or use Composer 2.2 LTS via "composer self-update --2.2". Aborting.` 

Either you can downgrade to an older version of composer by running `composer self-update --2.2` in the terminal. or you can install composer 2.2 along with composer 2.3

**Step 4. Install another composer to work with Laravel 4:**
1. Create a folder called **composer1** in **laragon/bin**.
2. Download composer.phar version 2.2.18 [Download Link](https://getcomposer.org/download/2.2.18/composer.phar) and save it in **laragon/bin/composer1**.
3. Open notepad, paste the following code in it and save it as **composer1.bat** in the same folder (laragon/bin/composer1)
```
@ECHO OFF
php "%~dp0composer.phar" %*
```
Your folder should look like this:

![composer1 folder structure](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rrc8adrl5pmvc4nd9sga.png)
4. Now we need to add composer1.bat to windows environment path. For that go to start and type **system** then select **system**.
![system](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n8v0yxat2yhja25xpyw6.png) then select **advanced system settings**
![Advance system settings](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ljgmcko2ps8nvi2orem4.png)Under the **Advanced** tab select **Environment Variables**
![environment variables](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/saryylgkcycgeaxd0o4h.png)In the user variables section select **Path** and click Edit. Click new and type the complete path to the folder containing **composer1.bat** Like this 
![composer1 path](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e12n8368mebolgczxl2o.png)
5. Start terminal again. Now if you type `composer1 -v` in the terminal it will show you composer version 2.2.3. If you change to php 8 and Apache 2.4.54, start terminal again and type `composer -v` you see composer version 2.3

**Step 5. Install composer dependency for the Laravel 4 project:**
Switch to php7 and Apache 2.4.41. Open terminal and navigate to the Laravel 4 project folder. Run `composer1 install`. This will install all the necessary Laravel 4 dependencies.

**Step 6. Connect to database:**
1. Add PhpMyAdmin by clicking menu > Tools > Quickadd > phpmyadmin like this: 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5szt8afc456obtnz1hi8.png)This will download the latest PhpMyAdmin which doesn't work with Php7.0. 
2. Switch to Php 8 and Apache 2.4.45 and click **Database** on Laragon. This will open PhpMyAdmin. Login with root and no password.
3. Check the Local database config file of Laravel 4 project at **app/config/local/database.php** and make sure that database for this project exists. If not create a new database. As per the config file create a new user with password as mentioned in the config file. While creating a new user, select **Native MySQL Authentication** in the Authentication plugin field. Grant all privileges to this user. Like this 
![Create SQL User](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g92aii4bg2437wkw0tzx.png)
4. If you have database migrations to run, you can now run `php artisan migrate`.

That's it. You now have Laravel 4 working in the latest Laragon. For creating Laravel 9 project, simply change the PHP and Apache version.

Several people have suggested to use docker for this use case. But it's an overkill unless you need both Laravel 4 as well as Laravel 9 running at the same time.