How To Install PHP & What Are Web Servers - PHP 8 Tutorial

Program With Gio
24 Nov 202008:29

Summary

TLDRThis video guide walks viewers through setting up a local PHP development environment using XAMPP, which bundles Apache, PHP, and MySQL. It explains the basics of web servers, how they process requests, and the importance of virtual hosts. The tutorial also touches on the limitations of all-in-one solutions like XAMPP for professional development and production environments, but recommends it for beginners and hobbyists. The video concludes with a demonstration of creating a simple 'Hello World' PHP file in the document root and emphasizes the need for a code editor for PHP development.

Takeaways

  • πŸ› οΈ Setting up a local development environment for PHP is essential before writing any code.
  • 🌐 A web server can be hardware, software, or both, and is responsible for processing HTTP requests and serving web pages.
  • πŸ“š Understanding how web servers work is important, especially when learning PHP, as they are the backbone of web applications.
  • πŸ“ˆ Web servers can host multiple websites using virtual hosts, sharing resources across different sites.
  • πŸ” Browsers communicate with web servers by sending requests and receiving responses, which can be inspected using developer tools.
  • πŸ’‘ Common errors like '404' occur when a requested file is not found, and can be observed in the browser's developer tools.
  • πŸ”‘ Two popular web servers are Apache and Nginx, each with their own advantages and suitable for different use cases.
  • πŸ‘ All-in-one solutions like XAMPP, MAMP, and WAMP simplify PHP setup by bundling necessary components and handling configurations.
  • 🚫 XAMPP is not recommended for production environments due to security and flexibility limitations.
  • πŸ›‘ When setting up XAMPP, ensure no other services are using the default ports to avoid conflicts.
  • πŸ“ The 'htdocs' directory in XAMPP is the document root where PHP project files should be placed for the web server to serve them.
  • πŸ’» A code editor is necessary for writing PHP code efficiently; options like Sublime Text, VS Code, and PHPStorm are recommended.

Q & A

  • What is the purpose of setting up a local development environment for PHP?

    -The purpose of setting up a local development environment for PHP is to allow developers to write, test, and debug PHP code on their own computers before deploying it to a live server.

  • What is a web server and what role does it play in serving web pages?

    -A web server is either a hardware or software system, or both, that stores web server software, source code, and other files. It processes incoming requests using protocols like HTTP, which browsers use to view web pages, and serves the appropriate content in response.

  • How can a single web server host multiple websites?

    -A single web server can host multiple websites using a feature called virtual hosts. This allows the server to allocate and share resources across multiple websites, even on the same server.

  • What happens when a browser requests a file from a web server?

    -When a browser requests a file, the web server processes the request. If it can locate the file, it responds with the content. If not, it responds with a 404 status code indicating the file was not found.

  • How can we inspect the requests made by a browser to a web server?

    -We can inspect the requests made by a browser to a web server by opening developer tools in the browser, either by right-clicking and selecting 'Inspect Element' or by pressing F12.

  • What are the two most common web servers used for PHP development?

    -The two most common web servers used for PHP development are Apache and Nginx.

  • Why might a beginner choose an all-in-one solution like XAMPP for PHP development?

    -A beginner might choose an all-in-one solution like XAMPP because it bundles the web server, PHP, a database, and other tools, handling the configuration automatically, making it easy for beginners to start PHP development quickly.

  • What are some limitations of using an all-in-one solution like XAMPP for PHP development?

    -Limitations of using XAMPP include a lack of flexibility, such as not being able to have multiple PHP versions installed at once, difficulty managing multiple projects, and security issues that make it unsuitable for production environments.

  • What is the document root in the context of a web server like XAMPP?

    -The document root is the directory where the web server, such as XAMPP's Apache, looks for files to serve to clients. In XAMPP, this is typically the 'htdocs' directory.

  • What is the significance of the 'index.php' file in a web server's document root?

    -The 'index.php' file is significant because the web server will look for this file in the document root to serve as the default page for a directory. If found, the server will use it to display the website; if not, it may list the directory contents.

  • Why is it recommended to use a code editor when writing PHP code?

    -It is recommended to use a code editor when writing PHP code because they provide features like syntax highlighting, code completion, and error detection that improve the coding experience and productivity, unlike basic text editors like Notepad.

