您现在的位置是: 首页> 学无止境> Linux> Linux

linux下安装php

张伟江2019-01-15 15:27Linux3255人已围观

简介PHP即“超文本预处理器”,是一种通用开源脚本语言。PHP是在服务器端执行的脚本语言,与C语言类似,是常用的网站编程语言。

1、创建www用户组和www用户

# 判断用户或用户组是否存在,不存在则创建
user=www
group=www
#create group if not exists
egrep "^$group" /etc/group >& /dev/null
if [ $? -ne 0 ]
then
    groupadd $group
fi

#create user if not exists
egrep "^$user" /etc/passwd >& /dev/null
if [ $? -ne 0 ]
then
    useradd -g $group -s /sbin/nolgin $user
fi

2、安装需要依赖的工具包

yum -y install wget vim pcre pcre-devel openssl openssl-devel libicu-devel gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses ncurses-devel curl curl-devel krb5-devel libidn libidn-devel openldap openldap-devel nss_ldap jemalloc-devel cmake boost-devel bison automake libevent libevent-devel gd gd-devel libtool* libmcrypt libmcrypt-devel mcrypt mhash libxslt libxslt-devel readline readline-devel gmp gmp-devel libcurl libcurl-devel openjpeg-devel

3、下载并解压安装包

rm -rf php-7.2.2
cp -frp /usr/lib64/libldap* /usr/lib/
if [ ! -f php-7.2.2.tar.gz ];then
  #wget https://cn2.php.net/distributions/php-7.2.2.tar.gz
  wget https://f.9635.com.cn/linux/php-7.2.2.tar.gz
fi
tar zxvf php-7.2.2.tar.gz

3、编译和安装

cd php-7.2.2
./configure --prefix=/alidata/server/php \
--with-config-file-path=/alidata/server/php/etc \
--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--enable-mysqlnd-compression-support \
--with-iconv-dir \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir \
--enable-xml \
--disable-rpath \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--enable-mbregex \
--enable-mbstring \
--enable-intl \
--with-mcrypt \
--with-libmbfl \
--enable-ftp \
--with-gd \
--enable-gd-jis-conv \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--with-gettext \
--disable-fileinfo \
--enable-opcache \
--with-pear \
--enable-maintainer-zts \
--with-ldap=shared \
--without-gdbm \


CPU_NUM=$(cat /proc/cpuinfo | grep processor | wc -l)
if [ $CPU_NUM -gt 1 ];then
    make ZEND_EXTRA_LIBS='-liconv' -j$CPU_NUM
else
    make ZEND_EXTRA_LIBS='-liconv'
fi
make install

4、设置日志文件和php配置文件所在目录

cd ..
cp ./php-7.2.2/php.ini-development /alidata/server/php/etc/php.ini
cp ./php-7.2.2/php-fpm-72 /etc/init.d/php-fpm-72
chmod a+x /etc/init.d/php-fpm-72
sed -i '$d'  /alidata/server/php/etc/php.ini
cp /alidata/server/php/etc/php-fpm.conf.default /alidata/server/php/etc/php-fpm.conf
cp /alidata/server/php/etc/php-fpm.d/www.conf.default /alidata/server/php/etc/php-fpm.d/www.conf

5、设置开机自启动

cat > /usr/lib/systemd/system/php-fpm.service<<"EOF"
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target

[Service]
Type=simple
PIDFile=/alidata/server/php/var/run/php-fpm.pid
ExecStart=/alidata/server/php/sbin/php-fpm --nodaemonize --fpm-config /alidata/server/php/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID

[Install]
WantedBy=multi-user.target
EOF
systemctl enable php-fpm.service
systemctl start php-fpm.service

完整脚本如下,复制以下脚本并给于可执行权限,执行脚本

#!/bin/bash
# lnmp之php-7.2.2的安装
# author ctocode-zwj <982215226@qq.com>

