Introduction
This guide will help you set up your Windows machine so that you can code websites with the PHP programming language.
Years ago when I first started out as a PHP developer I used Wampserver which was a Windows application that installed Apache, PHP and MySQL.
As I looked into local PHP environments I came across a newer one that I've never heard about before called Laragon which looked promising from my first impressions when looking at their website.
After spending a bit of time setting it up I decided that this would be a perfect solution for beginner programmers for PHP as it simplifies a lot of the more complicated parts of setting up a PHP website locally.
Laragon
Laragon is a new local development environment for Windows that supports PHP development on your local machine. Compared to Wampserver it has some extra features that make it much easier to set up PHP websites.
To begin go to the Download page and download the full edition of Laragon.
Setup
Go to your downloads folder in Windows and double-click the laragon-wamp.exe file to begin installation.
In the setup window the default location is C:\laragon, change it if you want and then click the Next button.
You have the option to change some of the settings.
- Run Laragon when Windows is booted
- Setup URLs for websites hosted in Laragon
- Add menu shortcuts for Command Prompt and Notepad++
I would leave them enabled, change if you prefer and click the Next button.
The next step is to show that installation will begin, click the Next button to start the process.
Wait till the installation is complete once the progress is complete you should see the completion message.
Click the Finish button to close the setup window and start-up Laragon.
A window should appear which can be used to manage Laragon, to start Apache and MySQL press the Start All button.
Once the Apache and MySQL entries appear then the web server should be up and running.
Now press the Web button to go to http://localhost in your browser to verify that Apache is working fine.
You should see the following screen in your browser, this means that Apache is working.
Change PHP version
One thing I've noticed is that Laragon comes with PHP version 8.1 built-in and at the time of writing this guide the latest version of PHP is 8.3.
Each version of PHP typically has new features which means it's worth upgrading to the latest stable version. Also, each version has security updates for a set amount of time so it is best practice to make sure you update PHP to the latest stable version when you can.
Go for the VS16 x64 Thread Safe block and download the Zip file.
Go to your downloads folder and you should see the php-8.3.1-nts-win32-vs16-x64.zip file. Right-click on the zip file, click the Extract All... option and then extract files in the same directory.
Right-click on the php-8.3.1-nts-win32-vs16-x64 folder and select the copy option.
Open a new file explorer window, go to the C:\laragon\bin\php folder and paste the php-8.3.1-nts-win32-vs16-x64 folder into this directory.
In the bottom right-hand corner, you should see a square icon with a blue outline, if it is not shown it might be in the hidden menu when you press the arrow icon.
Right-click the Laragon icon, select PHP -> Version and then left-click the version you just added. For this guide, it's PHP 8.3.1.
Go to the Laragon window and restart the Apache server by clicking the reload link.
Click the Web button to load up the localhost website you should see the PHP version has been updated.
Setup a test PHP website
Now that you have Laragon you can now set up PHP websites. To set one up right-click the Laragon icon in the bottom right-hand corner and select the Quick app -> Blank option.
A window pop-up will show up requesting a name for the new site. Give it the name like helloworld and press the OK button.
Laragon comes bundled with Notepad++ if the default option was left selected on installation. This application can be used to write PHP code to a file. Right-click the Laragon icon and select Tools -> Notepad++.
While inside of the Notepad++ application copy and paste the following example code which will print the text "Hello World!" once the website has loaded.
<?php
echo "Hello World!";
This file needs to be saved to the correct directory. Click on the File option in the top menu and then select the Save As... option.
Click the top dropdown menu next to the Save in: text and select the helloworld folder inside of the C:\laragon\www directory.
Next use index for the File name and select the PHP Hypertext Preprocessor file for the Save as type option. Finally, click the Save button to save the PHP file.
Go to the URL http:\\helloworld.test and if you see the Hello World! text then the PHP website has been set up and you can work with the PHP file to write code.
Manage MySQL databases
Laragon comes with MySQL support where you can manage data stored in databases. To access your databases go to the Laragon icon in the bottom right. Select the Laragon -> Database option to go to it.
HeidiSQL
HeidiSQL which is a MySQL client will open up, this application comes bundled with Laragon. A connection is already set up to connect to MySQL with the user and password setup. Click the Open button to connect to the MySQL connection.
After connecting to MySQL you can see the helloworld database, every time you create a project it will also automatically create a database with the same name.
It makes sense for Laragon to take this action as majority of cases every PHP application will connect to a database to store data.
phpMyAdmin
Another MySQL client is phpmyadmin which is a website version which can be made accessible online. To access phpmyadmin go to the Laragon icon, right-click for the menu and select Tools -> Quick add -> phpmyadmin.
A pop-up window will appear showing progress as it will require setup before it can load. Click the OK button once it is available.
You will be presented with the phpMyAdmin login page. Enter the Username as root and leave the password blank. Press the Log in button to log in.
After login, you will be presented with the phpMyAdmin UI interface to manage your databases.
Selecting a database on the left-hand menu will allow you to manage the tables for that selected database. As it's just been setup you won't have any tables available at the moment.
Conclusion
After setting up Laragon and trying out some of the features that it provides you can now start programming your PHP / MySQL projects in Windows quickly and easily without too much hassle or running into many issues which can occur in setting up a development environment.
Laragon is a definite improvement to PHP development when compared to other similar web servers such as Wampserver and XAMPP.
I highly recommend it for beginner PHP programmers who start off coding PHP in Windows.