This is the sixth day of my participation in the First Challenge 2022. For details: First Challenge 2022.


  • 🤟 blogger introduction: CSDN, Toutiao, Zhihu and other platforms quality bloggers, the whole network fans 2W +
  • 💬 If the article is helpful to you, welcome to follow, like, bookmark (click three links) and subscribe

First, PHP environment installation process

Note: RECENTLY I am building a personal website, and the environment is useful to PHP, which is hereby recorded. This installation case is based on THE PHP8.0.0 version as an example. It is recommended to install the dependency of the third step before the installation, so that there is no need to solve the problems one by one during the installation.

1. Download the PHP package (online or compressed)

Suggestion: Create the address of the compressed package in advance to facilitate file management. The download address is www.php.net/downloads.p…

Online download (offline download to the server if the network speed is slow) : wget www.php.net/distributio…

After offline downloading, you can run the rz command to upload the file to the server: rz-be file name


2. Decompress the package

Execute the code: tar-xvf php-8.0.0.tar.gz


3. Specify the configuration information

Note: Before compiling, you need to configure the storage location of the compiled and installed files and some installed components. Before installation, you must be clear about them. If you do not know about them, you are advised to use the code in this document to avoid exceptions.

Understand the concept:

1, the source code installation needs to go through steps: configure, compile, install.

Configure, on the other hand, is an executable that configures many options./ Configure –help

The –prefix option configures the installation path of the source code, and the –with-config-file-path option configures the location of the PHP configuration file (php.ini).

3. The benefits of specifying a storage path can be compared to the software installation steps in Windows and other graphical systems. The location of the software can be specified during installation to facilitate the unified management of the subsequent software (delete, search, etc.).

Note: the following code must be on the same line, it is recommended to copy to the text to see if it is on the same line, and then copy to the server to execute (otherwise there will be a lot of puzzling problems, I believe you do not want to spend a few days to deal with).

/configure –help =./configure –help =./configure –help =./configure –help =.

./configure --prefix=/usr/local/install/php8 --with-config-file-path=/usr/local/install/php8/etc --with-curl --with-freetype --enable-gd --with-jpeg  --with-gettext --with-kerberos --with-libdir=lib64 --with-libxml --with-mysqli --with-openssl --with-pdo-mysql  --with-pdo-sqlite --with-pear --enable-sockets --with-mhash --with-ldap-sasl --with-xsl --with-zlib --with-zip -with-bz2 --with-iconv  --enable-fpm --enable-pdo  --enable-bcmath  --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl  --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-xml --enable-sysvsem --enable-cli --enable-opcache --enable-intl --enable-calendar --enable-static --enable-mysqlnd
Copy the code

5. After the configuration is successful, the following message is displayed:


4. Possible exceptions and solutions during compilation

Before executing the configure script, the new server needs to integrate the existing dependency scripts. The following describes each exception:

yum install dnf
dnf install libxml2-devel
dnf install sqlite-devel
dnf -y install bzip2-devel
dnf -y install libcurl-devel
dnf -y install libpng-devel
dnf -y install libjpeg-devel
dnf -y install freetype-devel
dnf -y install libicu-devel
yum install oniguruma-devel -y
dnf -y install libxslt-devel
dnf -y install libzip-devel
Copy the code

1. Abnormal information:

Configure: error: Package requirements (libxmL-2.0 >= 2.9.0) were not met: No Package 'libxmL-2.0' found. Configure: error: Package requirements (libxmL-2.0 >= 2.9.0) were not met: No Package 'libxmL-2.0' foundCopy the code

DNF install libxml2-devel

2. Abnormal information:

-bash: dnf: command not found
Copy the code

Yum install DNF

3. Abnormal information:

Configure: error: Package requirements (SQlite3 > 3.7.4) were not met: No Package 'sqlite3' foundCopy the code

DNF install sqlite-devel

4. Abnormal information:

checking for BZip2 in default path... not found
configure: error: Please reinstall the BZip2 distribution
Copy the code

DNF -y install bzip2-devel

5. Abnormal information:

Configure: error: Package requirements (libcurl >= 7.29.0) were not met: No Package 'libcurl' foundCopy the code

DNF -y install libcurl-devel

6. Abnormal Information:

configure: error: Package requirements (libpng) were not met:
No package 'libpng' found
Copy the code

DNF -y install libpng-devel

7. Abnormal information:

configure: error: Package requirements (libjpeg) were not met:
Package 'libjpeg', required by 'virtual:world', not found
Copy the code

DNF -y install libjpeg-devel

8. Abnormal Information:

configure: error: Package requirements (freetype2) were not met:
Package 'freetype2', required by 'virtual:world', not found
Copy the code

DNF -y install freetype-devel

9. Abnormal information:

