Source compile Apache2.4 (httpd 2.4.43) + PHP7.4 on Linux and build a Web server --2 PHP introduction

Assumptions and preparations

Linux server building article

-Building a file server with Samba (CentOS 8.1 / openSUSE 15.1 / Ubuntu 20.04) -Source compilation of Apache2.4 + PHP7.4 on Linux --1 Apache introduction --Source compilation of Apache2.4 + PHP7.4 on Linux --2 PHP introduction [this article] -Source compilation of Apache2.4 + PHP7.4 on Linux --3 MySQL introduction

Last time built Apache httpd 2.4.43 on a web server by source compilation, but this time, continuing from the previous time, Apache is the backbone of the web application server. Introduce PHP 7.4 with source compilation (⑅ • ᴗ • ⑅)

environment

--Web server program: Apache 2.4.43 + PHP 7.4.6 (source compilation) --Client: Windows10 Pro --Server architecture: x64 (operation confirmed with Hyper-V 2nd generation) Linux distribution: CentOS 8.1 / openSUSE 15.1 Leap / Ubuntu 20.04 (all 64bit)

Premise

--User installed as root (in my verification, it is an administrator account called admin, and it is processed by sudo from there) --For all distributions, the firewall uses firewalld (does not use distribution-specific firewall commands) -Last time Apache installation completed (operation confirmed and built as a Web server)

Server conditions

IP address

--Client: 192.168.1.11 --Web server: 192.168.1.18 (verified with the same IP address for all distributions) --Affiliation network segment: 192.168.1.0/24 Webサーバー.png

Ability and version to download and install individual packages (as of June 2020)

Other required packages are installed with the distribution's standard package commands (dnf, apt, etc.) and do not need to be downloaded individually.

For download, you can access the official website, download from there and transfer it by FTP, or you can get it with wget if you know the URL of the download file, but the acquisition method is omitted.

Work procedure

PHP installation

Introduced libraries required for PHP source compilation

CentOS8.1


# dnf -y install libxml2 libxml2-devel sqlite-devel
# dnf -y install oniguruma-devel-6.8.2-1.el8.x86_64.rpm

openSUSE15.1


# zypper -n install libxml2-tools libxml2-devel sqlite3-devel oniguruma-devel

Up to PHP7.3, it was possible to install to handle multi-byte character strings without using SQLite and Oniguruma libraries, but in PHP7.4 it became mandatory for source compilation.

For CentOS 8.1 only, the Oniguruma library (oniguruma-devel-6.8.2-1.el8.x86_64.rpm) does not exist in the default package, so I brought it from the CentOS package download page.

As of June 2020: http://mirror.centos.org/centos/8/PowerTools/x86_64/os/Packages/oniguruma-devel-6.8.2-1.el8.x86_64.rpm

PHP source compilation

It will take about 40 minutes to compile. It's bigger than Apache, so you might want to take a break with a cup of coffee while compiling (\ * ˘︶˘ \ *) ...: \ * ♡

# cd [PHP 7.4.Directory where 6 archive files are located]
# tar xvzf php-7.4.6.tar.gz
# cd php-7.4.6/
# ./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysqli --with-pdo-mysql --enable-mbregex --enable-mbstring
# make
# make test

--MySQL enables PDO --Enable multibyte strings

"Make" and "make test" are commands that take a long time. If there are no errors on the way, compilation is complete. In addition, when I tested it with make test on CentOS 8.1, there were no bugs (๑ ・ ∞ ・ ๑)… It may be compatible with CentOS 8.1. php_test_fail.png

PHP installation

When the compilation is complete, install it.

# make install

