首页后端开发PHP如何从零搭建php环境呢?

如何从零搭建php环境呢?

时间2024-03-23 10:36:03发布访客分类PHP浏览889
导读:这篇文章主要给大家介绍“如何从零搭建php环境呢?”的相关知识,下文通过实际案例向大家展示操作过程,内容简单清晰,易于学习,有这方面学习需要的朋友可以参考,希望这篇“如何从零搭建php环境呢?”文章能对大家有所帮助。 推荐:...
这篇文章主要给大家介绍“如何从零搭建php环境呢?”的相关知识,下文通过实际案例向大家展示操作过程,内容简单清晰,易于学习,有这方面学习需要的朋友可以参考,希望这篇“如何从零搭建php环境呢?”文章能对大家有所帮助。

推荐:《PHP8教程》

从零搭建php环境-php8

一、下载

1、https://www.php.net/distributions/php-8.0.0.tar.gz下载到本地,文件传输上传到 /usr/local/src/
2、wget -P /usr/local/src/ https://www.php.net/distributions/php-8.0.0.tar.gz

二、解压、编译、安装
1、解压缩

>
     cd /usr/local/src/
>
     tar xzf php-8.0.0.tar.gz
>
     cd php-8.0.0

2、配置编译参数,参考https://www.php.net/manual/zh/configure.about.php选择自己需要的选项

./configure --prefix=/usr/local/php8 --with-config-file-path=/usr/local/php8/etc --with-fpm-user=www --with-fpm-group=www --with-curl --with-openssl --with-mysqli --with-pdo-mysql --with-iconv --with-mhash --with-zlib  --enable-mbstring  --enable-gd   --enable-gd-jis-conv --enable-sockets --enable-fpm --enable- --enable-xml  --enable-pdo  --enable-cli --enable-pcntl --enable-soap --enable-opcache --enable-fileinfo --disable-rpath --enable-mysqlnd --with-zip --enable-simplexml --with-libxml --with-sqlite3 --with-pdo-sqlite --enable-phar --enable-tokenizer --enable-cgi

问题1:

configure: error: Package requirements (libxml-2.0 >
    = 2.9.0) were not met:

Package 'libxml-2.0', required by 'virtual:world', not found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively, you may set the environment variables LIBXML_CFLAGS
and LIBXML_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.

问题1解决:

>
     yum install libxml2-devel

问题2:

configure: error: Package requirements (sqlite3 >
     3.7.4) were not met:

问题2解决:

>
     yum install sqlite-devel

问题3:

configure: error: Package requirements (libcurl >
    = 7.29.0) were not met:

问题3解决:

>
     yum install libcurl-devel

问题4:

configure: error: Package requirements (libpng) were not met:

问题4解决:

>
     yum install libpng libpng-devel

问题5:

configure: error: Package requirements (oniguruma) were not met:

问题5解决:

>
     cd /usr/local/src/
>
     wget http://ftp.altlinux.org/pub/distributions/ALTLinux/Sisyphus/x86_64/RPMS.classic/liboniguruma5-6.9.6-alt1.x86_64.rpm -O liboniguruma5-6.9.6-alt1.x86_64.rpm
>
     rpm -ivh liboniguruma5-6.9.6-alt1.x86_64.rpm
>
     wget http://ftp.altlinux.org/pub/distributions/ALTLinux/Sisyphus/x86_64/RPMS.classic/liboniguruma-devel-6.9.6-alt1.x86_64.rpm -O liboniguruma-devel-6.9.6-alt1.x86_64.rpm 
>
     rpm liboniguruma-devel-6.9.6-alt1.x86_64.rpmcli

问题6:

configure: error: Package requirements (libzip >
    = 0.11 libzip != 1.3.1 libzip != 1.7.0) were not met:

问题6解决:

>
     yum install libzip libzip-devel

配置编译参数成功

+--------------------------------------------------------------------+
| License:                                                           |
| This software is subject to the PHP License, available in this     |
| distribution in the file LICENSE. By continuing this installation  |
| process, you are bound by the terms of this license agreement.     |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point.                            |
+--------------------------------------------------------------------+

Thank you for using PHP.

3、编译源码

>
     make -j2 # 这里是依赖系统cpu核心数进行编译,对性能有一定提升,通常利用核心数不要超过一半,

4、安装

make install

安装成功

