To run PHP code in XAMPP, you’ll need to follow these steps:
- Install XAMPP: If you haven’t already installed XAMPP, download it from the Apache Friends website (https://www.apachefriends.org/index.html) and follow the installation instructions for your operating system (Windows, macOS, or Linux). You can find instructions here on how to download the XAMPP server for Windows. Click the link below.-https://www.aiuniverse.xyz/how-to-setup-xampp-in-windows-10/
2. Start XAMPP Control Panel: Once XAMPP is installed, start the XAMPP Control Panel. On Windows, you can typically find it in the Start menu or by searching for “XAMPP Control Panel”. On macOS, you can find it in the “Applications” folder.
3. Start Apache Server: In the XAMPP Control Panel, click the “Start” button next to Apache to start the Apache web server. Apache is the web server that will serve your PHP files.
4. Write PHP Code: Create or open a PHP file using a text editor. You can use any plain text editor such as Notepad (Windows), TextEdit (macOS), or any code editor like Visual Studio Code, Sublime Text, or Atom. For example, create a file named hello.php
and add the following code:
<?php
echo "Hello, world!";
?>
5. Save PHP File: Save the PHP file in the htdocs
directory inside the XAMPP installation directory. By default, on Windows, this directory is C:\xampp\htdocs
, and on macOS, it’s /Applications/XAMPP/htdocs
.
6. Access PHP File in Browser: Open your web browser and navigate to http://localhost/hello.php
. This URL corresponds to the hello.php
file located in the htdocs
directory of your XAMPP installation. You should see “Hello, world!” displayed in your browser, indicating that your PHP code is running successfully.
That’s it! You’ve now successfully run PHP code in XAMPP. You can create more PHP files and access them in the browser using similar steps. Remember to stop the Apache server from the XAMPP Control Panel when you’re done testing your PHP code to conserve system resources.