如何在Linux下安装php

本文为系列文章,该系列主要包含如何一步步在Linux上搭建项目。主要分为如何在

在Linux下安装php、

Linux下安装nginx、

Linux下安装MySQL、

Linux下如何配置nginx等。

一、下载解压

php官网下载需要的版本(tar.gz版本),并上传到 usr/local 目录下

解压上一步下载的文件,并进入文件下

tar -zxvf php-7.3.5.tar.gz
cd php-7.3.5

二、编译安装

1.更新依赖包并安装依赖包

yum -y update
yum -y install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses curl gdbm-devel db4-devel libXpm-devel libX11-devel gd-devel gmp-devel expat-devel xmlrpc-c xmlrpc-c-devel libicu-devel libmcrypt-devel libmemcached-devel libzip gcc-c++

2.添加用户和组

groupadd www
useradd -g www www

3.开始编译

./configure \
 --prefix=/usr/local/php\
 --enable-fpm\
 --with-fpm-user=www\
 --with-fpm-group=www\
 --with-config-file-path=/usr/local/php/conf\
 --disable-rpath\
 --enable-soap\
 --with-libxml-dir\
 --with-xmlrpc\
 --with-openssl\
 --with-mhash\
 --with-pcre-regex\
 --with-zlib\
 --enable-bcmath\
 --with-bz2\
 --enable-calendar\
 --with-curl\
 --enable-exif\
 --with-pcre-dir\
 --enable-ftp\
 --with-gd\
 --with-openssl-dir\
 --with-jpeg-dir\
 --with-png-dir\
 --with-zlib-dir\
 --with-freetype-dir\
 --enable-gd-jis-conv\
 --with-gettext\
 --with-gmp\
 --with-mhash\
 --enable-mbstring\
 --with-onig\
 --with-mysqli=mysqlnd\
 --with-pdo-mysql=mysqlnd\
 --with-zlib-dir\
 --with-readline\
 --enable-shmop\
 --enable-sockets\
 --enable-sysvmsg\
 --enable-sysvsem \
 --enable-sysvshm \
 --enable-wddx\
 --with-libxml-dir\
 --with-xsl\
 --enable-zip\
 --with-pear

这里会提示 configure: error: Please reinstall the libzip distribution,我们需要溢出libzip,手动安装最新版本

先编译安装最新版cmake

扫描二维码关注公众号,回复: 13607047 查看本文章
cd /usr/local/src
wget https://github.com/Kitware/CMake/releases/download/v3.14.3/cmake-3.14.3.tar.gz
tar -zxvf cmake-3.14.3.tar.gz
cd cmake-3.14.3
./bootstrap
make && make install

如果下载的慢,可以去官网下载自己需要的版本( Unix/Linux Source (has \n line feeds) ),然后上传到 usr/local 下,再执行解压编译安装操作;

再编译安装libzip

yum remove libzip -y
cd /usr/local/src
wget  https://libzip.org/download/libzip-1.5.2.tar.gz
tar -zxvf libzip-1.5.2.tar.gz
cd libzip-1.5.2
mkdir build
cd build
cmake ..
make && make install

如果下载的慢,可以去官网下载自己需要的版本( libzip-1.7.3.tar.gz ),然后上传到 usr/local 下,再执行解压编译安装等系列操作;

再次执行第3步开始的编译操作,继续报错 error: off_t undefined; check your library configuration,执行下面的命令

vi /etc/ld.so.conf 
#添加如下几行
/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64 
#保存退出
:wq
ldconfig -v # 使之生效

注:如果不会使用Linux编辑操作,可以找到 服务器根目录 / etc / ld.so.conf ,用xftp打开编辑并保存。然后再执行生效命令。

然后再次执行第3步开始的编译操作,完成会有 Thank you for uesing PHP!提示,没有问题再执行

make && make install

4.编译完成后,添加环境变量

vi /etc/profile
#添加以下内容到最后
PATH=$PATH:/usr/local/php/bin
export PATH
#保存退出
:wq
#刷新环境变量
source /etc/profile

注:如果不会使用Linux编辑操作,可以找到 服务器根目录 / etc / profile ,用xftp打开编辑并保存。然后再执行刷新环境变量操作。

5.编辑配置文件

cp php.ini-production /usr/local/php/conf/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

如果报 conf 文件夹没有创建,则手动创建一个

6.把systemctl文件加入开机启动文件

cp sapi/fpm/php-fpm.service /usr/lib/systemd/system/php-fpm.service
systemctl start php-fpm.service
systemctl enable php-fpm.service

至此就安装完成了,按照步骤来是没有问题。

小贴士,如何重启 php-fpm:

停止命令

 pkill php-fpm

启动

/usr/local/php/sbin/php-fpm -R  # 如果报错显示不能用root用户启动,则可以考虑使用 -R命令

猜你喜欢

转载自blog.csdn.net/CharmHeart/article/details/112507220