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:
- Laravel 9 uses php 8+ but Laravel 4 can only use up to php 7.0.
- The bundled composer in Laragon 6 wouldn't run for php lower than 7.2
- 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.
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:
- download php-7.0.33-Win32-VC14-x64: Download Link
- Extract the contents in laragon\bin\php . This is what my folder looks like.
- We also need to install a compatible Apache to work with php 7.0. Download httpd-2.4.41-win64-VC14.zip Download Link
- Extract the contents in laragon\bin\apache . This is what my folder looks like.
- 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
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:
- Create a folder called composer1 in laragon/bin.
- Download composer.phar version 2.2.18 Download Link and save it in laragon/bin/composer1.
- 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:
- Now we need to add composer1.bat to windows environment path. For that go to start and type system then select system.
then select advanced system settings
Under the Advanced tab select Environment Variables
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
- 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 typecomposer -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:
- Add PhpMyAdmin by clicking menu > Tools > Quickadd > phpmyadmin like this:
This will download the latest PhpMyAdmin which doesn't work with Php7.0.
- Switch to Php 8 and Apache 2.4.45 and click Database on Laragon. This will open PhpMyAdmin. Login with root and no password.
- 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
- 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.
Latest comments (0)