Hướng dẫn software to run php

Hướng dẫn software to run php

Nội dung chính

  • 1) Download and Install XAMPP
  • 2) Create a new project/folder
  • 3) Create a PHP file inside the project folder
  • 4) Open XAMPP Control Panel and start Apache server.
  • 5) Open the browser and search localhost/FolderName/FileName.php
  • Prerequisites for PHP Development
  • How to Setup XAMPP Software?
  • How to Install Code Editor?
  • Write and Run a “Hello World” Program
  • How run PHP code in xampp with VS code?
  • Can we run PHP code in Visual Studio Code?
  • How can I run PHP file in xampp?
  • How do I open PHP file in browser Visual Studio Code?

1) Download and Install XAMPP

You can find the XAMPP installer on the following permalink:
https://www.apachefriends.org/index.html

2) Create a new project/folder

Go to the xampp\htdocs folder and create a new folder (with your project name)

3) Create a PHP file inside the project folder

Open vs code in the project folder and create a new PHP file with a .php extension (i.e FileName.php) with the following code

4) Open XAMPP Control Panel and start Apache server.

5) Open the browser and search localhost/FolderName/FileName.php

Congratulations you have successfully created and run your first PHP code using visual studio code🎉.

You can also check my youtube video “how to run PHP in Visual Studio Code in 2021” if any doubt.👇

PHP is amongst the most widely used programming languages for web development. Since it is an open-source, server-side scripting language with relatively simple architecture, compared to other MVC-based frameworks, it has become a very common language.

A “Hello World” program, as the first program, has become a culture whenever learning a new programming language. Hence, following the footsteps, you will learn how to create a ‘Hello World’ program in PHP to mark the beginning of your journey in PHP.

Let’s get started.

Prerequisites for PHP Development

You need a certain environment to write PHP scripts. Since PHP is a server-side language, it requires a web server for the script to run. In this article, you will create a local webserver.

For PHP development, you need:

  • XAMPP Software.
  • Code editor (e.g., Visual Studio Code)

How to Setup XAMPP Software?

XAMPP is an open source software which stands for:

X = cross platform

A = Apache 

M = MariaDB

P = PHP

P = Perl

It is a complete web solutions package. You will be mainly using it for creating a local web server for this tutorial. XAMPP is also used to set up a MySQL database, which you will learn in the later sections.

To set up XAMPP:

1. Download and install XAMPP from the official website.

2. After installation, open the XAMPP control panel and start the Apache webserver.

Now, to write the code, you need a code editor.

How to Install Code Editor?

You will use Visual Studio Code as the code editor. You may also download any code editor of your choice. Eg: Atom, Notepad++ etc.

Download the Visual Studio Code from the official website.

Now, have a look at the syntax for writing PHP scripts.

PHP Syntax

A PHP script is very similar to how HTML codes are written. It starts with while the code goes in between.

For every PHP file, the default extension code is ".php".

A PHP file usually contains HTML codes with PHP scripts embedded into them.

Write and Run a “Hello World” Program

Now that you have set up the environment for PHP and learned its syntax let’s move onto creating the Hello World program.

Follow this step-by-step to create your PHP program:

1. Open the directory where XAMPP is installed. By default, XAMPP is installed in the C:\ drive.

2. Open the XAMPP folder and locate a folder named “htdocs” in it.

3. Inside that “htdocs” folder, create a folder and name it anything suiting your project.

Here, it has been named as “demo”.

4. Now open Visual Studio Code and click on “open folder”.

5. Locate to C:\xampp\htdocs and select the “demo” folder you created.

6. Create a file named “index.php” inside the demo folder.

7. Since PHP is embedded into HTML codes, write the following HTML code along with the PHP script.

In the above code, “echo” is used to print the string in front of it.

8. Save the file and open your web browser and type “localhost” (Since our server is locally hosted) followed by the folder name that you created and hit enter.

localhost/demo/

9. As you can see, you have got the output for your first PHP program.

Are you a web developer or interested in building a website? Enroll for the Full Stack Web Developer - MEAN Stack Master's Program. Explore the course preview!

Conclusion

This brings us to the conclusion of ‘Hello World’ in PHP article. You have learned how to set up the complete environment for PHP development and how to write and execute your first program in PHP.

Check our next tutorial on the PHP Login form.

If you are looking to master php and gain all the skills you need to become a top-notch full stack software development professional, Simplilearn’s Full Stack Web Developer - MEAN Stack Master's Program is the ideal choice for you. This Full Stack Web development bootcamp offers work-ready training in over 20 top and in-demand skills and tools any company today demands from its full stack developers.From MongoDB, to Express.js, Node.js, Angular, GIT, CSS, HTML, and JavaScript, get the complete software development skill package.

Do you have any questions regarding the article? Please mention it in the comment section of the "Hello World in PHP" article, and we'll have our experts answer it for you. Happy learning!

How run PHP code in xampp with VS code?

Follow this step-by-step to create your PHP program:.

Open the directory where XAMPP is installed. ... .

Open the XAMPP folder and locate a folder named “htdocs” in it..

Inside that “htdocs” folder, create a folder and name it anything suiting your project. ... .

Now open Visual Studio Code and click on “open folder”..

Can we run PHP code in Visual Studio Code?

PHP in Visual Studio Code. 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.

How can I run PHP file in xampp?

How to Run a PHP Code Using XAMPP?.

Go to “C:\xampp\htdocs” and inside it, create a folder. ... .

Inside the demo folder, create a new text file and name it “index. ... .

Now, to see the script output, open the XAMPP control panel and start Apache to host the local webserver, where our script will be running..

How do I open PHP file in browser Visual Studio Code?

Click the button Open In Browser on StatusBar..

In the editor, right click on the file and click in context menu Open PHP/HTML/JS In Browser..

Use keybindings Shift + F6 to open more faster (can be changed in menu File -> Preferences -> Keyboard Shortcuts ).