Outlines

00:00

πŸ› οΈ Setting Up a Local PHP Development Environment

This paragraph introduces the need for a local development environment to write PHP and discusses the concept of web servers, which are essential for running PHP. It explains that a web server can be hardware, software, or both, and is responsible for processing incoming HTTP requests and serving web pages. The paragraph also covers virtual hosts, which allow a single server to host multiple websites by sharing resources. A diagram is mentioned to illustrate the communication process between the client and server, including the common 404 status code response when a file is not found. The viewer is encouraged to explore this process using developer tools in their browser. The paragraph concludes by mentioning the two most common web servers, Apache and Nginx, and introduces the concept of all-in-one solutions like XAMPP, MAMP, and WAMP, which simplify the setup process for beginners. It also touches on the limitations of such solutions, such as the inability to run multiple PHP versions simultaneously and the challenges of managing multiple projects and upgrading PHP versions.

05:00

πŸ“ Exploring XAMPP and PHP Project Structure

The second paragraph delves into the practical aspects of setting up a PHP environment using XAMPP, which bundles a web server, PHP, and a database, making it beginner-friendly. It addresses common issues like port conflicts when other services are running on the same port and suggests solutions like changing the port or stopping the conflicting service. The paragraph guides the viewer through accessing XAMPP's control panel, starting and stopping services, and editing configurations. It introduces the 'htdocs' directory as the document root where source code and project files should be placed. The viewer is shown how to create a simple 'index.php' file to display 'Hello World' on the local server. The paragraph also discusses the importance of choosing a code editor for PHP development, recommending Sublime Text, VS Code, and PHPStorm, and concludes by summarizing the steps taken to get PHP running locally with XAMPP and looking forward to writing the first PHP code in the next video.

Mindmap

Keywords

πŸ’‘PHP

PHP is a server-side scripting language designed for web development. It is used to create dynamic web pages and manage server-side logic. In the video, PHP is the main focus as the script discusses setting up a local development environment to write and test PHP code. The video aims to help beginners understand how to get started with PHP development.

πŸ’‘Local Development Environment

A local development environment is a setup on a developer's computer that mimics the production environment where the final application will run. It allows developers to write, test, and debug code without affecting the live system. The video provides a step-by-step guide on setting up such an environment for PHP using XAMPP.

πŸ’‘Web Server

A web server is a system that processes requests via HTTP, the protocol used for fetching resources from the web. It can be hardware, software, or both. In the context of the video, the web server is essential for running PHP scripts, as PHP is primarily executed on a server to generate dynamic web content. Apache and Nginx are mentioned as common web servers.

πŸ’‘HTTP Protocol

HTTP stands for Hypertext Transfer Protocol, which is the foundational protocol for data communication on the World Wide Web. It defines how messages are formatted and transmitted, and what actions Web servers and browsers should perform in response to various commands. The script explains that a web server processes incoming requests using the HTTP protocol.

πŸ’‘Virtual Hosts

Virtual hosts allow a single web server to host multiple websites by sharing the same resources. Each virtual host can have its own domain name and website content. The script mentions virtual hosts as a way for a web server to allocate and share resources across multiple websites.

πŸ’‘404 Status Code

A 404 status code is an HTTP response indicating that the requested resource could not be found on the server. In the video, it is used as an example of how a web server responds when it cannot locate the requested file.

πŸ’‘Developer Tools

Developer Tools are a set of utilities available in most web browsers that allow developers to inspect and debug web pages. The script suggests using developer tools to observe the requests and responses between the browser and the server, which is an essential part of understanding web development.

πŸ’‘Apache

