This article brings you relevant knowledge about PHP. It mainly introduces how to compile and install PHP in the Centos system and how to configure it correctly. The steps are very detailed! Friends who are interested can take a look below. I hope it will be helpful to everyone.
PHP (full name: PHP: Hypertext Preprocessor, i.e. "PHP: Hypertext Preprocessor") is an open source general-purpose computer scripting language, especially suitable for Developed for the web and can be embedded in HTML. The syntax of PHP draws on the characteristics of popular computer languages such as C language, Java and Perl, making it easy for ordinary programmers to learn. The main goal of PHP is to allow web developers to write dynamic pages quickly.
Preparation
Download the installation file
To be safe, use php official website download: https: //www.php.net/downloads
The download speed using the official website is slower, but the security is guaranteed. If you have no requirements for security, you can also search for related mirrors on Baidu. This article chooses the latest stable version PHP 8.1.6
wget https://www.php.net/distributions/php-8.1.6.tar.gz tar -zxvf php-8.1.6.tar.gz cd php-8.1.6
yum install libxml2 libxml2-devel libsqlite3x-devel openssl bzip2 libcurl-devel libcurl libjpeg libpng freetype gmp libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel zlib zlib-devel glibc glib2 ncurses curl gdbm-devel db4-devel libXpm-devel libX11-devel gd-devel gmp-devel expat-devel xmlrpc-c xmlrpc-c-devel libicu-devel libmcrypt-devel libmemcached-devel -y
Note: The current Centos official image has stopped serving,
yum install
Installationdevel
software, if an error is reported and cannot be installed, try overwriting the file contents inCentOS-Base.repo.rpmsave
in the/etc/yum.repos.d/
directory. ToCentOS-Linux-BaseOS.repo
,CentOS-AppStream.repo.rpmsave
is overwritten toCentOS-Linux-AppStream.repo
, please make a backup before operation
Because there is no oniguruma package in the yum source, here we use the github source code to compile and install. Project address: https://github.com/kkos/oniguruma
wget https://github.com/kkos/oniguruma/releases/download/v6.9.8/onig-6.9.8.tar.gz tar -zxvf onig-6.9.8.tar.gz cd onig-6.9.8 ./configure --prefix=/usr make && make install
For security reasons, we need to create a user for running php. Generally, this user is prohibited from logging in. This article creates a user The name and user group are both www
, this name can be customized
# 创建用户组 groupadd www # 创建用户 useradd -g www www -M -s /sbin/nologin
- ##-g www
Specify user group
- -M
Do not create a home directory (a home directory is not required to run the program)
- -s /sbin/nologin
Do not allow login , more secure
Compile and install# 生成编译文件
./configure --prefix=/www/server/php81 --with-config-file-path=/www/server/php81/etc --enable-fpm --with-fpm-group=www --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype --with-mcrypt --with-jpeg --with-png -with-zlib --with-libxml-dir --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl -enable-mbstring --enable-gd --with-openssl --with-mhash --enable-pcntl --with-xmlrpc --enable-zip --enable-soap --with-gettext --enable-opcache --with-xsl --enable-sockets --enable-mbregex --enable-ftp --with-webp
# 编译并安装
make && make install
# 复制配置文件
cp php.ini-production /www/server/php81/etc/php.ini
# 或者使用 development
cp php.ini-development /www/server/php81/etc/php.ini
apache , you need to add
--with-apxs2=/www/server/apache/bin/apxs in the compilation parameters, and the
--enable-fpm parameter can be removed, where
/www/server/apache is the installation directory of
apache. After compilation, uncomment the
php_module in the configuration file of
apache. , this article will not go into details about
apache configuration.
Configuration
Configuration environment variables
In/etc/profile Add
PATH=$PATH:/www/server/php81/bin && export PATH, and use
source /etc/profile to make the configuration take effect immediately.
php-fpm Soft link:
ln -s /www/server/php81/sbin/php-fpm /www/server/php81/bin/php-fpm
nginx configuration php
Copy the configuration file. If you have copied it before, please skip this step:cp /www/server/php81/etc/php-fpm.conf.default /www/server/php81/etc/php-fpm.conf cp /www/server/php81/etc/php-fpm.d/www.conf.default /www/server/php81/etc/php-fpm.d/www.confStart php-fpm:
/www/server/php81/sbin/php-fpmModify nginx configuration fileEdit
nginx.conf file, add the following content under the corresponding
server:
location ~ [^/]\.php(/|$) { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; }
, create a new phpinfo.php
file in the root directory of the website: <pre class='brush:php;toolbar:false;'><?php
phpinfo();</pre>
推荐学习:《PHP视频教程》
The above is the detailed content of Detailed steps to compile, install and configure php8 in Centos. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 English version
Recommended: Win version, supports code prompts!

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.
