-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 (⑅ • ᴗ • ⑅)
--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)
--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)
--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
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.
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
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.
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
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>
…
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
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.
# 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. PHP was recognized correctly! !! (\ * ´꒳` \ *)
I can recognize PDO properly. Otherwise you won't be able to use MySQL and SQLite ... (´ • ̥ ̫ • ̥ `)
Introduce MySQL to make the database available to PHP's web app server