2 | How to Install a Local Server for PHP | 2023 | Learn PHP Full Course for Beginners

Dani Krossing
8 Mar 202310:43

Summary

TLDRThis video tutorial guides viewers on setting up a local server for PHP development using XAMPP, a popular and easy-to-install software. It addresses common concerns about server installation and reassures viewers of its simplicity. The tutorial covers downloading XAMPP from apachefriends.org, installing it on Windows, and configuring it to run PHP and MySQL services. It also demonstrates creating a new PHP file in Visual Studio Code, setting the PHP executable path, and testing PHP code execution on a local server, concluding with a teaser for the next video on PHP syntax.

Takeaways

  • πŸ˜€ Setting up a local server is essential for developing websites using PHP and should not be intimidating.
  • πŸ› οΈ There are various server software options available such as LAMP, VAMP, XAMPP, and WAMP.
  • 🐘 The tutorial recommends using XAMPP (Apache, MySQL, PHP, Perl) for its ease of setup and familiarity.
  • πŸ’» XAMPP can be downloaded from apachefriends.org, offering versions for Windows, Linux, and macOS.
  • πŸ“₯ Download and install the appropriate XAMPP version for your operating system, ensuring to note the installation location.
  • πŸ”§ After installation, configure the XAMPP control panel and start the Apache and MySQL services to run PHP locally.
  • πŸ“ The 'htdocs' folder in XAMPP is where you can create and manage your local websites.
  • 🌐 Access your local server by typing 'localhost' in your browser to view the default XAMPP page or your PHP websites.
  • πŸ’¬ PHP files can be created by renaming HTML files to '.php' and can contain both HTML and PHP code.
  • πŸ–₯️ If using Visual Studio Code, ensure PHP is set up correctly by configuring the PHP executable path in settings.
  • πŸ”— PHP code within a PHP file can be executed on the server, as demonstrated by the 'echo "Hello World";' example.

Q & A

  • What is the purpose of installing a local server on your computer for PHP development?

    -Installing a local server allows you to run a website using PHP on your computer without uploading it to the internet, making it easy to work on your website offline.

  • Why might some people be scared of installing a server on their computer?

    -Some people might be scared due to misconceptions about the complexity or potential risks of installing a server, but the script clarifies that setting up a server is a common and straightforward process in web development.

  • What are some of the different server software options mentioned in the script?

    -The script mentions LAMP, VAMP, XAMPP, and LIMP as different server software options available for setting up a local server.

  • Why does the speaker recommend using XAMPP for setting up a local server?

    -The speaker recommends XAMPP because it's easy to set up and they have been using it for many years, making them comfortable with its functionality.

  • How can one obtain XAMPP for setting up a local server?

    -XAMPP can be downloaded from the Apache Friends website, and the script provides a link to the website for easy access.

  • What are the two services that need to be running in XAMPP to get PHP working?

    -The two services that need to be running are the Apache server, which runs PHP, and the MySQL server, which provides access to the database.

  • Where should the 'htdocs' folder be located in relation to the XAMPP installation directory?

    -The 'htdocs' folder should be located within the XAMPP installation directory, typically found in the C drive or a specified installation directory.

  • What is the significance of the 'localhost' URL when working with a local server?

    -Typing 'localhost' in the browser URL directs you to the default page served by the local server, which in the case of XAMPP, is the 'htdocs' folder where your websites are stored.

  • How can you create a new website within the XAMPP server?

    -You can create a new website by creating a new folder within the 'htdocs' directory and then adding PHP files to it, which will be accessible via the 'localhost' URL with the folder's name.

  • What is the difference between creating a PHP file and an HTML file when setting up a website?

    -While both PHP and HTML files can contain HTML code, PHP files allow for the execution of PHP code, which can dynamically generate content for the website.

  • Why might Visual Studio Code show a 'cannot validate' message when working with PHP?

    -Visual Studio Code may show a 'cannot validate' message if it cannot find the PHP executable path. This can be resolved by manually setting the path to the PHP installation within the editor's settings.