Installing PHP SAPI module:       apache2handler
/usr/local/apache2/build/instdso.sh SH_LIBTOOL='/opt/apr-1.7.0/build-1/libtool' libphp7.la /usr/local/apache2/modules
/opt/apr-1.7.0/build-1/libtool --mode=install install libphp7.la /usr/local/apache2/modules/
libtool: install: install .libs/libphp7.so /usr/local/apache2/modules/libphp7.so
libtool: install: install .libs/libphp7.lai /usr/local/apache2/modules/libphp7.la
libtool: warning: remember to run 'libtool --finish /home/admin/php-7.4.6/libs'
chmod 755 /usr/local/apache2/modules/libphp7.so
[activating module `php7' in /usr/local/apache2/conf/httpd.conf]
Installing shared extensions:     /usr/local/lib/php/extensions/no-debug-zts-20190902/
Installing PHP CLI binary:        /usr/local/bin/
Installing PHP CLI man page:      /usr/local/php/man/man1/
Installing phpdbg binary:         /usr/local/bin/
Installing phpdbg man page:       /usr/local/php/man/man1/
Installing PHP CGI binary:        /usr/local/bin/
Installing PHP CGI man page:      /usr/local/php/man/man1/
Installing build environment:     /usr/local/lib/php/build/
Installing header files:          /usr/local/include/php/
Installing helper programs:       /usr/local/bin/
  program: phpize
  program: php-config
Installing man pages:             /usr/local/php/man/man1/
  page: phpize.1
  page: php-config.1
/home/admin/php-7.4.6/build/shtool install -c ext/phar/phar.phar /usr/local/bin
ln -s -f phar.phar /usr/local/bin/phar
Installing PDO headers:           /usr/local/include/php/ext/pdo/

Some of the PHP libraries are placed in multiple locations depending on the purpose, such as "/ usr / local / include / php /" and "/ usr / local / lib / php /". For openSUSE 15.1, some are located at "/ usr / local / lib64 / php /". Also, at this point, ** PHP DLLs (dynamic link libraries, corresponding to external extension applications) are automatically deployed to the Apache folder **.

Next, copy the PHP configuration file. First, copy php.ini to your PHP library folder / usr / local / lib /.

# cp php.ini-development /usr/local/lib/php.ini
# ls -l /usr/local/lib
Total 328
-rw-r--r--1 root root 144402 June 24 12:34 libz.a
lrwxrwxrwx 1 root root 14 June 24 12:34 libz.so -> libz.so.1.2.11
lrwxrwxrwx 1 root root 14 June 24 12:34 libz.so.1 -> libz.so.1.2.11
-rwxr-xr-x 1 root root 113656 June 24 12:34 libz.so.1.2.11
drwxr-xr-x 4 root root 37 June 24 16:19 php
-rw-r--r--1 root root 72278 June 24 16:21 php.ini
drwxr-xr-x 2 root root 21 June 24 12:34 pkgconfig

Settings on the Apache side

I need to make the PHP file recognizable by Apache, so edit it. The PHP DLL is automatically written in httpd.conf when PHP is installed, so there is no need to add it. All you have to do on the httpd.conf side is that Apache recognizes the PHP MIME type.

# vi /usr/local/apache2/conf/httpd.conf

/usr/local/apache2/conf/httpd.conf


…
<IfModule dir_module>
    DirectoryIndex index.html ← 「index.Add "php"
</IfModule>
…
<IfModule mime_module>
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    …
    AddType application/x-httpd-php .php ← add this line
</IfModule>
…

PHP preferences

Change the PHP character code and reference library settings.

When PHP is compiled and installed, the storage directory of php.ini differs depending on the distribution. ** openSUSE only, PHP is included in / usr / local / lib64 / **, so the difference in the library folder "lib" is confusing

CentOS8.1. Ubuntu20.04


# vi /usr/local/lib/php.ini

openSUSE15.1


# vi /usr/local/lib64/php.ini

php.ini


#Since the content is long, only the ones that have been partially modified and the ones that have been modified are listed. semicolon";"Is removed. ";It is described including the line that you just remove
output_buffering = On
default_charset = "UTF-8"
 [CentOS 8.1. Ubuntu 20.04] include_path = ".:/usr/local/include/php:/usr/local/lib/php"
 [openSUSE 15.1] include_path = ".:/usr/local/include/php:/usr/local/lib64/php"
extension_dir = "/usr/local/include/php/ext"
date.timezone = Asia/Tokyo
mbstring.language = Japanese
mbstring.encoding_translation = Off
mbstring.detect_order = UTF-8, SJIS, EUC-JP, JIS, ASCII
mbstring.substitute_character = none

PHP operation check

PHP confirmation page

First, create a PHP page for confirmation.

# vi /usr/local/apache2/htdocs/phpi.php

phpi.php


<?php phpinfo(); ?>

Why put PHP files in / usr / local / apache2 / htdocs /? ?? However, when Apache is installed by source compilation, the default storage folder for Web page data is "/ usr / local / apache2 / htdocs /". Well, you can change the storage location in httpd.conf, but this time I will omit it.

Restart apache

# systemctl stop httpd
# systemctl start httpd
# systemctl status httpd

If you do not restart, Apache will not work with the PHP module loaded, so stop it and restart it. After that, make sure that it is started with status. phpinfo.png PHP was recognized correctly! !! (\ * ´꒳` \ *)

