感谢公司给我压力,给我 php从入门到放弃的机会
环境搭建
php8.0+Linux+Apache+mysql
php8.0搭建
- 下载php的包到linux环境中
wget https://www.php.net/distributions/php-8.1.7.tar.gz
- 解压压缩包
tar -xvf php-8.1.7.tar.gz
- 执行配置命令
./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
- 执行命令后我遇到的报错
-
configure编译提示no acceptable C compiler found in $PATH,这种错误一般就是缺失gcc导致的
yum install gcc
-
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' found
运行命令
yum install dnf
dnf install libxml2-devel
-
configure: error: Package requirements (krb5-gssapi krb5) were not met
解决办法
yum -y install krb5-devel
-
No package 'openssl' found
解决办法
yum install openssl openssl-devel
-
No package 'sqlite3' found
configure: error: Package requirements (sqlite3 >= 3.7.7) were not met:
No package 'sqlite3' found
解决办法
yum install sqlite-devel
-
checking for BZip2 in default path... not found
解决办法
yum install bzip2 bzip2-devel
-
configure: error: Package requirements (libcurl >= 7.29.0) were not met:
checking for libcurl >= 7.29.0... no
configure: error: Package requirements (libcurl >= 7.29.0) were not met:
No package 'libcurl' found
解决办法
yum install libcurl-devel
-
configure: error: Package requirements (libpng) were not met:
configure: error: Package requirements (libpng) were not met:
No package 'libpng' found
Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.
解决办法
yum install libpng-devel
9.configure: error: Package requirements (libjpeg) were not met:
configure: error: Package requirements (libjpeg) were not met:
No package 'libjpeg' found
解决办法
yum install -y libjpeg-devel
-
configure: error: Package requirements (freetype2) were not met:
configure: error: Package requirements (freetype2) were not met:
No package 'freetype2' found
解决办法
yum -y install freetype freetype-devel
-
configure: error: Package requirements (icu-uc >= 50.1 icu-io icu-i18n) were not met:
checking for icu-uc >= 50.1 icu-io icu-i18n... no
configure: error: Package requirements (icu-uc >= 50.1 icu-io icu-i18n) were not met:
No package 'icu-uc' found
No package 'icu-io' found
No package 'icu-i18n' found
解决办法
yum install libicu-devel
12.configure: error: in `/opt/php/php-8.1.7':
checking for g++... no
checking for c++... no
checking for gpp... no
checking for aCC... no
checking for CC... no
checking for cxx... no
checking for cc++... no
checking for cl.exe... no
checking for FCC... no
checking for KCC... no
checking for RCC... no
checking for xlC_r... no
checking for xlC... no
checking for clang++... no
checking whether the compiler supports GNU C++... no
checking whether g++ accepts -g... no
checking for g++ option to enable C++11 features... none needed
checking how to run the C++ preprocessor... /lib/cpp
configure: error: in `/opt/php/php-8.1.7':
configure: error: C++ preprocessor "/lib/cpp" fails sanity check
See `config.log' for more details
解决办法
yum install gcc-c++
- configure: error: Package requirements (oniguruma) were not met:
configure: error: Package requirements (oniguruma) were not met:
No package 'oniguruma' found
解决办法
wget https://github.com/kkos/oniguruma/archive/v6.9.4.tar.gz -O oniguruma-6.9.4.tar.gz
tar -zxf oniguruma-6.9.4.tar.gz
cd cd oniguruma-6.9.4
./autogen.sh && ./configure --prefix=/usr
// 如果报错则执行 ./autogen.sh: line 6: autoreconf: command not found
dnf install autoconf automake libtool
make
sudo make install
14 configure: error: Package requirements (libzip >= 0.11 libzip != 1.3.1 libzip != 1.7.0) were not met:
checking for libzip >= 0.11 libzip != 1.3.1 libzip != 1.7.0... no
configure: error: Package requirements (libzip >= 0.11 libzip != 1.3.1 libzip != 1.7.0) were not met:
Requested 'libzip >= 0.11' but version of libzip is 0.10.1
解决办法
https://blog.csdn.net/ljh101/article/details/108531725
- 编译和安装
make
make install
- 查看php安装的情况
切换到configure指定的安装路径的bin目录,执行版本查看:
/usr/local/install/php8/bin/php --version
- 管理各种配置文件
1、生成php.ini配置文件(在php源码压缩包目录下):
cp php.ini-production /usr/local/install/php8/etc/php.ini
2、生成www配置文件:
cd /usr/local/install/php8/etc/php-fpm.d/
cp www.conf.default www.conf
3、生成php-fpm配置文件:
cd /usr/local/install/php8/etc/
cp php-fpm.conf.default php-fpm.conf
4、生成php-fpm可执行文件:
-- 创建存放配置文件的目录
mkdir /usr/local/install/php8/fpm
-- 从源码中复制一份fpm可执行脚本
cp /opt/php/php-8.0.0/sapi/fpm/init.d.php-fpm /usr/local/install/php8/fpm/php-fpm
-- 将php-fpm修改为可执行文件
chmod 740 /usr/local/install/php8/fpm/php-fpm
- 管理php
说明:本文推荐使用php-fpm进行管理php程序,php-fpm(FastCGI Process Manager:FastCGI进程管理器)是一个PHPFastCGI管理器,旨在将FastCGI进程管理整合进PHP包中(来源:百度百科)。
优点:相对Spawn-FCGI,php-fpm在CPU和内存方面的控制都更胜一筹,而且前者很容易崩溃,必须用crontab进行监控,而php-fpm则没有这种烦恼。
1、启动php-fpm:
/usr/local/install/php8/fpm/php-fpm start
2、查看php-fpm进程是否启动成功
ps aux | grep php | grep -v grep
3、查看pfp-fpm占用的端口
ss -lntp | grep php
4、执行php --version出现php command not found异常,解决步骤
// 1、修改配置文件
vim /etc/profile
//2、添加php环境变量(即configure脚本时指定的安装路径下的bin目录)
PATH=$PATH:/usr/local/install/php8/bin
export PATH
// 刷新配置文件
source /etc/profile
5、大功告成