Outlines

00:00

πŸ’» Setting Up a Local Server for PHP Development

The paragraph discusses the process of setting up a local server on a computer to develop websites using PHP. It reassures users that installing a server is safe and common practice among web developers. The narrator introduces various server options like LAMP, MAMP, XAMPP, and WAMP, and mentions Docker. The chosen server for the tutorial is XAMPP due to its ease of setup and familiarity. The tutorial guides users to download XAMPP from apachefriends.org, select the appropriate version for their operating system, and install it on their computer. It emphasizes the importance of noting the installation location and provides a step-by-step guide through the installation process, including handling potential pop-ups and setting up the server to run PHP and MySQL services.

05:01

🌐 Creating and Configuring a PHP Website Locally

This paragraph explains how to create and configure a PHP website using the XAMPP server. It details the process of deleting the default files in the 'htdocs' folder and creating a new folder for the user's website. The narrator demonstrates how to access the local server through the browser by typing 'localhost' and shows how to create multiple websites within the server. The tutorial then moves on to setting up the website in a preferred code editor, such as Visual Studio Code, and creating an 'index.php' file. It highlights the difference between HTML and PHP files and provides a solution for a common issue where Visual Studio Code might not recognize the PHP installation, guiding users to manually set the PHP executable path within the editor's settings.

10:02

πŸ”§ Testing PHP Code and Preparing for Further Tutorials

The final paragraph demonstrates testing PHP code by writing a simple 'echo' statement within PHP tags in an HTML file. It shows how to save the file, refresh the website in the browser, and see the output 'hello world', confirming that the PHP server is running correctly. The paragraph concludes by mentioning that the next video will cover PHP syntax, allowing users to write PHP code effectively within their websites. The tutorial ends on a positive note, expressing gratitude and anticipation for the continuation of the learning process.

Mindmap

Keywords

πŸ’‘Local Server

A local server is a software system that mimics the behavior of a live server, but operates on a user's personal computer. In the context of the video, setting up a local server is essential for developing and testing websites using PHP without needing to upload them to the internet. The video script mentions installing a local server as the first step for PHP web development, emphasizing its importance for offline website testing.

πŸ’‘PHP

PHP is a server-side scripting language designed for web development. It is used to create dynamic web pages and manage server-side operations. The video script discusses installing a local server specifically to run PHP, indicating that PHP is central to the video's theme of website development. The script also mentions creating PHP files instead of HTML for incorporating server-side logic into web pages.

πŸ’‘XAMPP

XAMPP is a widely-used software package that includes an Apache server, MySQL database, and PHP. The video script highlights XAMPP as the preferred choice for setting up a local server, due to its ease of setup and familiarity to the speaker. XAMPP is used to demonstrate how to run a PHP website on a local computer, showcasing its role in the development process.

πŸ’‘Apache Server

The Apache Server is a popular open-source web server software. It is one of the components of the XAMPP package and is necessary for running PHP scripts. The video script explains that starting the Apache server within XAMPP is a critical step to enable PHP execution, linking it directly to the functionality of a local development server.

πŸ’‘MySQL Server

MySQL Server is a relational database management system that is also part of the XAMPP package. It is used to manage and store data for websites. The script mentions starting the MySQL server alongside the Apache server to access databases, which is essential for dynamic website development where PHP interacts with databases.

πŸ’‘LAMP Stack

LAMP is an acronym for Linux, Apache, MySQL, and PHP, referring to a stack of software used to develop web applications. The video script lists LAMP as one of the many types of servers available for local development, indicating its popularity and relevance to the video's theme of setting up a PHP development environment.

πŸ’‘Docker

Docker is a platform that uses containers to enable developers to develop and deploy applications consistently across different environments. The video script mentions Docker as an alternative to traditional local server setups, suggesting it as a modern approach to setting up a development environment for PHP.

πŸ’‘localhost

