树莓派centos 7.x版本 编译安装 PHP7.2

下载安装包

树莓派上yum里没有的软件只能编译安装

wget http://cn2.php.net/distributions/php-7.2.0.tar.gz
tar -zxvf php-7.2.0.tar.gz
cd php-7.2.0

安装依赖包

yum install gcc gcc-c++ systemd-devel libxml2 libxml2-devel curl curl-devel bzip2 bzip2-devel libjpeg-turbo libjpeg-turbo-devel libpng libpng-devel freetype freetype-devel libicu libicu-devel openssl openssl-devel pcre pcre-devel

编译 && 安装

./configure \
--prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--with-zlib-dir \
--with-freetype-dir \
--enable-mbstring \
--with-libxml-dir=/usr \
--enable-xmlreader \
--enable-xmlwriter \
--enable-soap \
--enable-calendar \
--with-curl \
--with-zlib \
--with-gd \
--with-pdo-sqlite \
--with-pdo-mysql \
--with-mysqli \
--with-mysql-sock \
--enable-mysqlnd \
--disable-rpath \
--enable-inline-optimization \
--with-bz2 \
--with-zlib \
--enable-sockets \
--enable-sysvsem \
--enable-sysvshm \
--enable-pcntl \
--enable-mbregex \
--enable-exif \
--enable-bcmath \
--with-mhash \
--enable-zip \
--with-pcre-regex \
--with-jpeg-dir=/usr \
--with-png-dir=/usr \
--with-openssl \
--enable-ftp \
--with-kerberos \
--with-gettext \
--with-xmlrpc \
--with-xsl \
--enable-fpm \
--with-fpm-user=php-fpm \
--with-fpm-group=php-fpm \
--with-fpm-systemd \
--disable-fileinfo

编译之后开始安装

make && make install

配置PHP与Nginx

cd /usr/local/php
cp etc/php-fpm.conf.default etc/php-fpm.conf
cp etc/php-fpm.d/www.conf.default etc/php-fpm.d/www.conf

修改配置文件

vim etc/php-fpm.d/www.conf
#修改
user = nginx
group = nginx

如果报错 用户不存在:ERROR: [pool www] cannot get uid for user 'nginx'

groupadd nginx
useradd -g nginx nginx

启动php-fpm: 

#root 用户启动 参数为 -R

/usr/local/php/sbin/php-fpm

若报错 file not found 

修改nginx配置文件

fastcgi_param

location / {
    root   html;
    index  index.html index.htm index.php;
}
location ~\.php$ {
    root /home/www;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    include        fastcgi_params;
}

检测是否成功

新建index.php


加入环境变量 

# vim /etc/profile

末尾添加:
export PATH=$PATH:/usr/local/php/sbin:/usr/local/php/bin

# source /etc/profile     立即生效

新操作方式

# 启动
php-fpm -R

# 停止
pkill -f php-fpm -9

#查询进程
ps -ef | grep php-fpm

 个人不习惯用systemctl操作PHP,有需要的话请自行google

你可能感兴趣的:(环境搭建,Linux,PHP)