系统版本信息
代码语言:javascript复制cat /etc/kylin-release
nkvers
cat /proc/version
安装PHP
安装PHP依赖环境
yum -y install libtool sqlite-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel readline readline-devel libxslt libxslt-devel
yum install openldap openldap-devel -y
拷贝和链接所需必要文件
代码语言:javascript复制cp -frp /usr/lib64/libldap* /usr/lib/
ln -s /usr/lib64/liblber.so /usr/lib/liblber.so
安装 oniguruma-6.9.4
代码语言:javascript复制wget https://github.com/kkos/oniguruma/archive/v6.9.4.tar.gz -O oniguruma-6.9.4.tar.gz
tar -xvf oniguruma-6.9.4.tar.gz
cd oniguruma-6.9.4/
./autogen.sh && ./configure --prefix=/usr --libdir=/lib64
make && make install
安装 libmcrypt
代码语言:javascript复制wget https://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
tar xf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure --prefix=/usr/local/libmcrypt
make && make install
编译安装PHP
下载php-7.4.30源文件
代码语言:javascript复制cd /opt
wget --timeout=7200 https://www.php.net/distributions/php-7.4.30.tar.gz
tar -xvf php-7.4.30.tar.gz
cd php-7.4.30
PHP编译配置项
代码语言:javascript复制./configure --prefix=/usr/local/php
--with-config-file-path=/usr/local/php/etc
--enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx
--enable-inline-optimization --disable-debug --disable-rpath
--enable-shared --enable-soap --with-xmlrpc
--with-openssl --with-mhash --with-sqlite3
--with-zlib --enable-bcmath --with-iconv --with-bz2
--enable-calendar --with-curl --with-cdb --enable-dom
--enable-exif --enable-fileinfo --enable-filter
--enable-ftp --with-openssl-dir --with-zlib-dir
--enable-gd-jis-conv --with-gettext --with-gmp --with-mhash
--enable-json --enable-mbstring --enable-mbregex
--enable-pdo --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd
--with-zlib-dir --with-pdo-sqlite --with-readline --enable-session
--enable-shmop --enable-simplexml --enable-sockets --enable-sysvmsg
--enable-sysvsem --enable-sysvshm --with-xsl --with-ldap
--enable-mysqlnd-compression-support --with-pear
--enable-opcache --disable-fileinfo
编译安装
代码语言:javascript复制make -j 3
make install
PHP环境变量
代码语言:javascript复制echo "export PATH=$PATH:/usr/local/php/bin" >> /etc/profile
source /etc/profile
拷贝PHP配置文件
代码语言:javascript复制cp /opt/php-7.4.30/php.ini-production /usr/local/php/etc/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
ln -s /usr/local/php/etc/ /etc/php
修改 /usr/local/php/etc/php-fpm.conf 运行用户和组改为nginx
代码语言:javascript复制chown nginx.nginx /usr/local/php/etc/php-fpm.conf
chown -R nginx.nginx /etc/php
查看PHP 安装模块
启动php-fpm
代码语言:javascript复制/usr/local/php/sbin/php-fpm
重启php-fpm
代码语言:javascript复制kill -USR2 303081
终止php-fpm
代码语言:javascript复制kill -INT 303081
Nginx 配置
vim /usr/local/nginx/conf/nginx.conf
代码语言:javascript复制worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ .php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}
检查配置
代码语言:javascript复制nginx -t
启动nginx
代码语言:javascript复制systemctl start nginx
测试
代码语言:javascript复制cat > /usr/local/nginx/html/index.php <<eof
<?php
phpinfo();
?>
eof
浏览器访问测试
代码语言:javascript复制http://127.0.0.1/index.php
测试PHP连接MySQL
php 脚本
vim /usr/local/nginx/html/mysql.php
代码语言:javascript复制<?php
//创建连接
$servername = "127.0.0.1"; //域名
$username = "root "; //用户名
$passwd = "password"; //密码
//检测连接
$conn = mysqli_connect($servername,$username,$passwd);
if(!$conn){
die("connection failed:" . mysqli_connect_errno());
}else{
echo "数据库连接成功!!!";
mysqli_close($conn); //关闭连接
}
浏览器访问测试
代码语言:javascript复制http://127.0.0.1/mysql.php
编译PHP 7.4出现ldap错误
PHP 编译安装运行"make",提示如下错误
代码语言:javascript复制/usr/bin/ld: ext/ldap/.libs/ldap.o: undefined reference to symbol 'ber_memfree'
//usr/lib64/liblber-2.4.so.2: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make: *** [Makefile:278: sapi/cli/php] Error 1
创建链接修复问题
代码语言:javascript复制ln -s /usr/lib64/liblber.so /usr/lib/liblber.so