Apache is a widely used open-source web server software. It is known for its reliability and flexibility. The video script mentions Apache as one of the two most common web servers, and the one that will be used for the PHP local development environment setup.

πŸ’‘XAMPP

XAMPP is a free and open-source cross-platform web server solution stack that includes Apache, MySQL, PHP, and Perl. It is designed to be easy to install and use, making it a popular choice for beginners setting up a local development environment for PHP. The video provides instructions on installing XAMPP.

πŸ’‘Document Root

The document root is the directory on the web server that serves as the filesystem root directory from where the web server serves files. In the context of the video, the script explains that the 'htdocs' directory in the XAMPP installation is the document root, where the user's PHP files and project files should be placed.

πŸ’‘Code Editor

A code editor is a type of text editor specifically designed for editing source code with various features such as syntax highlighting, line numbers, and auto-indentation. The video script suggests trying different code editors like Sublime Text, VS Code, and PHPStorm to find one that is comfortable for PHP development.

Highlights

Setting up a local development environment is the first step before writing any PHP code.

Understanding what a web server is and how it works is crucial since PHP runs on web servers.

A web server can refer to hardware, software, or both, and it processes incoming requests using protocols like HTTP.

Web servers can host multiple websites on the same server using virtual hosts, which share resources across sites.

The browser requests files from the server, and the server responds with the necessary HTML or an error code like 404 if the file is not found.

Common web servers include Apache and Nginx, each with its own pros and cons.

XAMPP, MAMP, and WAMP are all-in-one solutions that bundle a web server, PHP, database, and other tools, making it easy for beginners to set up a PHP environment.

Docker is a more flexible alternative for setting up a PHP environment, though it is not covered in this video.

XAMPP's simplicity comes with trade-offs like limited flexibility in having multiple PHP versions installed simultaneously.

XAMPP is not suited for production due to security concerns, leading to potential differences between local and production environments.

XAMPP is suitable for hobby projects and learning PHP quickly without complex setup.

Installing XAMPP involves downloading it, selecting necessary services, and addressing common errors related to port conflicts.

The XAMPP control panel allows managing services, viewing logs, and configuring settings.

In XAMPP, the 'htdocs' directory is the document root where source code and project files are stored.

When accessing 'localhost,' the server looks for an 'index.php' file in the document root to serve the website.

A code editor is essential for writing PHP code, with recommendations including Sublime Text, Atom, VS Code, and PHPStorm.

Transcripts

play00:00

before we can write any php we need to

play00:01

have the local development environment

play00:03

set up for it let's do that in this

play00:05

video and also talk a little bit about

play00:07

web servers because php mostly runs on

play00:09

the web server and it's a good idea to

play00:11

know what a web server is and how it

play00:13

works

play00:14

[Music]

play00:19

when talking about a web server you

play00:21

could either refer to a hardware or

play00:23

software or both hardware and software

play00:25

together a web server on the hardware is

play00:27

just a computer that stores the web

play00:29

server software source code and some

play00:31

other stuff a web server can process

play00:34

incoming requests using different

play00:35

protocols typically it's the http

play00:37

protocol which is the protocol used by

play00:39

the browser to view the web pages a web

play00:42

server can host either a single or

play00:44

multiple websites on the same server

play00:46

using the same resource this is done by

play00:48

something called virtual hosts where the

play00:50

single web server is able to allocate

play00:53

and share resources across multiple

play00:55

websites here is a simple diagram of how

play00:57

the communication between the client and

play00:59

the server happens when you visit the

play01:01

website the browser will request for the

play01:03

file from the server the web server will

play01:05

process this request and respond

play01:07

accordingly if it cannot locate the file

play01:10

then it will respond with the 404 status

play01:12

code we can actually see this in action

play01:14

by visiting any website and opening

play01:17

developer tools to inspect the requests

play01:19

you can either open dev tools by either

play01:21

right clicking on your mouse and then

play01:23

clicking on the inspect element or by

play01:25

hitting f12 on the keyboard let's

play01:27

refresh the page and see what happens as

play01:30