In web development, 'localhost' refers to the local server on one's own computer. The video script instructs the viewer to type 'localhost' in the browser to access the local server, demonstrating how to view a PHP website running on the local server. This term is crucial for understanding how to access and test a website during development.

πŸ’‘Visual Studio Code

Visual Studio Code is a popular source-code editor that supports PHP development. The video script mentions setting up PHP within Visual Studio Code, highlighting the importance of having a suitable text editor for PHP development. It also touches on configuring the editor to recognize the PHP executable, which is necessary for syntax highlighting and code validation.

πŸ’‘PHP Syntax

PHP syntax refers to the rules governing the structure of PHP code. The video script briefly mentions that future content will cover PHP syntax, indicating that understanding the proper syntax is essential for writing functional PHP code. The script uses 'echo' as an example of PHP syntax for outputting 'hello world', demonstrating a basic PHP command.

Highlights

Installing a local server is essential for setting up a PHP website.

Local server installation is a common practice among web developers and should not be feared.

Various server software options exist, such as LAMP, VAMP, XAMPP, and LIMP.

Docker is another method mentioned for setting up a server environment.

XAMPP is chosen for its ease of setup and familiarity to the presenter.

ApacheFriends.org is a resource for downloading the XAMPP server software.

XAMPP allows running a PHP website locally without uploading to the internet.

Different versions of XAMPP are available for Windows, Linux, and Mac.

The installation process for XAMPP is straightforward and quick.

It's important to note the installation location for future configuration changes.

After installation, the XAMPP control panel can be accessed to start the Apache and MySQL services.

Docking the XAMPP control panel for easy access is recommended.

The htdocs folder in XAMPP is where websites are created and managed.

Creating a new folder in htdocs allows for the setup of a new local website.

PHP files can be created by changing the extension from .html to .php.

Visual Studio Code may require manual configuration to recognize the PHP executable.

A PHP file allows for both HTML and PHP code, maintaining website functionality.

The presenter demonstrates creating a simple PHP file that outputs 'Hello World'.

Next steps include learning PHP syntax for proper website development.

Transcripts

play00:00

so in order to set up a website using

play00:02

PHP we have to install what is called a

play00:05

local server and there's a lot of

play00:06

different software out there in the

play00:08

internet that you can get in order to

play00:09

install a local server on your computer

play00:10

I do know that some people are a little

play00:12

bit scared when it comes to installing a

play00:14

server on your computer and I just want

play00:15

to point out that there's nothing to be

play00:16

scared of everything is going to be fine

play00:18

and you're not going to install any sort

play00:20

of viruses anything setting up a server

play00:22

is something that is actually quite easy

play00:23

to do and anyone that does websites do

play00:26

it quite frequently so it's not

play00:27

something that new people should be

play00:29

scared of doing it's something that

play00:30

takes a couple of minutes to do and then

play00:31

you have something running on your

play00:33

computer so when it comes to installing

play00:34

a server there's many different servers

play00:36

you can choose from you have lamp Vamp

play00:38

xampp limp there's many different kinds

play00:42

of servers I did also hear about

play00:43

something called Docker from one of my

play00:45

subscribers in the last video so it's

play00:47

just interesting to see that there's so

play00:48

many different ways to do it what we're

play00:50

going to use however is a server called

play00:52

exam and the argument I have for using

play00:54

exam is that it's easy to set up and

play00:56

it's the one I've been using for many

play00:58

years I'm just really comfortable using

play01:00

exam amp so going inside your computer

play01:02

you can see that we have this website

play01:04

here that I just found called

play01:06

apachefriends.org I'll go ahead and

play01:08

leave a link to it so you can actually

play01:09

see it on screen here basically this is

play01:11

just going to be a piece of software

play01:12

that you're going to download that we're

play01:14

going to start and then it's going to

play01:16

run our server on our computer this

play01:18

means that we can actually run a website

play01:19

that is using PHP on our computer

