Run php on desktop

A Simple Way To Installing PHP And Run Script Files On Windows

PHP and Composer On Windows

Here is a simple way to install the PHP and run the script files on Windows Environment. in the installation process we’ll use the Chocolatey Windows Package Manager which contain about 8785 free community maintained packages, that can be searched and listed here https://community.chocolatey.org/packages.

And we can do it as following…

Now Run Windows PowerShell as an Administrator by:
Press Win Key + R. so a small window will pop up as shown in the screenshot below

Windows Run

Type in the popup window powershell , then press Ctrl+Shift+Enter or press OK While hold Ctrl+Shift.

run windows powershell as admin

1- Install Chocolatey Windows Package Manager

In The PowerShell Run The Following Commands to install Chocolatey Windows Package Manager.

First check if the execution policies is not restricted on the PowerShell , by run Get-ExecutionPolicy command as shown:

Power Shell AllSigned

If not return AllSigned i.e. Restricted, so we’ll need to run the command Set-ExecutionPolicy AllSigned or Set-ExecutionPolicy Bypass -Scope Process

To install the Chocolatey Package Manager run the following command at the Powershell

Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString(‘https://community.chocolatey.org/install.ps1’))

installing Chocolatey Windows Package Manager

2- Installation PHP Package

Installing PHP on Windows

PS C:\> choco install php Chocolatey v0.11.3 Installing the following packages: php By installing, you accept licenses for the packages. Progress: Downloading php 8.0.10. 100% php v8.0.10 [Approved] php package files install completed. Performing other installation steps. The package php wants to run 'chocolateyInstall.ps1'. Note: If you don't run this script, the installation will fail. Note: To confirm automatically next time, use '-y' or consider: choco feature enable -n allowGlobalConfirmation Do you want to run the script?([Y]es/[A]ll - yes to all/[N]o/[P]rint): yes Extracting 64-bit C:\ProgramData\chocolatey\lib\php\tools\php-8.0.10-nts-Win32-vs16-x64.zip to C:\tools\php80. C:\tools\php80 PATH environment variable does not have C:\tools\php80 in it. Adding. Creating default php.ini Configuring PHP extensions directory Please make sure you have CGI installed in IIS for local hosting Environment Vars (like PATH) have changed. Close/reopen your shell to see the changes (or in powershell/cmd.exe just type `refreshenv`). The install of php was successful. Software installed to 'C:\tools\php80' Chocolatey installed 1/1 packages. See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).

The installation path is C:\tools\php80 , and after installation successfully completed, the PHP command will be inserted to the Windows Environment Vars Path Automatically, so can run from any where any terminal.

3- Installation PHP Composer Package For Windows

Installing PHP Composer On Windows

To install PIP we need to run the command choco install composer

The Windows Environment Vars PATH will updated too, so you can use composer command in any terminal.

Источник

How to Run PHP Code on Your PC

Do you want to run PHP code on your PC? This tutorial will teach you everything.

PHP is a server-side scripting language, that’s why you can’t run it by just opening it in your browser.

You need two things to run PHP code on your PC.

  1. A Local Webserver software with Apache, MySQL, and PHP support,
  2. A Text Editor for example Visual Studio Code.

Note: You can use any text editor with PHP support.

Now, let’s see the steps to set up, install and run PHP code on your PC.

How to Run PHP Code

First of all, we’re going to teach you how to create a local web server on your computer to run PHP. Because PHP is a server-side language and you can’t run it without a server.

Fortunately, we have third-party software available on the internet like XAMPP, WAMP, MAMP, etc. These apps can make the job extremely easy for you to run PHP.

We’ll use XAMPP to create a local webserver. The reason I prefer XAMPP is that we can run XAMPP on multiple operating systems, like Windows, MAC, Linux, etc. And also, it has more features.

So, let’s begin with our first step.

Step 1: Install XAMPP, Run Apache and MySQL

XAMPP is software that you can use to create a local webserver on your PC. Using XAMPP, you can run the Apache server that is required to run and execute PHP code.

There are other web server apps available on the internet like WAMP, MAMP, etc. But we choose XAMPP because it is open-source software and available for more than one operating system. It is available for Windows, Linux, and MAC OS.

To install XAMPP, visit the apachefriends.org website. Then, download and install XAMPP on your PC.

install XAMPP to run PHP

After installing XAMPP on your PC, open it. Then run Apache and MySQL as shown in the image below. MySQL is a database server, it is not mandatory. Because in this tutorial, we’ll not talk about the MySQL database. We’ll talk about the MySQL database in our later PHP tutorials.

So you can only Start Apache if you want.

Run Apache and MySQL on XAMPP

And done! you have successfully created a local web server on your PC. But wait! How you can access it in your browser?

Every web server has an IP address and a hostname. As this server is on our local computer. So, for XAMPP by default, our hostname is localhost and our localhost’s IP address is 127.0.0.1.

Just type localhost in your browser’s search bar to access your local web server.

localhost

You will see a ‘Welcome to XAMPP’ page. This means the local web server or XAMPP is working on your PC.

Step 2: Place Your Project Folder on the Local Server

On a live web server your website files (aka your project files) are located in directories (mean folders). Same as the files and folders on your computer. Here, to run PHP code in XAMPP, your website files will store in the htdocs folder which is located in the XAMPP folder.

To do this, you have to copy-paste your PHP project folder into ‘htdocs‘ folder as shown in the image below and create a folder inside it with any name.

htdocs folder in xampp to store php files

This is where your HTML, CSS, JS, and PHP files will store. The PHP files you’re going to create in the next step will also store in this folder.

So now, you have a web server running on your PC. It’s time to create a PHP file and execute PHP code in our Browser. So, let’s see the main step.

Step 3: Create a PHP File to Run PHP Code

I am using visual studio code to create a PHP file. You can download this text editor from their website, it’s free.

Before creating a PHP file, open the htdocs folder and create a new folder in that. You can give it any name. This is the folder where your website or project files are located. As you can see in the image below, I gave it a name testwebsite .

Create a Folder in htdocs folder

You can access this folder in your browser by typing localhost/testwebsite.

After that, open visual studio code and open this folder in your text editor as shown below.

Open test website folder in VS code

Then, create a PHP file and give it the name sample.php.

After that, write some code in that file. You can copy/paste the code given below.

This will look like this as shown in the image below.

It is the simple hello world program that we’re going to run on your PC.

Now, we have created the PHP file and written some code in it. Now, you can run PHP in your browser.

Step 4: Execute or Run PHP Code in Your Browser

To do this, open your browser and type in the search bar localhost/testwebsite/sample.php. And hit enter. This will open a PHP file and run a PHP script in your browser.

According to our code. The ‘Hello World’ program has been executed. See the image below.

a simple php hello world program

That’s it. Now, you know how to run PHP code on your PC. And you can create and run as many PHP files as you want.

Things to Remember Before Running PHP Code:

  • Whenever you want to run PHP code, always make sure XAMPP is running with Apache and MySQL.
  • Your project folder containing PHP files must be placed inside ‘htdocs‘ folder which is located in the XAMPP installation folder.
  • Whenever you install XAMPP on your PC, just make sure you select the default location to install XAMPP which is usually C drive. To avoid errors.

What’s next? Now, you should learn PHP variables. Variables are containers for storing data. This tutorial is will help you to understand the concepts behind variables.

If you want to learn something advanced about PHP. Then, see this trending guide on how to connect HTML Form to MySQL database using PHP.

That’s it, if you have any questions related to this guide, then feel free to leave a comment below.

Keep learning and sharing!

About The Author

Muhammad Zeeshan

Hi everyone, I’m a Full Stack Web Developer and Technical Writer. I just love to share my knowledge to help others in this community. I mostly write about HTML, CSS, JS, MySQL, and PHP.

Источник

A Simple Way To Installing PHP And Run Script Files On Windows

PHP and Composer On Windows

Here is a simple way to install the PHP and run the script files on Windows Environment. in the installation process we’ll use the Chocolatey Windows Package Manager which contain about 8785 free community maintained packages, that can be searched and listed here https://community.chocolatey.org/packages.

And we can do it as following…

Now Run Windows PowerShell as an Administrator by:
Press Win Key + R. so a small window will pop up as shown in the screenshot below

Windows Run

Type in the popup window powershell , then press Ctrl+Shift+Enter or press OK While hold Ctrl+Shift.

run windows powershell as admin

1- Install Chocolatey Windows Package Manager

In The PowerShell Run The Following Commands to install Chocolatey Windows Package Manager.

First check if the execution policies is not restricted on the PowerShell , by run Get-ExecutionPolicy command as shown:

Power Shell AllSigned

If not return AllSigned i.e. Restricted, so we’ll need to run the command Set-ExecutionPolicy AllSigned or Set-ExecutionPolicy Bypass -Scope Process

To install the Chocolatey Package Manager run the following command at the Powershell

Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString(‘https://community.chocolatey.org/install.ps1’))

installing Chocolatey Windows Package Manager

2- Installation PHP Package

Installing PHP on Windows

PS C:\> choco install php Chocolatey v0.11.3 Installing the following packages: php By installing, you accept licenses for the packages. Progress: Downloading php 8.0.10. 100% php v8.0.10 [Approved] php package files install completed. Performing other installation steps. The package php wants to run 'chocolateyInstall.ps1'. Note: If you don't run this script, the installation will fail. Note: To confirm automatically next time, use '-y' or consider: choco feature enable -n allowGlobalConfirmation Do you want to run the script?([Y]es/[A]ll - yes to all/[N]o/[P]rint): yes Extracting 64-bit C:\ProgramData\chocolatey\lib\php\tools\php-8.0.10-nts-Win32-vs16-x64.zip to C:\tools\php80. C:\tools\php80 PATH environment variable does not have C:\tools\php80 in it. Adding. Creating default php.ini Configuring PHP extensions directory Please make sure you have CGI installed in IIS for local hosting Environment Vars (like PATH) have changed. Close/reopen your shell to see the changes (or in powershell/cmd.exe just type `refreshenv`). The install of php was successful. Software installed to 'C:\tools\php80' Chocolatey installed 1/1 packages. See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).

The installation path is C:\tools\php80 , and after installation successfully completed, the PHP command will be inserted to the Windows Environment Vars Path Automatically, so can run from any where any terminal.

3- Installation PHP Composer Package For Windows

Installing PHP Composer On Windows

To install PIP we need to run the command choco install composer

The Windows Environment Vars PATH will updated too, so you can use composer command in any terminal.

Источник

Читайте также:  Глобальные стили
Оцените статью