[Drupal] Setting up a local environment for Drupal 9 Part 2~Installing PHP

Continuation from the previous session. This time, we will create a web server and a database, and install PHP.

First, let’s set up a web server. A web server’s role is to respond to our browser’s requests. When we send instructions to the web server through our browser, the web server returns a web page in response.

There are several types of web servers available, but here, we want to install the most famous one, Apache.

Use the following command to install Apache (execute it in the Teraterm console that you opened in the previous session).

$ dnf install httpd

In response to ‘Is this okay?’, enter ‘y’ for all of them.

Execute the following command.

↓Allow httpd in the firewall.

$ firewall-cmd –permanent –add-service=http

↓Restart the firewall.

$ firewall-cmd –reload
$ systemctl start httpd

Open your browser and connect to ‘http://CentOS-IP-address‘. If you see a screen like the one below, the Apache installation was successful.

Next, we will create a database.

o use a database, you need to install a Database Management System (DBMS). There are DBMS options like MySQL and SQLite, but this time we will install PostgreSQL.

Let’s install PostgreSQL with the following command.

$ dnf install postgresql-server

In response to ‘Is this okay?’, enter ‘y’ for all of them.

Next, we’ll configure PostgreSQL.

$ postgresql-setup initdb
$ systemctl start postgresql
$ systemctl status postgresql

If it shows ‘Active: active (running),’ you have succeeded.

Now, let’s configure PostgreSQL user settings.

↓Switch to the ‘postgres’ user:

$ su – postgres

↓Launch a tool that can execute SQL and other commands.

$ psql

↓x can be any character.

$ create user xxx login password ‘xxx’;

↓Creating a database.

$ create database myDrupal;

That concludes the setup for the web server (Apache) and the database (PostgreSQL).

We’d like to install Drupal right away, but it’s important to note that Drupal is built using the PHP programming language.

Therefore, we need to install PHP first. By default, PHP 7.2 gets installed, so we’ll need to configure it to install PHP 7.3.

Use the following command to configure the repository.

$ dnf module reset php
$ dnf module enable php:7.3

Let’s install PHP 7.3.

$ dnf install php
$ dnf install php-json
$ dnf install php-dom
$ dnf install php-pdo
$ dnf install php-gd
$ dnf install php-opcache
$ dnf install php-mbstring
$ dnf install php-pgsql

In response to ‘Is this okay?’, enter ‘y’ for all of them.

Execute the following command, and if version information is displayed, you have succeeded.

$ php -v

That’s all for this time. In the next session, we will finally proceed with installing Drupal.

I am studying Drupal using the following book.
It contains specific implementation methods for Drupal that are not found in Japanese books on Drupal 9.