play01:21

without having to upload our website to

play01:23

the Internet so this makes it very easy

play01:25

to just work on our website offline on

play01:28

our computer just like if it were to

play01:30

just make a HTML website as you can see

play01:32

we have a couple of different versions

play01:33

We can install in here we have for

play01:35

Windows Linux and mac and you can also

play01:37

see what version we're going to install

play01:39

in this case here this is going to be

play01:40

release 8.2.0 which is the PHP version

play01:43

that we're going to run on This Server

play01:44

here so once you've figured out what

play01:46

operating system you're sitting on I bet

play01:48

you probably know already you're going

play01:50

to go and click the button for that one

play01:51

so I'm going to click windows then it's

play01:53

going to install the program for you and

play01:55

if it doesn't you're just going to go

play01:56

ahead and click up here where it says

play01:57

click here

play01:58

then we're going to accept the Privacy

play02:00

pop-up and then we're just going to go

play02:01

and download the latest version which is

play02:04

8.2.0 so we have the latest version of

play02:06

PHP here so I'm going to go and download

play02:07

it now once you have it downloaded

play02:09

you're just going to go ahead and double

play02:10

click it so we can make sure to install

play02:11

it on our computer and it is important

play02:14

that you take note of where exactly you

play02:15

are installing it since we will have to

play02:17

go in and do a couple of changes to it

play02:19

now if you do get a pop-up like this

play02:21

don't worry too much about it since this

play02:23

is only going to be relevant if we were

play02:25

to install this inside our program files

play02:27

inside our main drive so with that I'm

play02:29

just going to click OK and then we're

play02:31

going to choose where we want to install

play02:32

this program so we're going to make sure

play02:33

all these are ticked on and then I'm

play02:35

going to click next then I'm going to

play02:37

select where I want to install this now

play02:38

as you can see I have it inside my C

play02:40

drive but not inside my program file so

play02:42

I can just go and install it directly on

play02:44

the C drive so I'm just going to go and

play02:45

do that click next then I'm going to

play02:48

choose a language in this case it's

play02:49

going to be English

play02:50

and then we can just go ahead and make

play02:52

it set up our program on our computer so

play02:54

it's just going to unpack and install

play02:55

now if you do insist that you want to

play02:57

install this inside your program files

play02:59

then I do have a link in the description

play03:01

where you can go in and actually make

play03:03

sure there's no warnings popping up when

play03:05

you try to run this program inside the

play03:07

program files but like I said if you

play03:09

just installed it directly inside the C

play03:11

drive like I did here we're not going to

play03:13

have any sort of issues now once you

play03:15

have it installed it's going to ask if

play03:16

you want to start the control panel now

play03:17

if you want to wait with later for now

play03:19

let's just go ahead and not do that

play03:21

because I do want to show where exactly

play03:22

this is installed so you can just open

play03:24

it up from inside your computer so with

play03:26

that I'm going to click finish and then

play03:28

you're going to go into a installed

play03:29

xampp which is inside in my case the C

play03:31

drive so I'm going to go into this PC

play03:33

inside my C drive then I'm going to go

play03:35

down to the bottom here and then you can

play03:37

see I have X amp inside the XM folder

play03:40

we're going to have the actual server

play03:41

files which means that we can scroll

play03:43

down to the bottom and actually run this

play03:45

control panel that we were just asked

play03:47

about so we can just go and click the

play03:49

xamppdashcontrol.exe open it up and then

play03:52

you can see we have a little software in

play03:54

here now the important thing for you to

play03:56

know about in here is that we have two

play03:57

services that we need in order to

play03:58

actually get PHP working one is going to

play04:01

be the Apache server which is the one

play04:03

that we need in order to actually run

play04:04

PHP and the second one is the MySQL

play04:07

server which is used in order to get

play04:09

access to our database so what I can do

play04:11

is I can start these two and then you

play04:13

can see we have them running another tip

play04:14

that I have for you is to make sure that

