Home > Backend Development > PHP7 > Compile and install PHP7.4 (ubuntu)

Compile and install PHP7.4 (ubuntu)

จุ๊บ陈
Release: 2023-02-18 09:30:02
Original
4335 people have browsed it

This article is provided by the PHP7 tutorial column to introduce to you how to compile and install PHP7.4 (ubuntu). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.

Download PHP7.4 source code package

wget https://www.php.net/distributions/php-7.4.26.tar.gz
Copy after login

Unzip

tar -zxvf php-7.4.26.tar.gz
Copy after login

Install PHP dependency library

apt-get install libxml2 libxml2-dev sqlite3 libsqlite3-dev libcurl3-dev libxml-dev
Copy after login

Run ./configure

# cd 到php源码目录
./configure --prefix=/usr/local/php7 \
--with-config-file-path=/etc \
--with-fpm-user=test \
--with-fpm-group=test \
--with-curl --enable-fpm
Copy after login

Note: There are only a few extensions here, because if there are more, the compilation time will be very long. It is only used for testing compilation and installation of php, so there are not many extensions added. After the installation is complete, if you want to add more extensions later and forget the previous compilation parameters, you can see the previous compilation parameters in the source code directory cat config.nice. Then add new parameters and recompile (don’t forget to install the extended dependency library first).
Run make && make install
You can add the -j parameter when running make install, which means multiple jobs are working at the same time, and the compilation speed will be faster.

make install -j 2
Copy after login

Set PHP environment variables

1. Open the file

vim /etc/profile
Copy after login

2. Write the content

PATH=$PATH:/usr/local/php7/bin
export PATH
Copy after login

3. Make the environment The variable takes effect immediately

source /etc/profile
Copy after login

4. No error is reported when entering php -v, and the environment variable is set successfully

Configuration file

# 修改配置文件 
cd /usr/local/php7/etc 
cp php-fpm.conf.default php-fpm.conf 
cp php-fpm.d/www.conf.default php-fpm.d/www.conf  

# 修改pid文件位置
vim php-fpm.conf
# 添加这行
pid = /run/php-fpm.pid

# 创建php-fpm软链接  
ln -s /usr/local/php7/sbin/php-fpm /usr/sbin/php-fpm
Copy after login

Start and stop php-fpm

# 启动 
/usr/sbin/php-fpm 
# 关闭 
kill -INT `cat /run/php-fpm.pid` 
# 重启 
kill -USR2 `cat /run/php-fpm.pid`
Copy after login

Error handling

ERROR: [pool www] cannot get uid for user 'test'

1. Reason: Due to the previous settings during compilation, the user and user group of php-fpm are test [set casually] (--with-fpm-user=test --with-fpm-group= test), in fact, this user does not exist. There are two ways to deal with it:

  • Create the user and user group for test

  • Modify php-fpm.conf sets the user and user group to the same as nginx or apache user group

# 打开php-fpm.conf 
vim /usr/local/php7/etc/php-fpm.conf
# 找到位置修改为(我nignx用户组是 www-data user = www-data) 
group = www-data
Copy after login

2. ERROR: failed to retrieve TCP_INFO for socket: Protocol not available (92 )

Reason: I am using the Linux subsystem (ubuntu system) under Windows, which is not a completely virtual system. There will be some problems, but it does not affect it. Check in the host task manager that php-fpm has been started.

Compile and install PHP7.4 (ubuntu)

Solution: Modify php-fpm.conf

# 方法1: 
listen = /run/php-fpm.sock 
# 方法2 设置 
log_level = alert
Copy after login

Add daemon

# PHP源码里有自带的服务脚本,只需要复制到/etc/init.d 目录,加上执行权限就可以了。
# 要注意保持 /usr/local/php7/etc/php-fpm.conf 里面的 pid 文件位置是初始值。原来的是 pid = run/php-fpm.pid
# 在源码目录执行
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
systemctl daemon-reload

# 使用方法与上面相同,也可以使用 systemctl
service php-fpm start 
service php-fpm stop 
service php-fpm restart 
service php-fpm status
# 或者
systemctl start php-fpm
systemctl stop php-fpm
systemctl restart php-fpm
systemctl status php-fpm
Copy after login

The above is the detailed content of Compile and install PHP7.4 (ubuntu). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template