pdo.png I can recognize PDO properly. Otherwise you won't be able to use MySQL and SQLite ... (´ • ̥ ̫ • ̥ `)

next time

Introduce MySQL to make the database available to PHP's web app server

Recommended Posts

Source compile Apache2.4 (httpd 2.4.43) + PHP7.4 on Linux and build a Web server --2 PHP introduction
Source compile Apache2.4 (httpd 2.4.43) + PHP7.4 on Linux to build a Web server --3 MySQL 8.0 introduction
Source compile Apache2.4 + PHP7.4 with Raspberry Pi and build a Web server --2 PHP introduction
Source compile Apache2.4 + PHP7.4 with Raspberry Pi and build a Web server ―― 1. Apache introduction
Source compile Apache2.4 + PHP7.4 with Raspberry Pi and build a web server --3. Use MySQL
Build Apache HTTP Server and Wildfly on Oracle Linux 8
Build a simple WebDAV server on Linux
Build a Samba server on Arch Linux
Build a CentOS Linux 8 environment with Docker and start Apache HTTP Server
Build a server on Linux and local network with Raspberry Pi NextCloud and desktop sharing
Install LAMP on Amazon Linux 2 and build a WordPress environment.
[Introduction to AWS] A memorandum of building a web server on AWS
Build a LAMP environment with Vagrant (Linux + Apache + MySQL + PHP)
Linux Web server construction (Ubuntu & Apache)
Run a Linux server on GCP
Build a Pypi cache server on QNAP
[UE4] Build DedicatedServer on Windows and Linux
Build an NFS server on Arch Linux
Install and Configure TigerVNC server on Linux
Start a web server using Bottle and Flask (I also tried using Apache)
Build Linux on a Windows environment. Steps to install Laradock and migrate
I want to pass an argument to a python function and execute it from PHP on a web server
Install Python3 and Django on Amazon Linux (EC2) and run your web server
Effective and simple Web server security measures "Linux"
Launch a web server with Python and Flask
Let's integrate Django and apache (httpd) on Mac! !!
Run the flask app on Cloud9 and Apache Httpd
Specify the volume on linux and make a sound
[Linux] [kernel module] Build and load a simple loadable kernel module
CTF beginner tried to build a problem server (web) [Problem]
Execute the command on the web server and display the result
Compile and install MySQL-python for python2.7 on amazon linux
[Linux] Create a self-signed certificate with Docker and apache
How to start a simple WEB server that can execute cgi of php and python
Build a web API server at explosive speed using hug
Set up a web server with CentOS7 + Anaconda + Django + Apache
How to integrate Apache httpd 2.4 and Tomcat 9 on Cent OS 8
Build a Python environment and transfer data to the server
Build a speed of light web API server with Falcon
Build a python environment on CentOS 7.7 for your home server