Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Chapter 1 Getting Started

For example,

<code>
sudo ln -s /usr/local/bin/docker-compose /usr/bin/
docker-compose
</code>

Optionally, install command completion for the bash and zsh shells.
Test the installation.

<code>
$ docker-compose --version
</code>

The Development Environment


Now that you have Docker installed and ready to go, you need the YAML
files for your project to set up your development environment. Go to
https://github.com/apress/php8-basics and click the Download ZIP
button, shown in Figure 1-5.

Figure 1-5. yaml files for your project

11
Chapter 1 Getting Started

Once you have the ZIP file downloaded, unzip it in a directory of your
choosing. We used ~/ (my users home directory) ~/coding. Once
unzipped, your directory structure should look something like Figure 1-6.

Figure 1-6. Unzipped project folder

Inside this directory will be all the information needed for Docker to
start the development environment.
Go ahead and run

<code>
docker-compose up
</code>

and watch Docker spin up (Figure 1-7).

Figure 1-7. Running the docker-compose command

Next, point your browser to

<code>
http://localhost:8000
</code>

12
Chapter 1 Getting Started

and you should see the table of contents page for this book and
verification that the database has connected successfully. Go to the
command prompt and type

<code>
docker ps
</code>

This command shows you any containers that Docker has or is


currently using. Here you can see the mysql, nginx, and beginning php
containers. One last thing to verify is that you can run PHP from within the
PHP container. From the command line, type

<code>
docker exe -ti php-app bash
</code>

This connects you, much like ssh, to the container itself. From here, go
into the Chapter1 directory.

<code>
cd Chapter1
</code>

Type

<code>
php first_script.php
</code>

You should see this output:

<code>
Output here
</code>

13
Chapter 1 Getting Started

Summary
In this chapter, you learned in general the why, what, and how of using the
PHP programming language in the development world. We introduced
why you want to use PHP, Nginx, and MySQL and their benefits. As
next steps, you learned how to install the Docker tool, which is an open
platform for developing, shipping, and running applications. Finally,
you saw why you needed the YAML files for your project to set up your
development environment.
In the next chapter, we will explain how programming languages use
variables to store and manipulate data and to build useful tools in PHP.

14
CHAPTER 2

PHP Fundamentals
In order to build useful tools in PHP, you need to know how to manipulate
data. Programming languages use variables to store and manipulate data.
In this chapter, you will learn how programming languages use
variables to store and manipulate data and to build useful tools in PHP.
Additionally, you’ll explore the following topics:

• Using errors as tools

• Objects

• Verbs: GET and POST

Variables
PHP has a few rules when it comes to variables:
• A variable must start with the $ sign, followed by the
name of the variable.

• A variable name must start with a letter or the


underscore character.

• A variable name cannot start with a number.

• A variable name can only contain alpha-numeric


characters and underscores (A-z, 0-9, and _ ).

• Variable names are case-sensitive ($pants and $PANTS


are two different variables).

© Gunnard Engebreth, Satej Kumar Sahu 2023 15


G. Engebreth and S. K. Sahu, PHP 8 Basics, https://doi.org/10.1007/978-1-4842-8082-9_2

You might also like