Php tutorials with xampp

PHP Tutorial – How to Setup PHP and XAMPP for Your Project

Okoro Emmanuel Nzube

Okoro Emmanuel Nzube

PHP Tutorial – How to Setup PHP and XAMPP for Your Project

Hello and welcome to this tutorial, everyone. Today, we’ll look at how you can set up and use PHP in a project.

But before we get started, we’ll need to understand what PHP is all about.

What is PHP?

PHP is an abbreviation or acronym for «Hypertext Preprocessor.» It’s a web-based open source server-side scripting language that’s integrated in your HTML files.

Читайте также:  Необычный тег для html

You use it to make webpages that are both responsive and interactive with the database.

Advantages of PHP

PHP has many benefits, and here are a few of them:

PHP is Simple to Use

You don’t need to study extensively to learn and use PHP because its syntax is sensible and well-organized. The command functions are also easy to work with because they help you understand exactly what they do.

PHP is Flexible

Flexibility is a major benefit that every scripting language should have, and PHP is no exception. Even after a project has been launched, a PHP developer has the ability to make changes to the project.

PHP Helps You Collect Data from Forms

You can use PHP to collect data from a form that has been created with HTML (like Name, E-mail, Phone Number, or Password). Many websites use this particular function of PHP.

PHP Has Good Security

PHP does not outsource the data or information collected from forms. This is part of the reason why most most website and social media apps make use of it because it has a secure database system.

How to Install and Setup PHP in your Project

To get started with PHP, you’ll need three things: a code editor for writing your code, an installed version of PHP, and XAMPP.

We’ll be using Visual Studio code in this example, and I’ll teach you how to install a version of PHP and XAMPP on your PC.

Go to the PHP website and click on download in the navigation bar. The current version should be at the top.

Click on «Windows downloads,» and when it opens, scroll down a little and you should see a section that has «VS16 x64 Thread Safe (2022-May-11 09:29:42).» The section contains a «zip» file below it – click on it and wait for your download to finish.

PHP_-Hypertext-Preprocessor---Google-Chrome-5_30_2022-7_57_44-PM-1PHP_-Hypertext-Preprocessor---Google-Chrome-5_30_2022-7_57_58-PMPHP_-Hypertext-Preprocessor---Google-Chrome-5_30_2022-7_58_42-PM

When the download is complete, go to your computer’s downloads folder and look for a PHP zip file. Right-click it and select extract file. It’s important to save the file to your local drive.

bandicam-2022-05-30-20-15-25-892-1

Open the Local Disk and open the extracted PHP folder. Click once on the bar that shows the current directory then copy the name of the directory, which should be in this format: C:\php-8.1.6.

bandicam-2022-05-30-20-30-59-641

In your windows bar, search for “Edit the systems environment property”. Click on the “environment variables” button, click on “Path”, and then click on the edit button below. It opens a space where you can create a new variable.

So click on the new button and then paste the name of the directory you copied earlier (which should be “C:\php-8.1.6”) and click ok for all of them.

Environment

To test if PHP is now installed in your computer, search for the command prompt in Windows by using the search keyword cmd . Open it then type php —version and click enter. You should see something similar to this:

bandicam-2022-05-30-20-46-16-280

The current version of PHP is installed on our PC as seen in the image above. The next step is to get XAMPP.

What is XAMPP?

The acronym XAMPP stands for cross-platform, Apache, MySQL, PHP, and Perl. XAMPP is a free and open source web server that allows you to develop, test, and build websites on a local server.

Unlike PHP, XAMPP installation is quite simple and uncomplicated. Search for «XAMPP Download» in your browser or go to their website. You should see the current version of XAMPP for Windows, Linux, and OSX when it opens.

Because I’m using a Windows computer, I simply need to click on the one for Windows, and the download should begin.

bandicam-2022-05-30-21-01-27-189

When its done downloading, go to your downloads, right click on the setup file and select “run as administrator”.

This will take you to the Setup-xampp wizard:

bandicam-2022-05-30-21-07-14-620

Click next, and you’ll be able to select the components you want:

bandicam-2022-05-30-21-07-22-682