play04:16

you go down and actually dock this at

play04:17

the bottom since this is the program

play04:18

you're going to have to start every

play04:20

single time you need to start working on

play04:21

your website this means that we need to

play04:23

go down actually dot get or pin it to a

play04:25

taskbar so you have easy access to it

play04:27

next time with this running we now need

play04:29

to set up our website inside This Server

play04:31

here which is very easy to do so we're

play04:33

going to go back inside our folder where

play04:34

we have X amp installed and then you're

play04:36

going to go up to the top here and then

play04:38

you're going to go inside the folder

play04:39

called 8T Docs

play04:41

now in here you're going to find a bunch

play04:43

of files and these are just mainly to

play04:45

welcome you into the XM software so if I

play04:47

were to go inside my browser here and

play04:49

inside the URL I'm going to type

play04:50

localhost and then you can see we get

play04:53

this little website here and this is

play04:54

basically what we see with these files

play04:56

inside the HC docs folder this is

play04:58

basically what this is so we don't

play05:00

really need to have this so what I can

play05:02

do is I can go back inside our folder

play05:04

then I'm just going to delete all the

play05:06

files that we have in here now the

play05:07

important thing for you to know about

play05:08

this folder here is that this is going

play05:10

to be the place where you start creating

play05:11

your websites every time you want to

play05:13

create a new website inside This Server

play05:15

here so what we can do is we can go and

play05:17

create a new root folder so I'm going to

play05:19

right click and say I want to create a

play05:20

new folder I can call this one my

play05:23

website just to give it some kind of

play05:25

name of course you're more than welcome

play05:26

to call whatever you want it to be but

play05:28

in my case I'm just going to call it my

play05:29

website

play05:30

and now what you're going to notice is

play05:32

that inside the browser I can go back

play05:34

inside and type localhost and then you

play05:36

can see we get a list of all the

play05:38

different websites that I have inside

play05:39

this folder here this means that if I

play05:41

were to create a second website go in

play05:43

here create a second one my second

play05:47

website then you can see if I were to

play05:49

refresh in here we now have a new

play05:51

website that we can open up using this

play05:53

server here so if I were to click my

play05:55

website you can now see that we have

play05:56

this website open so going inside your

play05:59

preferred editor in my case this is

play06:01

going to be Visual Studio code I'm going

play06:02

to go ahead and create my first file

play06:04

which means that I'm going to save this

play06:07

file inside this folder that I just

play06:08

created a very good advice for you is to

play06:11

go inside and actually dock the HD docs

play06:13

folder on the side over here so I have

play06:15

quick access to it so what I can do is I

play06:16

can go ahead and go inside find xampp

play06:19

take my HD docs folder and dock it over

play06:21

here in the side so in this sort of way

play06:23

I have quick access to it whenever I

play06:25

have to open my folders here so I can

play06:27

click it go in here let's just go and

play06:29

delete that second website since we

play06:30

don't have actually need it I'm going to

play06:32

go inside my root folder and create a

play06:34

index dot PHP now this is the moment

play06:38

where some people are going to get

play06:39

confused if it came directly from my

play06:40

HTML course because when it comes to PHP

play06:43

we want to make sure that instead of

play06:44

creating HTML files we create a PHP file

play06:47

the main difference here is that we

play06:49

actually allow for PHP to be run inside

play06:51

these files here you can still write

play06:52

HTML just like you can before so you

play06:55

don't need to freak out about your

play06:56

website breaking or anything like that

play06:57

or not being able to write HTML inside

play06:59

these files just because it's called dot

play07:01

PHP and the same thing goes if you have

play07:03

an existing website that you want to

play07:05

convert into a PHP website you can just

play07:07

take all the different HTML files that

play07:09

you have and just change the extension

play07:11

from HTML to PHP on those and it's going

play07:14

to work inside your server and it's not

play07:16

going to break anything by the way I

play07:18

should say that because some people do

play07:20

worry that it is going to break

