Let me explain today how to use the wamp server to run PHP files. You can use this method to run PHP scripts you may have obtained from somewhere and need to run with little to no knowledge of PHP. You can execute your scripts through a web server where the output is a web browser. So let's get started To set up the server we are using a software called wamp server.Introduction: How to Run a PHP Script With Wamp Server
Step 1:
Installing the Server Software
Step 2: Setting Up the Server
- If the installation went well, you should have an new icon in the bottom right, where the clock is.
- Click the icon to see the menu as given above[1]. The icon should be green in color, if it is red/orange then there is an error. From here, you can stop the server, exit it, view help files, and see the configuration pages.
- Click on localhost, though, and you'll see the page as above[2] : [Localhost just refers to the server running on your own computer. Another way to refer to your server is by using the IP address 127.0.0.1.]
If you saw the above page, then congratulations! Your PHP server is up and running, and you can make a start scripting PHP pages.
Step 3: Saving Your PHP Scripts
- Whenever you create a new PHP page, you need to save it in your www directory. You can see where this is by clicking the www directory item on the menu.
When you click on www directory, you should see an explorer window appear.
The PHP Script you want to run should be copied into this directory.
This www folder for Wampserver is usually at this location on your hard drive:
c:/wamp/www/Bear this in mind when you click File > Save As to save your PHP scripts.
Step 4: Running the PHP Script
- You can run the PHP Script in two ways:
Method 1:
Open localhost through the menu in the bottom right of the taskbar.
A page should open in your browser and you should see a list called Your Projects
If you saved your PHP script at the right place you should see your script name in this list
Click on the script to run it
Method 2:
Suppose you have created a php script called test1.php. To launch
this script, you need to add the script name after localhost in your browser. So we type
//localhost/test1.php
Your server knows where the www folder is, so you don't have to type it out: just add the script name to localhost. Likewise, if you create a folder under www then you'd just type this:
//localhost/folder_name/script_name.php
Viola, your script should be up and running.
Step 5: Troubleshooting
If you encounter an error like "api-ms-win-crt-runtime-l1-1.0.dll is missing”, then you need to [re]install the Visual C++ Redistributable for Visual Studio 2015, either via Windows Update or download and directly install the Visual C++ Redistributable:
- Install all pending Windows Updates
1. Go to Start – Control Panel – Windows Update
2. Check for updates and install all pending updates, then restart the computer.
3. After the restart repeat the steps above again until no more updates are available.
2. Download the Visual C++ Redistributable 2015
- For Windows 64-bit
Visual C++ Redistributable for Visual Studio 2015 [64-bit]
- For Windows 32-bit
Visual C++ Redistributable for Visual Studio 2015 [32-bit]
- Run the vcredist_x64.exe [64-bit] or vcredist_x86.exe [32-bit] and select Uninstall if already installed
- [If you uninstalled] Run the .exe again and select Install and restart the computer
Be the First to Share
Recommendations
Visual Studio Code is a great editor for PHP development. You get features like syntax highlighting and bracket matching, IntelliSense [code completion], and snippets out of the box and you can add more functionality through community-created VS Code extensions.
Linting
VS Code uses the official PHP linter [php -l
] for PHP language
diagnostics. This allows VS Code to stay current with PHP linter improvements.
Tip: Using XAMPP? Install the full version of PHP in order to obtain the development libraries.
There are three settings to control the PHP linter:
php.validate.enable
: controls whether to enable PHP linting at all. Enabled by default.php.validate.executablePath
: points to the PHP executable on disk. Set this if the PHP executable is not on the system path.php.validate.run
: controls whether the validation is triggered on save [value:"onSave"
] or on type [value:"onType"
]. Default is on save.
To change the PHP settings, open your User or Workspace Settings [⌘, [Windows, Linux Ctrl+,]] and type 'php' to filter the list of available settings.
To set the PHP executable path, select the Edit in settings.json link under PHP > Validate: Executable Path, which will open your user settings.json
file. Add the php.validate.executablePath
setting with the path to your PHP installation:
Windows
{
"php.validate.executablePath": "c:/php/php.exe"
}
Linux and macOS
{
"php.validate.executablePath": "/usr/bin/php"
}
Snippets
Visual Studio Code includes a set of common snippets for PHP. To access these, hit ⌃Space [Windows, Linux Ctrl+Space] to get a context-specific list.
PHP extensions
There are many PHP language extensions available on the VS Code Marketplace and more are being created. You can search for PHP extensions from within VS Code in the Extensions view [⇧⌘X [Windows, Linux Ctrl+Shift+X]] then filter the extensions dropdown list by typing 'php'.
Disable built-in PHP support
To disable the built-in PHP smart completions in favor of suggestions from an installed PHP extension, uncheck PHP > Suggest: Basic, which sets php.suggest.basic
to false in your settings.json
file.
Debugging
PHP debugging with XDebug is supported through a PHP Debug extension. Follow the extension's instructions for configuring XDebug to work with VS Code.
Next steps
Read on to find out about:
- Extension Marketplace - Browse the extensions others have shared
- Debugging - Learn more about VS Code debugging
9/1/2022