# 判断用户或用户组是否存在,不存在则创建
user=www
group=www
#create group if not exists
egrep "^$group" /etc/group >& /dev/null
if [ $? -ne 0 ]
then
    groupadd $group
fi

#create user if not exists
egrep "^$user" /etc/passwd >& /dev/null
if [ $? -ne 0 ]
then
    useradd -g $group -s /sbin/nolgin $user
fi

yum -y install wget vim pcre pcre-devel openssl openssl-devel libicu-devel gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses ncurses-devel curl curl-devel krb5-devel libidn libidn-devel openldap openldap-devel nss_ldap jemalloc-devel cmake boost-devel bison automake libevent libevent-devel gd gd-devel libtool* libmcrypt libmcrypt-devel mcrypt mhash libxslt libxslt-devel readline readline-devel gmp gmp-devel libcurl libcurl-devel openjpeg-devel

rm -rf php-7.2.2
cp -frp /usr/lib64/libldap* /usr/lib/
if [ ! -f php-7.2.2.tar.gz ];then
  #wget https://cn2.php.net/distributions/php-7.2.2.tar.gz
  wget https://f.9635.com.cn/linux/php-7.2.2.tar.gz
fi
tar zxvf php-7.2.2.tar.gz
cd php-7.2.2
./configure --prefix=/alidata/server/php \
--with-config-file-path=/alidata/server/php/etc \
--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--enable-mysqlnd-compression-support \
--with-iconv-dir \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir \
--enable-xml \
--disable-rpath \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--enable-mbregex \
--enable-mbstring \
--enable-intl \
--with-mcrypt \
--with-libmbfl \
--enable-ftp \
--with-gd \
--enable-gd-jis-conv \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--with-gettext \
--disable-fileinfo \
--enable-opcache \
--with-pear \
--enable-maintainer-zts \
--with-ldap=shared \
--without-gdbm \


CPU_NUM=$(cat /proc/cpuinfo | grep processor | wc -l)
if [ $CPU_NUM -gt 1 ];then
    make ZEND_EXTRA_LIBS='-liconv' -j$CPU_NUM
else
    make ZEND_EXTRA_LIBS='-liconv'
fi
make install
cd ..
cp ./php-7.2.2/php.ini-development /alidata/server/php/etc/php.ini
cp ./php-7.2.2/php-fpm-72 /etc/init.d/php-fpm-72
chmod a+x /etc/init.d/php-fpm-72
sed -i '$d'  /alidata/server/php/etc/php.ini
cp /alidata/server/php/etc/php-fpm.conf.default /alidata/server/php/etc/php-fpm.conf
cp /alidata/server/php/etc/php-fpm.d/www.conf.default /alidata/server/php/etc/php-fpm.d/www.conf

    cat > /usr/lib/systemd/system/php-fpm.service<<"EOF"
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target

[Service]
Type=simple
PIDFile=/alidata/server/php/var/run/php-fpm.pid
ExecStart=/alidata/server/php/sbin/php-fpm --nodaemonize --fpm-config /alidata/server/php/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID

[Install]
WantedBy=multi-user.target
EOF
systemctl enable php-fpm.service
systemctl start php-fpm.service
sleep 5

github示例:https://github.com/zhangweijiang/linux/blob/master/shell/lnmp_php-7.2.2.sh

- END -


点赞(0) 打赏

上一篇:Linux下安装nginx

下一篇:Linux下安装mysql

文章评论 共有 0 条评论

暂无评论

站点信息

  • 建站时间:2018年10月24日
  • 网站程序:fastadmin
  • 文章统计301篇文章
  • 标签管理标签云
  • 统计数据百度统计
  • 微信号:zwj982215226

打赏本站

  • 如果你觉得本站很棒,可以通过扫码支付打赏哦!
  • 微信扫码:你说多少就多少~
  • 支付宝扫码:你说多少就多少~

微信小程序

微信扫一扫体验

立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部