[root@54skyer php-8.0.0]# make install
Installing shared extensions:     /usr/local/php8/lib/php/extensions/no-debug-non-zts-20200930/
Installing PHP CLI binary:        /usr/local/php8/bin/
Installing PHP CLI man page:      /usr/local/php8/php/man/man1/
Installing PHP FPM binary:        /usr/local/php8/sbin/
Installing PHP FPM defconfig:     /usr/local/php8/etc/
Installing PHP FPM man page:      /usr/local/php8/php/man/man8/
Installing PHP FPM status page:   /usr/local/php8/php/php/fpm/
Installing phpdbg binary:         /usr/local/php8/bin/
Installing phpdbg man page:       /usr/local/php8/php/man/man1/
Installing PHP CGI binary:        /usr/local/php8/bin/
Installing PHP CGI man page:      /usr/local/php8/php/man/man1/
Installing build environment:     /usr/local/php8/lib/php/build/
Installing header files:          /usr/local/php8/include/php/
Installing helper programs:       /usr/local/php8/bin/
  program: phpize
  program: php-config
Installing man pages:             /usr/local/php8/php/man/man1/
  page: phpize.1
  page: php-config.1
/usr/local/src/php-8.0.0/build/shtool install -c ext/phar/phar.phar /usr/local/php8/bin/phar.phar
ln -s -f phar.phar /usr/local/php8/bin/phar
Installing PDO headers:           /usr/local/php8/include/php/ext/pdo/

5、添加环境变量

>
     vim /etc/profile # 在文件末尾加入
# PATH=$PATH:/usr/local/php8/bin/
# export PATH
# :wq 保存并退出
>
     source /etc/profile # 立刻生效配置
>
     php -v # 获得如下信息

php -v
PHP 8.0.0 (cli) (built: Dec 15 2020 02:46:59) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.0-dev, Copyright (c) Zend Technologies

6、获取默认配置

// 复制php.ini到编译配置参数指定的目录。php.ini在解压的源码目录里
>
     cp /usr/local/src/php-8.0.0/php.ini-production /usr/local/php8/etc/php.ini
// 复制一份php-fpm的配置模版文件到同级目录 方便备份和修改
>
     cp /usr/local/php8/etc/php-fpm.conf.default /usr/local/php8/etc/php-fpm.conf
// 复制一份php-fpm的扩展配置模板文件到同级目录 方便备份和修改
>
     cp /usr/local/php8/etc/php-fpm.d/www.conf.default /usr/local/php8/etc/php-fpm.d/www.conf
// 复制开启自起脚本到系统启动自动加载脚本目录。fpm/init.d.php-fpm在解压的源码目录里
>
     cp /usr/local/src/php-8.0.0/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

7、开机自启动
设置命令可被执行

>
     chmod +x /etc/init.d/php-fpm # 添加可执行权限

检验自启动脚本

>
     service php-fpm start # 检验服务启动
>
     service php-fpm stop # 检验服务关闭
// 均正常提示
>
     chkconfig php-fpm on # 设置开机自动执行php-fpm开机自启动脚本
>
     reboot # 重启,ssh重连
# 重启后
[root@54skyer ~]# netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      1097/nginx: master  
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1061/sshd           
tcp        0      0 0.0.0.0:16379           0.0.0.0:*               LISTEN      1090/redis-server 0 
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      1083/php-fpm: maste

7、额外说明
关于配置文件的一些说明 参考:https://www.cnblogs.com/xiaozong/p/5724984.html
php-fpm.conf是PHP-FPM特有的配置文件
php.ini是所有php模式中必须的配置文件
两者的区别是,php-fpm.conf是PHP-FPM进程管理器的配置文件,php.ini是PHP解析器的配置文件

有的PHP版本的配置文件路径中还有/fpm.d/www.conf配置文件

这是php-fpm.conf配置的文件的扩展文件,可以打开php-fpm.conf文件查看

; include=fpm.d/*.conf

我们可以使用php-fpm.conf配置慢日志

我们是可以开启慢日志功能的。

slowlog = /usr/local/var/log/php-fpm.log.slow
request_slowlog_timeout = 5s


以上就是关于“如何从零搭建php环境呢?”的介绍了,感谢各位的阅读,希望文本对大家有所帮助。如果想要了解更多知识,欢迎关注网络,小编每天都会为大家更新不同的知识。

声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!

php

若转载请注明出处: 如何从零搭建php环境呢?
本文地址: https://pptw.com/jishu/651283.html
新php8的特性,JIT对php应用性能有什么影响? pandas读取excel文件的方法是什么,如何实现?

游客 回复需填写必要信息