Then you’ll come to the installation folder. You have to select a folder where you want to install XAMPP. I recommend creating a folder in your local disk to install XAMPP.

bandicam-2022-05-30-21-07-29-806

Then you’ll select the language. You can select either English or Deutsch (your choice):

bandicam-2022-05-30-21-09-03-881

Now you’ll get Bitnami for XAMPP:

bandicam-2022-05-30-21-09-08-433

And you’re ready to install:

bandicam-2022-05-30-21-09-25-333

Be patient while the installation process completes. When it’s, done click ok.

bandicam-2022-05-30-21-09-30-643

Once the installation process is finished, you can now use XAMPP in you project.

Why Do You Need XAMPP?

To run PHP for the web, you will need to install a web server like Apache and a database like MySQL – and both are supported by XAMPP.

XAMPP is a local server that can run smoothly on our personal computer, and is accepted in both Windows and Linux. It also helps you test websites and see if they work before actually publishing them to a web server.

How to Run PHP with XAMPP

To run PHP with XAMPP you will have to go through some steps, and I will break it down so you can understand.

First, open the local storage folder, go to the “xampp” folder and open it. You should see a folder named “htdocs”. Open it then create a new folder in it. In my case I named the folder I created “Demo” (so give your folder the name of your choice).

1-2-3

Next, open your VS code, click on open folder, then go to the location where you saved the folder you created (which in my case I named “Demo”). Create a file with the extension .php – in my case I named mine test.php . The extension .php tells the code editor that we are working on a PHP code/project.

bandicam-2022-06-01-22-08-09-094

The echo keyword tells the browser to display My Name is Derek while the tells the web browser to format the text to be bold/bigger. Then save it.

After writing the code, open the XAMPP control panel, and start the Apache module by clicking on start under the action section.

test.php---Demo---Visual-Studio-Code-6_2_2022-1_23_21-AM

Then go to your web browser and in the search bar type localhost/Demo/test.php , then enter. Your web browser should be display this:

bandicam-2022-06-01-22-07-50-039

If your code was displayed on the web browser, congratulations! You’re up and running.

Conclusion

Thank you very much for following along with this tutorial. I hope you got some value out of this lesson and I hope you’ll try using PHP and XAMPP.

Stay tuned for my next tutorial.

Источник

How to Run a PHP File Using XAMPP: A Step By Step Guide

PHP Using XAMPP: The Ultimate Step-by-Step Guide

PHP is the most popular and widely-used server-side scripting language for web development. However, it requires a webserver to run even a locally developed webpage. There are various web server software for setting up our local webserver. Amongst them, PHP XAMPP and WampServer are the most popular. While WampServer is only available for the Windows platform, XAMPP is a cross-platform application that can run on Windows, Linux, and macOS. Hence, in this tutorial, you will learn PHP using XAMPP.

What Is PHP?

PHP (Hypertext Protocol) is Open Source Programming Language used to make web pages. PHP language can run on various platforms and is compatible with almost all servers. PHP files use .php as their extension. PHP can perform functions, like from files on a system it can create, open, read, write, and close them. You can add, delete, and modify elements within your database with the help of PHP. You can restrict users from accessing some pages of your website using PHP. PHP can encrypt data too.

Advantages Of PHP

Web-Developers use many other languages, but most prefer using PHP because of its advantages. Some advantages of PHP are:

  1. Simple and easy to learn — PHP is known as the easiest Scripting language as it doesn’t have intensive studying. Commands are very easy to understand for new learners and developers too.
  2. Compatible — PHP language is compatible because it can run on many operating systems. It can easily run on platforms like Windows, LINUX, and UNIX.
  3. Flexibility — PHP language is very flexible for developers because it allows you to change the existing or completed project.
  4. Less Costly — As PHP is an open-source language, you can download it for free. You don’t have to purchase any license or software.
  5. MVC Pattern — Model-View-Controller Pattern in PHP helps you organize codes.
  6. Loading Time — PHP is faster than other programming languages. It can be loaded when your network connection is slow.
  7. Library Support — PHP also has a collection of many, many advanced written codes that you can use repeatedly. And also use it whenever you want to run a program.