Configure: error: Package requirements (ICU-UC >= 50.1 ICU-IO ICU-i18n) were not met: Package 'icu-uc', required by 'virtual:world', not found Package 'icu-io', required by 'virtual:world', not found Package 'icu-i18n', required by 'virtual:world', not foundCopy the code

DNF -y install libicu-devel

10. Abnormal Information:

configure: error: Package requirements (oniguruma) were not met:
No package 'oniguruma' found
Copy the code

Yum install oniguruma-devel-y

11. Abnormal Information:

Configure: error: Package requirements (libxslt >= 1.1.0) were not met: No Package 'libxslt' foundCopy the code

DNF -y install libxslt-devel

12. Abnormal Information:

Configure: error: Package requirements (libzip >= 0.11 libzip! = 1.3.1 libzip! Were not met: Package 'libzip', required by 'virtual:world', not foundCopy the code

DNF -y install libzip-devel

13. Abnormal Information:

Configure: error: Package requirements (libzip >= 0.11 libzip! = 1.3.1 libzip! Requested 'libzip >= 0.11' but version of libzip is 0.10.1Copy the code

Solution:

Yum remove libzip-devel libzip yum remove libzip-devel libzip

2, online download the corresponding version: wget libzip.org/download/li… –no-check-certificate

4. Go to the decompressed folder and run the configuration script./confugure

5, compile and install: make & make install

6, installation is complete, the query/usr/local/lib directory pkgconfig directory, any execute commands export PKG_CONFIG_PATH = “/ usr/local/lib/pkgconfig/” to specify PKG_CONFIG_PATH, Then re-execute the decompressed PHP folder and execute the./configure script


5. Compile and install

After configuration, execute make to compile the source code, execute make install to install the source code, or execute both at the same time (note: both compile and install are executed in the decompressed PHP folder — that is, the directory where the configure script exists):

1. Compile: make

2, Install: make install

Cc: Internal compiler error: Killed (Program CC1)

Cause: There is a high probability that the memory is insufficient. You can use swap partition to solve the problem first, and then delete it after compiling and installing.

Solution:

sudo dd if=/dev/zero of=/swapfile bs=64M count=16
sudo mkswap /swapfile
sudo swapon /swapfile
Copy the code

Cancel swap partition:

sudo swapoff /swapfile
sudo rm /swapfile
Copy the code

6. Check the PHP installation

Go to the bin directory of the installation path specified by configure and check the version:

/usr/local/install/php8/bin/php --version
Copy the code

Execution Result:


2. Manage various configuration files

1, generate the php.ini configuration file (in the PHP source package directory) :

cp php.ini-production /usr/local/install/php8/etc/php.ini
Copy the code

Create WWW configuration file:

cd /usr/local/install/php8/etc/php-fpm.d/
cp www.conf.default www.conf
Copy the code

3, generate phP-fPM configuration file:

cd /usr/local/install/php8/etc/
cp php-fpm.conf.default php-fpm.conf
Copy the code

4, generate phP-fPM executable:

- create storage configuration file directory mkdir/usr/local/install/php8 / FPM - a copy of FPM executable scripts from source cp/usr/local/PHP - 8.0.0 / PHP/sapi/FPM/init. D.p HP - FPM / usr/local/install/php8 / FPM/PHP - FPM - PHP - FPM modify chmod 740 for an executable file/usr/local/install/php8 / FPM/PHP - FPMCopy the code

Manage PHP

Php-fpm (FastCGI Process Manager: FastCGI Process Manager) is a PHPFastCGI Manager designed to integrate FastCGI Process management into THE PHP package.

Advantages: PhP-FPM has more CPU and memory control than Spawn FCGI, and it crashes easily and has to be monitored with crontab instead of phP-FPM.

1. Start php-fpm:

/usr/local/install/php8/fpm/php-fpm start
Copy the code

2. Check whether the php-fpm process is started successfully

ps aux | grep php | grep -v grep
Copy the code

3. Check the port occupied by pfP-FPM

ss -lntp | grep php
Copy the code

4. Run PHP –version. PHP command not found

1. Modify the configuration file
vim /etc/profile
 
// add the PHP environment variable to the bin directory specified by the configure script.
PATH=$PATH:/usr/local/install/php8/bin
export PATH
    
// Refresh the configuration file
source /etc/profile
    
Copy the code

You’re done


Write in the last

If you feel the article is helpful, please give the blogger a thumbs-up, favorites, follow. The following bloggers will bring more quality and quality articles.

If you want to learn more and learn more about open source projects, please click below to add a blogger and enter the technical circle (all resources are free, but you are required to have long-term interest in the circle, if it is just an impulse, it is not recommended to join, after all, the quota is limited).

Join the technical circle, in addition to free guidance for building problems, but also the first time to receive the latest industry consultation and know the professional leaders!