Please wait

Installing PHP

In this lesson, we'll take the first step in our journey by installing PHP along with other important software for developing websites.

Environments

First, let's understand the concept of an environment. In the programming world, an environment is a place where you can write, test, and run computer code. Think of it like a virtual workspace with all the tools you need to make a program work.

Generally, there are two types of environments, local and production.

Local Environment

A local environment refers to the setup you have on your personal computer or local machine, where you can write, test, and run your code. Local environments are primarily used for development and testing purposes and may not have the same level of security, performance, and reliability as the production environment.

This gives you, the developer, the opportunity to break things without disrupting your users. You can freely modify and make changes before shipping a program to the real world.

Production Environment

On the other hand, a production environment is a live environment where your code is actually deployed and running for end users.

A production environment is typically hosted on a remote server, and it is designed to handle the demands of real-world usage, including security, scalability, and reliability. The production environment is also monitored, managed, and maintained by a team of professionals to ensure optimal performance.

LAMP Stack

As you can imagine, we're going to be installing PHP in a local environment. However, we're not installing PHP alone.

PHP was designed for creating dynamic pages. It can't be used as a database or as a web server. Therefore, we'll need additional software to develop PHP applications. The most popular stack is called LAMP.

What is a stack?

A stack refers to a set of programs that are used together to build and run applications. Developers like to use acronyms to describe stacks. In the PHP world, the LAMP stack is the most popular stack.

LAMP is an acronym that stands for Linux, Apache, MySQL/MariaDB, and PHP. It is a popular open-source software stack used for building dynamic websites and web applications.

  • Linux: The operating system that runs the server and provides the foundation for the stack.
  • Apache: A popular web server software that is used to serve and host web pages.
  • MySQL/MariaDB: A relational database management system that is used to store and retrieve data for web applications.
  • PHP: A server-side scripting language used for creating dynamic web pages and web applications.

Each part of the LAMP stack works together to provide a complete solution for serving dynamic web content. The Linux operating system provides a secure and reliable platform for the stack to run on; Apache serves the web pages, MySQL stores the data, and PHP generates the dynamic content.

A strange reality

According to the Stack Overflow Developer Survey, a large majority of developers like to use Windows or Mac professionally. You don't have to use Linux if you don't want to.

Actually, for this book, I'll be using Windows. Therefore, we can refer to our stack as WAMP. If you're on a Mac, you can refer to your stack as MAMP.

Either way, the operating system is entirely interchangeable in our stack. Don't worry about having to switch operating systems just for the sake of learning PHP.

Installing XAMPP for Windows and Mac

The simplest way of installing PHP on Windows or Mac is to use a program called XAMPP. XAMPP is a free, open-source software stack that stands for Cross-Platform, Apache, MariaDB, PHP, and Perl.

We have the option of installing each software independently. However, that can be time-consuming and tedious since each software needs to be configured to work together. To expedite the process, we can use XAMPP, which performs these steps for us in a few minutes.

It is a web development platform that provides a complete package of software tools for building and running dynamic websites and web applications. XAMPP includes the Apache web server, the MariaDB database, and the PHP and Perl scripting languages, along with other tools, all pre-configured and ready to use. It is designed to make it easy for developers to set up a local web server environment for testing and developing their web applications.

What is Perl?

Perl is another programming language bundled with XAMPP. It's not necessary to use it for PHP development, nor will it be used throughout this book. XAMPP includes Perl for those who need it, along with the traditional LAMP stack.

You can download XAMPP over at Apache Friends. On the homepage, there will be an option to download XAMPP for windows or mac. Choose the option relevant to your operating system.

Click XAMPP for Windows/Mac on the homepage.
Click XAMPP for Windows/Mac on the homepage.

After XAMPP has been downloaded, you can navigate to your downloads to right-click on the exe file and select "run as administrator." The XAMPP setup wizard will boot up.

Click next to begin the installation
Click next to begin the installation

Click next. You'll eventually have the option to select the components you'd like to install. In most cases, the default selection should work fine. Please make sure PHP is selected.

Select all components
Select all components

Next, you must select a folder for installing XAMPP. I recommend installing XAMPP in a separate folder from your programs so that it's easier to access and find.

Select folder
Select folder

Afterward, you can select a language. Choose whichever you prefer. XAMPP can be used in multiple languages.

Select language
Select language

Finally, you can begin installing XAMPP.

Finalize XAMPP installation
Finalize XAMPP installation

This may take a few moments, so be patient.

XAMPP Installing
XAMPP Installing

After some time has passed, XAMPP should've been installed successfully. Congrats! You're well on your way to learning PHP.

Alternatives

XAMPP is not the only program available for installing the same software. While XAMPP is cross-platform, some Mac users may struggle with installing it. In that case, you can check out MAMP. Originally designed for Mac users, it also supports Windows.

Another great option is called Laragon. However, Laragon only works on Windows.

Replit

If you have limited permissions on your current machine, you can consider using Replit. It's an online IDE for software development. Support for PHP is available. I recommend using Replit if you don't want to spend time configuring your machine to learn PHP.

What about Docker

As you start to work on larger projects, these tools begin to show their flaws. It isn't easy to switch between environments without affecting other projects. Ideally, each project should have its own environment and be isolated from other projects.

For advanced PHP users, Docker is the clear winner. The major problem is that it can be overwhelming for beginners.

Don't worry; there's a chapter dedicated to using Docker + PHP. You will naturally come across it, assuming you're reading this book from beginning to end. For now, XAMPP, MAMP, or Laragon will suffice for what's covered.


Comments

Please read this before commenting