play07:21

something so I have to say it with this

play07:24

file here I'm going to save it and then

play07:26

you can see we have this front page here

play07:28

so if I were to go back inside my

play07:29

website I can refresh my website and

play07:32

then you can see we get a completely

play07:33

blank page and that's because right now

play07:35

we have the index file running inside

play07:37

our server now depending on the editor

play07:39

you're using because in some cases the

play07:41

editor is just going to work straight

play07:42

away but if you are using visual studio

play07:44

code it may ask you something down here

play07:47

at the bottom it says cannot validate

play07:49

since a PHP installation could not be

play07:51

found this is a very typical thing when

play07:53

you have a new version of Visual Studio

play07:55

code so if you have not set up PHP

play07:57

already inside this software you are

play08:00

going to have to set it up manually

play08:01

inside this text editor here so what you

play08:04

can do if you were quick enough is to

play08:06

make sure you opened up the link it gave

play08:07

you if not then we're going to go up

play08:10

into file go down to preferences go

play08:13

inside your settings then you're going

play08:14

to click on extensions and then you're

play08:16

going to go down to PHP and from in here

play08:19

you can actually set it to where you

play08:20

want to have the executable path set up

play08:22

inside a Json file so go to click this

play08:25

you can now see that we have this one

play08:27

line called

play08:29

psp.validate.executable path and this is

play08:31

where we need to set in the link for our

play08:33

PHP installation which is again inside

play08:35

the exam folder so if I were to go back

play08:37

inside the exam folder go back you can

play08:40

see we have a folder in here called PHP

play08:42

so I'm going to click it and then you

play08:44

can see we have a PHP dot exe file down

play08:47

here at the bottom this is the one we

play08:49

need to link to inside this executable

play08:52

path inside Visual Studio code so what I

play08:55

can do is I can copy my path here go

play08:57

back inside paste it inside the double

play08:59

quotes and then we're going to write

play09:01

backslash PHP dot exe now if you copied

play09:05

the path directly like I did here you

play09:07

want to make sure these are not

play09:08

backslashes but instead forward slashes

play09:10

otherwise you're going to get an error

play09:12

message

play09:13

and once you did this you're just going

play09:15

to go and save the file and then you can

play09:16

close it down and now we have it set up

play09:18

so that we can actually find the PHP

play09:20

version that we're using once we start

play09:22

creating a PHP website so just to kind

play09:24

of test this out let's go ahead and

play09:25

start up a regular HTML website now I'm

play09:28

just going to zoom in for you so you can

play09:30

actually see what is going on here and

play09:31

what I'm going to do is I'm going to go

play09:32

inside the body tags and create a pair

play09:35

of PHP tags which we use in order to

play09:37

write PHP inside a website so what I can

play09:39

do is I can write angle bracket question

play09:41

mark PHP question mark angle bracket and

play09:45

then anything that goes in between here

play09:46

is going to be considered as PHP so just

play09:49

to follow a very popular tradition here

play09:51

let's go ahead and go inside and write

play09:52

Echo

play09:54

double quotes hello world

play09:58

close it off with a semicolon save it go

play10:01

inside our website

play10:03

refresh it and then you can see we get

play10:05

hello world so with that we now know

play10:08

that we have a server running so we can

play10:09

actually write PHP code inside our

play10:11

website and have it display inside the

play10:13

browser and with that in the next video

play10:15

we're going to talk a bit about PHP

play10:16

syntax so we can actually write PHP

play10:18

properly inside our website so hope you

play10:20

enjoyed and I'll see you in the next

play10:22

video

play10:28

[Music]

play10:35

thank you

play10:38

[Music]

Rate This
β˜…
β˜…
β˜…
β˜…
β˜…

5.0 / 5 (0 votes)

Related Tags
Local ServerPHP SetupXAMPP GuideWeb DevelopmentServer InstallationPHP TutorialCoding BasicsWeb ServerDevelopment ToolsOnline Learning