you can see the first request is what

play01:32

gets sent to the server and then it

play01:33

responds back with the html that then

play01:36

gets rendered on the screen don't worry

play01:38

about the other requests for now also

play01:40

don't worry if this is new to you or if

play01:42

it doesn't really make sense you don't

play01:44

really need to worry about this too much

play01:46

at this stage of your learning i just

play01:48

wanted to explain how it works and what

play01:50

web servers are so things make more

play01:52

sense when you're actually installing

play01:54

the necessary software to run the php

play01:56

the two most common web servers are

play01:58

apache and nginx they both have their

play02:01

pros and cons i'm not going to get into

play02:03

much detail on which one is better or

play02:06

which one to choose because i don't want

play02:07

to overwhelm you with too much

play02:09

information we'll be using the apache

play02:11

for now because it comes with the

play02:13

software bundled in that we're going to

play02:15

be installing in this video there are

play02:17

many different ways you could have php

play02:19

installed in your local environment you

play02:20

might even have it installed on your os

play02:23

if you have php manually installed you

play02:25

will need a local server either apache

play02:27

or nginx you would need to install that

play02:30

manually yourself later if you decided

play02:32

that you also needed a database you

play02:34

would need to install that as well this

play02:35

does not sound beginner friendly you

play02:38

probably just want to get it installed

play02:39

as simply and as fast as possible this

play02:42

is why all in one solutions like xampp

play02:44

mamp and wamp exist they bundle in the

play02:46

web server php database and some other

play02:49

useful tools and handle the

play02:51

configuration for you which makes it

play02:53

very easy for beginners to get started

play02:55

with php some other better alternatives

play02:57

to xampp to get a php environment set up

play03:00

are virtual machines or containers i

play03:02

personally don't use xampp i use docker

play03:05

and i will have a separate video about

play03:07

getting php environment setup using

play03:09

docker but don't worry about it right

play03:11

now we are not going to be installing

play03:13

docker right now we are going to be

play03:15

installing xampp this simplicity though

play03:18

comes with a trade-off and that is

play03:19

flexibility one of those trade-offs is

play03:22

you cannot have multiple php versions

play03:24

installed at the same time out of the

play03:26

box there are ways you could achieve

play03:27

this with xampp but it's not simple and

play03:30

requires some work you may also need a

play03:32

different version of the database per

play03:34

project which goes back to the point one

play03:36

it also becomes harder to manage and

play03:38

maintain multiple projects especially

play03:40

when you're trying to upgrade your

play03:42

current php version it is not suited for

play03:45

production due to its security so i

play03:47

would not be advising using x-amp for

play03:49

production and because you would not use

play03:51

x-amp in production you would always

play03:53

have some sort of disconnect differences

play03:56

between your local setup and your

play03:57

production these differences could be

play03:59

minor if you know what you're doing or

play04:01

you could be major like a difference in

play04:03

php versions or the packages it's

play04:05

installed for example which could yield

play04:07

to issues like it works on my local

play04:09

machine but it does not work in

play04:11

production there is absolutely nothing

play04:13

wrong with using xampp for hobby

play04:15

projects or just playing around with php

play04:17

and getting it running as fast as

play04:18

possible it is entirely up to you how

play04:20

you want to get your local environment

play04:22

set up or what tools you want to use if

play04:24

you are a beginner then i would suggest

play04:26

to stick with xampp for now and then

play04:28

look for alternatives once you're

play04:30

comfortable so just go to the xampp

play04:32

website download it and follow the

play04:34

instructions to install on one of the

play04:35

steps it will ask you what services you

play04:38

want to include in the bundle you could

play04:39

unselect the ones that you do not

play04:42

care or you don't want to use for this

play04:44

course though we're only going to be

play04:46

using database and php so we don't need

play04:48

all other services so we could disable

play04:50

them for now

play04:52

let's start the control panel and

play04:53

briefly review it right away as you can

play04:56

see i'm getting an error and this is

play04:57

actually a pretty common error for cases