How to Set Up and Install PHP for Your Project?

Step 1: Find a web server that supports PHP and MYSQL.

Step 2: Then install PHP from its website.

Step 3: Then install MYSQL DB on your PC.

What is XAMPP?

XAMPP is an open-source web server solution package. It is mainly used for web application testing on a local host webserver.

Now that you have a better understanding of the XAMPP software, let us move on to its installation.

Why Do You Need XAMPP?

To run any PHP program, you will need Apache or MYSQL databases, both supported by XAMPP. XAMPP helps you to run your program smoothly.

Basics to Advanced — Learn It All!

How to Install XAMPP?

Apache friends developed XAMPP, and it is available for everyone free of cost.

You can download XAMPP through the official website, https://www.apachefriends.org/download.html.

On completing the download of the setup file, begin the installation process and, in the “Select Components” section, select all the required components.

XAMPP_1

Next, select the directory where you want the software to be installed. It is recommended that you keep the default directory “C:\xampp” and click on “next” to complete the installation.

XAMPP_2

Now that the installation is complete, let’s move ahead to see how to run a PHP script using the same.

How to Start a New PHP Project in XAMPP?

  • Before you run or start writing any program in PHP, you should start Apache and MYSQL.
  • After starting both servers, you have to write a program in Notepad.
  • After writing it, save that file as «program.php».
  • Then copy that file program.php to C:/Program Files/XAMPP/htdocs.
  • Open the browser and type http://localhost.
  • Now run your code in that browser.

Designing a Social Media App Like Instagram

How to Run a PHP Code Using XAMPP?

Before running a PHP script, you must know where to write it.

In the XAMPP directory, there exists a folder called “htdocs”. This is where all the programs for the web pages will be stored.

1. Go to “C:\xampp\htdocs” and inside it, create a folder. Let’s call it “demo”. It’s considered good practice to create a new folder for every project you work on.

XAMPP_3

2. Inside the demo folder, create a new text file and name it “index.php” and write the following script.

XAMPP_4.

3. 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.

XAMPP_5

4. Now navigate to your browser and type in “localhost/demo/” in the address bar to view the output.

/first_php_script_xampp_6

Congratulations, with this, you have created a PHP file and also executed the program successfully.

Conclusion

This concludes the tutorial. In this “PHP using XAMPP” tutorial, you looked into why you need XAMPP, what XAMPP is, how to install XAMPP, and finally, how to run your first PHP script on it.

Are you planning to take the plunge and do a course on PHP? In that case, Simplilearn’s PHP course would be an excellent choice. The Post Graduate Program in Full Stack Web Development covers all the fundamental and advanced concepts, making your journey towards learning PHP an easy one.

If you have any questions regarding the “PHP using XAMPP” tutorial, please ask away in the comments section of this article, and we’ll have our experts answer them for you.

FAQs

1. How to run a PHP file in localhost XAMPP?

Create any project, for e.g.,

2. Can we run PHP in XAMPP?

Yes, you can run PHP in XAMPP. First, start the XAMPP server, create a program you want to and run it at http://localhost.

3. How do I run my PHP file?

PHP files are saved in C:/Program Files/XAMPP/htdocs. You have to open it, click on the program, and it will automatically run on localhost.

4. How to run PHP files in phpMyAdmin?

  • Login into PHPMyAdmin, then click on the import tab.
  • Browse the file with a .sql extension.
  • Keep in mind to check and uncheck some options.
  • Choose SQL format and click on Go.

Find our Full Stack Java Developer Online Bootcamp in top cities:

Name Date Place
Full Stack Java Developer Cohort starts on 4th Aug 2023,
Weekend batch
Your City View Details
Full Stack Java Developer Cohort starts on 25th Aug 2023,
Weekend batch
Your City View Details

About the Author

Ravikiran A S

Ravikiran A S works with Simplilearn as a Research Analyst. He an enthusiastic geek always in the hunt to learn the latest technologies. He is proficient with Java Programming Language, Big Data, and powerful Big Data Frameworks like Apache Hadoop and Apache Spark.

Full Stack Java Developer Career Bootcamp

Источник

Оцените статью