“This is my 28th day of participating in the First Challenge 2022. For details: First Challenge 2022.”
Author: Mintimate
Blog: www.mintimate.cn
Minxml’s Blog, just to share with you
PHP
PHP is an open source general-purpose computer scripting language, especially suitable for web development and embedded in HTML.
The biggest feature is JIT, no NEED for JVM like Java; Many projects use PHP for quick builds.
However, I don’t use PHP much for Web development, so this article will focus on how to compile and install PHP on Linux.
Download PHP source code
It used to be the environment first. Change the plan this time. Download the source code first and select the PHP environment.
Mainly… PHP has too many optional dependencies…
Go to the PHP download page and download the PHP8 source code: www.php.net/downloads.p…
# Download PHP source codeWget HTTP: / / https://www.php.net/distributions/php-8.1.2.tar.gz# decompressionThe tar xf PHP - 8.1.2. Tar. Gz# enter
cdPHP - 8.1.2Copy the code
After that, use configure to check:
./configure -h
Copy the code
My demand is not high, PHP is building a h5ai:https://github.com/lrsjng/h5ai
PHP modules needed:
--with-curl \
--with-mysqli \
--with-openssl \
--with-pdo-mysql \
--with-jpeg \
--enable-gd \
--enable-fpm \
--enable-bcmath \
--enable-xml \
--with-zip \
--enable-mbstring \
--enable-sockets \
--with-zlib \
--enable-fileinfo \
--enable-exif
Copy the code
For this, the environment needs some lib library support.
Environment to prepare
PHP8 is installed on the Debian distribution of Linux, CentOS distribution of Linux, please note:
- The following dependencies need to be installed when you compile and install.
Also, if you feel that this installation method is too technical. In fact, you can also try the Pagoda panel to install PHP, or the package manager to install PHP.
This tutorial uses a Debian10 x64 virtual machine:
GCC
Compiling, of course, requires compiler support, which Nginx will need as well. GCC can be installed with build-essential. Similar to Xcode-Commnad for macOS. Terminal input:
apt install -y build-essential
Copy the code
pkg-config
Pkg-config is required and can be installed on Debian distribution Linux like this:
apt install -y pkg-config
Copy the code
Pkg-config is a dependency package manager.
libxml2
Libxml2 is required and can be installed on Debian distribution Linux like this:
apt install -y libxml2-dev
Copy the code
Literally, a dependency library for XML.
openssl
Openssl is required and can be installed on Debian distribution Linux. Openssl is required, this provides encryption support:
apt install -y openssl libssl-dev
Copy the code
sqlite3
Sqlite3 is required and can be installed on the Debian distribution Linux like this:
apt install -y libsqlite3-dev
Copy the code
zlib
You need zlib, which is very important for file compression
apt install zlib1g-dev
Copy the code
libcurl
You need libcurl to call curl:
apt install libcurl4-openssl-dev
Copy the code
libpng&libjpeg
I need libpng and libjpeg because I have images to work with:
apt install -y libpng-dev libjpeg-dev
Copy the code
oniguruma
Need oniguruma:
apt install -y libonig-dev
Copy the code
libzip
You need libzip to generate and process zip files:
apt install -y libzip-dev
Copy the code
Configuration and Compilation
The dependencies are now installed. You are ready to configure and compile. The first is configuration:
./configure \
--prefix=/usr/local/php8 \
--with-curl \
--with-mysqli \
--with-openssl \
--with-pdo-mysql \
--with-jpeg \
--enable-gd \
--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \
--enable-bcmath \
--enable-xml \
--with-zip \
--enable-mbstring \
--enable-sockets \
--with-zlib \
--enable-fileinfo \
--enable-exif
Copy the code
Among them:
--with-fpm-user
PHP FPM user, here I choose to belong to WWW user.--with-fpm-group
: indicates the user group to which PHP FPM belongs.
After that comes regular compilation:
make
Copy the code
Next, you are ready to install.
Installation and startup
Installation is too simple:
make install
Copy the code
We tried to start php-fpm:
./php8/sbin/php-fpm
Copy the code
It is found that the startup fails:
The solution is simple, let’s activate the default phP-fpm:
mv /usr/local/php8/etc/php-fpm.conf.default /usr/local/php8/etc/php-fpm.conf
mv /usr/local/php8/etc/php-fpm.d/www.conf.default /usr/local/php8/etc/php-fpm.d/www.conf
Copy the code
Then you can start:
./php8/sbin/php-fpm
Copy the code
Setting up daemons
Mysql > set systemctl Unit to manage php-fpm:
vim /usr/lib/systemd/system/php-fpm.service
Copy the code
Reload after:
# overload configuration
systemctl daemon-reload
# start PHP - FPM
systemctl start php-fpm
# Set boot to boot
systemctl enable php-fpm
Copy the code
Nginx set
Of course, don’t add PHP configuration files on Nginx:
# PHP - FPM configuration
location ~ [^/].php(/|$){
# try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
include fastcgi.conf;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
}
Copy the code
Take a look at the h5AI effect I configured:
Uninstall the PHP
We compiled PHP8, how to uninstall? Is simple:
Stop the php-fpm service
systemctl stop php-fpm
Delete Unit from systemctl
rm -rf /usr/lib/systemd/system/php-fpm.service
# overloading Systemctl
systemctl daemon-reload
# remove PHP
rm -rf /usr/local/php8
Copy the code
And you’re done. The above is I compiled PHP8 uninstall, you want to tool their situation appropriate change.
END
At this point, manual compilation of PHP8 is over. Maybe the package manager or Docker compiler is easier