搭建lnmp环境编译安装PHP和常见报错的解决方法

php官网:https://www.php.net
进入官网后点击downloads选择需要下载的版本即可

本文以php 7.3.10版本为例
安装包存放路径 /usr/local/src/

下载:

[root@linux src]# wget https://www.php.net/distributions/php-7.3.10.tar.bz2

解压:

[root@linux src]# tar -jxvf php-7.3.10.tar.bz2

编译安装:
进入目录 cd php-7.3.10.tar.bz2

配置编译参数:
./configure --prefix=/usr/local/php-fpm --with-config-file-path=/usr/local/php-fpm/etc --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-pdo-mysql=/usr/local/mysql --with-mysql-sock=/tmp/mysql.sock --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --with-pear --with-curl --with-openssl

编译: make

安装:make install

拷贝配置文件php.ini-development到php程序安装目录:

[root@linux php-7.3.10]# cp php.ini-development /usr/local/php-fpm/etc/php.ini

拷贝启动脚本到/etc/init.d/目录:

[root@linux php-7.3.10]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

进入php安装目录下的/etc目录重命名配置文件:

[root@linux php-7.3.10]# cd /usr/local/php-fpm/etc/
[root@linux etc]# cp php-fpm.conf.default php-fpm.conf
[root@linux etc]# cd php-fpm.d/
[root@linux php-fpm.d]# cp www.conf.default www.conf

添加php启动脚本到系统服务:

[root@linux php-fpm.d]# chkconfig --add php-fpm
[root@linux php-fpm.d]# chkconfig php-fpm on
[root@linux php-fpm.d]# chmod 755 /etc/init.d/php-fpm

创建php用户:

[root@linux php-fpm.d]# useradd php-fpm

启动php:

[root@linux php-fpm.d]# service php-fpm start

编译安装php报错解决方法:

报错1:checking for gcc… no
解决:yum -y install gcc

报错2:error: libxml2 not found
解决:yum install -y libxml2-devel

报错3:error: Cannot find OpenSSL’s
解决:yum install -y openssl-devel

报错4:error: cURL version 7.15.5 or later is required
解决:yum install -y libcurl-devel

报错5:configure: error: jpeglib.h not found
解决:yum install -y libjpeg-turbo-devel

报错6:configure: error: png.h not found
解决:yum install -y libpng-devel

报错7:configure: error: freetype-config not found
解决:yum install -y freetype-devel

报错8:configure: error: wrong mysql library version or lib not found

该错误表示当前安装的MySQL/MariaDB版本过高,下载个低版本的MySQL包将编译参数含有MySQL/MariaDB的路径改为低版本MySQL程序目录即可,无需安装低版本MySQL

解决:
1.下载MySQL5.6二进制包:

[root@linux ~]# cd /usr/local/src/
[root@linux src]# wget http://mirrors.163.com/mysql/Downloads/MySQL-5.6/mysql-5.6.43-linux-glibc2.12-x86_64.tar.gz

2.解压:

[root@linux src]# tar -zxvf mysql-5.6.43-linux-glibc2.12-x86_64.tar.gz 

3.移动到/usr/local/目录下重命名为mysql5.6:

[root@linux src]# mv mysql-5.6.43-linux-glibc2.12-x86_64.tar.gz /usr/local/mysql5.6

4.更改编译参数中 - -with-mysql,- -with-mysqli,- -with-pdo-mysql指向的路径为MySQL5.6目录:
./configure --prefix=/usr/local/php-fpm --with-config-file-path=/usr/local/php-fpm/etc --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm –with-mysql=/usr/local/mysql5.6 --with-mysqli=/usr/local/mysql5.6/bin/mysql_config --with-pdo-mysql=/usr/local/mysql5.6 --with-mysql-sock=/tmp/mysql.sock --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --with-pear --with-curl --with-openssl

报错9:ERROR: [pool www] cannot get uid for user ‘php-fpm’
创建编译参数中指定的php用户即可
解决:useradd php-fpm

你可能感兴趣的:(Linux运维)