play05:00

where you may already be running some

play05:02

other servers on the same port for

play05:04

example in my case i have a database

play05:06

running in a docker container on the

play05:08

same port 3306 and because this port is

play05:11

already taken xampp can start the

play05:14

database service this can easily be

play05:16

fixed by turning off the service that's

play05:17

currently running on port 3306 or we

play05:20

could use a different port to run it

play05:22

same thing can happen for apache for

play05:24

example so if you see such errors just

play05:26

check what services are using that port

play05:28

and either disable or change them we

play05:30

won't be needing the database right now

play05:32

so we can ignore this error for now and

play05:34

fix it once we actually start using the

play05:36

database you could also change the

play05:38

xampp's configuration you could change

play05:40

the default text editor or you could

play05:42

enable some of the services to start

play05:44

automatically whenever the xm starts you

play05:46

could also stop and start the necessary

play05:49

services from the control panel view and

play05:51

edit configuration files and check logs

play05:54

don't worry about the config files for

play05:56

now we'll touch on that topic in a

play05:57

separate video let's head over to the

play05:59

browser and type http localhost and hit

play06:02

enter it opens the welcome dashboard

play06:04

page for xampp which means that the web

play06:06

server is working as expected you might

play06:09

be wondering where you would put your

play06:10

source code and that depends mainly on

play06:12

how the web server is configured so

play06:14

let's open xampp control panel and click

play06:17

on the explorer button here this opens

play06:19

the directory where xampp is installed

play06:22

and here we see that that's where apache

play06:24

phpmysql and other services are

play06:26

installed but you don't have to worry

play06:28

about these directories for now the only

play06:29

thing that you need to know is that

play06:31

htdocs right here this is your document

play06:34

root which means that this is where your

play06:35

source code and project files will go to

play06:38

if we open that we see that this is the

play06:40

source code for this dashboard page that

play06:42

we see on the localhost so we could go

play06:44

ahead and delete this because we're

play06:46

going to be adding our own files

play06:48

now what happens when you go to

play06:50

localhost is that it will try to locate

play06:52

index.php within your document root if

play06:55

it finds the index.php then it will

play06:57

serve the website using that index.php

play07:00

if it cannot find the index.php then it

play07:02

will just list the files and directories

play07:04

within the document root so for example

play07:07

right now we don't have any content if i

play07:09

were to create just some file here

play07:12

and go to localhost

play07:14

we see that it just lists the document

play07:16

tree so what we can do is we can create

play07:18

directories here so we can call this

play07:21

program with geo

play07:23

and here we could create

play07:26

an index dot php and we could just say

play07:30

hello world for now now a quick note

play07:32

here we're not writing a php code yet

play07:35

this is just a simple uh text so if we

play07:38

go to the local host now we see the

play07:40

program with geo directory if we click

play07:42

that we see hello world as you noticed

play07:45

we have not written a php code yet we'll

play07:48

do that on the next video where we'll go

play07:49

over the basic syntax before we can do

play07:52

that though we need a code editor

play07:54

because even though you could write php

play07:55

in notepad it's not so pleasant to work

play07:58

with there are a lot of options when it

play08:00

comes to code editors try some of them

play08:02

and pick the one that you like and feel

play08:03

more comfortable with sublime text adam

play08:06

vs code and phpstorm are the ones that i

play08:08

recommend though it's up to you what you

play08:10

use this is it for this video now you

play08:12

know how to get up and running with php

play08:14

on your local environment using xampp

play08:16

but in addition to that you also know

play08:18

what web server is and how it works

play08:20

thank you for watching hope you liked

play08:22

this video please hit like and subscribe

play08:23

and i will see you on the next one where

play08:25

we'll go over the syntax and write our

play08:27

first php code

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

5.0 / 5 (0 votes)

Related Tags
PHP DevelopmentLocal EnvironmentXAMPP SetupWeb ServerApache ServerNginx ServerVirtual HostsPHP SyntaxCode EditorDevelopment Tools