ubuntu2204编译安装php7.4.33
//
# ubuntu2204编译安装php7.4.33
源码编译目录:/opt/php-7.4.33
php生成目录:/usr/local/php
# 安装基础依赖包
apt -y install build-essential autoconf bison re2c pkg-config
apt -y install libgmp-dev libxml2-dev libsqlite3-dev libcurl4-openssl-dev libonig-dev libxslt1-dev libssl-dev libbz2-dev libreadline-dev libpng-dev libjpeg-dev libwebp-dev
1
2
2
# 下载php7.4.33安装包
wget https://www.php.net/distributions/php-7.4.33.tar.gz
tar -xvf php-7.4.33.tar.gz
cd php-7.4.33
1
2
3
2
3
Ubuntu 22.04 编译安装 PHP 7.4.33 报错:make: *** [Makefile:749: ext/openssl/openssl.lo] Error 1...
从 OpenSSL 1.1.0 开始,一些旧的 API 和宏定义被标记为弃用,并在后续版本中被移除。RSA_SSLV23_PADDING 常量在 OpenSSL 3.0 中被移除,因此如果你正在使用 OpenSSL 3.0 或更新版本,就会出现这个错误。
- 修改源码配置
cp -a $(pwd)/ext/openssl/openssl.c{,.bak}
sed -i 's#RSA_SSLV23_PADDING#RSA_PKCS1_PADDING#g' $(pwd)/ext/openssl/openssl.c
1
2
2
# 开始编译
Dir=/usr/local
./configure --prefix=${Dir}/php/ --with-config-file-path=${Dir}/php/etc --with-config-file-scan-dir=${Dir}/php/etc/conf.d \
--enable-fpm --with-fpm-user=www --with-fpm-group=www --enable-soap --with-openssl --with-openssl-dir --with-pcre-regex --with-zlib --with-iconv \
--with-bz2 --enable-calendar --with-curl --with-cdb --enable-dom --enable-exif --with-pcre-dir --enable-ftp --enable-bcmath --with-gd --with-jpeg-dir \
--with-png-dir --with-freetype-dir --with-gettext --enable-ctype --with-gmp --with-mhash --enable-mbstring --with-libmbfl --with-onig --enable-pdo \
--with-pdo-mysql --with-zlib-dir --with-readline --enable-session --enable-shmop --enable-simplexml --enable-sockets --enable-sysvmsg --enable-sysvsem \
--enable-sysvshm --enable-mbregex --enable-inline-optimization --enable-wddx --with-libxml-dir --with-xsl --enable-libxml --enable-xml --enable-zip \
--enable-mysqlnd --enable-pcntl --with-mysqli --with-xmlrpc --without-pear --enable-opcache
make -j $(nproc)
make install
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
# 生成配置文件
Dir=/usr/local
Path=/opt/php-7.4.33
cp ${Path}/php.ini-production ${Dir}/php/etc/php.ini
#删除系统自带配置文件
rm -rf /etc/php.ini
#添加软链接到 /etc目录
ln -s ${Dir}/php/etc/php.ini /etc/php.ini
#拷贝模板文件为php-fpm配置文件
cp ${Dir}/php/etc/php-fpm.conf.default ${Dir}/php/etc/php-fpm.conf
#添加软连接到 /etc目录
ln -s ${Dir}/php/etc/php-fpm.conf /etc/php-fpm.conf
cat >/etc/php-fpm.conf<<OPO
[global]
pid = ${Dir}/php/var/run/php-fpm.pid
error_log = /opt/logs/php-fpm.log
log_level = error
emergency_restart_threshold = 60
emergency_restart_interval = 60s
process_control_timeout = 5s
daemonize = yes
[www]
listen = 127.0.0.1:9000
listen.backlog = 8192
listen.owner = www
listen.group = www
listen.mode = 0666
user = www
group = www
pm = static
pm.max_children = 400
pm.max_requests = 10240
pm.status_path = /_php_fpm_status_
request_terminate_timeout = 30s
request_slowlog_timeout = 3s
slowlog = /opt/logs/php-fpm.log.slow
rlimit_files = 65535
rlimit_core = 65535
catch_workers_output = yes
env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp
OPO
[ -d /opt/logs ] || mkdir -p /opt/logs
ulimit -SHn 65536
#永久生效
grep 6553 /etc/security/limits.conf
if [ $? -ne 0 ];then
cat >>/etc/security/limits.conf<<OPPO
* soft nofile 65536
* hard nofile 65536
* soft nproc 65536
* hard nproc 65536
OPPO
ulimit -a
else
echo '已经修改文件描叙符'
fi
#创建运行用户
id www
if [ $? -ne 0 ];then
groupadd www
useradd -s /sbin/nologin -g www -M www
fi
cp ${Path}/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
test -f ${Dir}/php/bin/php-fpm || cp ${Path}/sapi/fpm/init.d.php-fpm ${Dir}/php/bin/php-fpm
chmod +x /etc/init.d/php-fpm ${Dir}/php/bin/php-fpm
#sed -i 's#disable_functions =#disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd, posix_getegid,posix_geteuid,posix_getgid, posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid, posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit, posix_getsid,posix_getuid,posix_isatty, posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid, posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname#g' ${Dir}/php/etc/php.ini
sed -i 's#;date.timezone =#date.timezone = PRC#g' ${Dir}/php/etc/php.ini
sed -i 's#expose_php = On#expose_php = Off#g' ${Dir}/php/etc/php.ini
sed -i 's#;opcache.enable=1#opcache.enable=1#g' ${Dir}/php/etc/php.ini
sed -i 's#;opcache.enable_cli=0#opcache.enable_cli=0#g' ${Dir}/php/etc/php.ini
echo 'zend_extension=opcache.so'>>${Dir}/php/etc/php.ini
echo "export PATH=${Dir}/php/bin:\$PATH" >> /etc/profile
echo "export PATH=${Dir}/php/sbin:\$PATH" >> /etc/profile
ln -s ${Dir}/php/sbin/* ${Dir}/sbin/
ln -s ${Dir}/php/bin/* ${Dir}/bin/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# 启动php-fpm服务
/etc/init.d/php-fpm start
/etc/init.d/php-fpm reload
1
2
3
2
3
# 查看有哪些模块
php -m
# 添加redis模块
test -d /opt/soft || mkdir /opt/soft && cd /opt/soft
wget https://pecl.php.net/get/redis-6.0.2.tgz
tar xf redis-6.0.2.tgz
cd redis-6.0.2
PHP_dir=/usr/local/php/bin
${PHP_dir}/phpize
./configure --with-php-config=${PHP_dir}/php-config
make -j $nproc
make install
echo $?
cat >>/etc/php.ini<<OPO
extension=redis.so
OPO
/usr/local/php/bin/php-fpm reload
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 测试
- 配置nginx
cat >/etc/nginx/sites-enabled/404.conf<<'EOF'
server {
listen 80;
server_name _;
root html;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000; # PHP-FPM 监听地址
fastcgi_index index.php;
}
}
EOF
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
- 配置连接redis库,get数据
cat >/etc/nginx/html/index.php<<'EOF'
<?php
// 连接到 Redis 服务器
$redis = new Redis();
$redis->connect('192.168.0.126', 6379);
$redis->auth('GhRJhuI11111EJCcar2er');
$redis->select(6); // 选择数据库 0
// 检查连接是否成功
if (!$redis->isConnected()) {
die("Redis connection failed.");
}
// 指定你想要获取的键
$key = 'test001';
// 获取键的值
$value = $redis->get($key);
// 检查键是否存在
if ($value === false) {
echo "Key '{$key}' not found.";
} else {
// 返回键的值给前端
echo json_encode(['key' => $key, 'value' => $value]);
}
// 关闭连接
$redis->close();
?>
EOF
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//
如果此文章对您有帮助,点击 -->> 请博主喝咖啡 (opens new window)
上次更新: 2025/06/30, 17:43:00