Running PHP locally has been a challenge for new developers all the time. In this article, I will brief the method in which you can quickly set up a local server connection. After that, running PHP locally would be very easy.
PHP, or Hypertext Preprocessor (earlier known as personal home page), is a web scripting language that helps in converting a static webpage to dynamic.
Learn more on Static and Dynamic webpages.
PHP can run by itself using a server configuration and a database connection (if you include database functionality in your webpage). Running PHP locally means that your hard disk behaves as the server storage space. The Apache software (in case of WAMP / XAMPP) creates port for communication and configures the server access variables.
WAMP (Windows Apache MySQL PHP) or XAMPP are both software to be used in conjunction with Windows operating system. So, it is like using a Windows server in a hosting plan. This software does not work in Linux. For Linux users, you must use LAMP software.
So, let’s start with understanding the basics of running PHP locally –
- Installation of the WAMP software
- Writing our PHP file and storing it inside www
- Opening our server page on the browser and running PHP locally
First of all – let’s install WAMP for running PHP locally on our computer
The WAMP or XAMPP software is readily available on the Internet. If you are finding it very difficult to get hold of them, here’s my list of links that will help you –
Download the software from one of the above links before you try running PHP locally. This software behaves as the host configurator and must be installed first. Once you have downloaded WAMP / XAMPP, start installing it. It’s a simple job if you follow each procedure step by step.
- Use administrator rights to continue with installation when you first click the setup file.
- The next few steps are very easy. Just like installing any other software, you must accept terms; select the path for installation, etc.
- After the installation starts, in the middle you would be asked about your default browser. Just click okay when it shows explorer (by default it sows explorer, so click ok in the default popup window).
- That’s it. The software for running PHP locally is now installed. Now click on the shortcut icon to start WampServer.
- To check whether it is running or not, look for the below icon in the taskbar.
Storing your files in the dedicated folder
Your PHP projects must all be stored in a particular folder in order to be accessed by the host (localhost) before running PHP locally. WAMP provides a folder named “www” within the folder where it has been installed. On the other hand, XAMPP provides a folder named “https”.
All your PHP files and projects must be within this folder. You can keep the files in dedicated folders or just randomly (I do not suggest this at all!). When you access the project via your browser, you would access this folder first and then go down the folder hierarchy.
Now let’s switch to running PHP locally from the browser.
Running PHP locally – steps in the front end
Once the files and installations are all at place, just open your browser and type in “localhost”. Make sure you have turned on WAMP or XAMPP before accessing the browser.
When you write localhost now, it means the browser straight heads to that “www” or “https” folder. So, now if you call a particular folder after “localhost”; that respective project would run.
So, let’s say you had stored all your PHP, HTML, CSS files for a single project inside a folder named “project101”. Now you moved this folder inside your “www” or “https”. When you have done this, for running PHP locally and running your project, just type in the following –
“localhost/project101/” and hit enter! Your project will be live on your computer!
Running PHP locally while accessing and associating a database
Accessing a database is quite tough for beginners in the web domain programming zone. People really find it very difficult to work with databases while coding in a web scripting language. Well, let me tell you that PHP has a very short, simple and user friendly syntax. Just a bit of research and you’ll find it super easy to access database values from your PHP code.
Well, running PHP locally while using database is very easy. You must first create a database using WampServer on your computer.
Look at the image below –
This is how you access the database section for your local server. All your local projects that have database access and requirements can be handled from the “phpmyadmin” section.
The following image shows the phpmyadmin dashboard. This is your hub for accessing database values and entities. You can fully edit and update database values and settings from the phpmyadmin page.
That’s all. Use WAMP or XAMPP for running PHP locally and let me know.