linux+php安装部署

安装编译库

yum install gcc gcc-c++ openssl-devel zlib-devel libxml2-devel libjpeg-turbo-devel libiconv-devel freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel mhash mhash-devel mcrypt mcrypt-devel libmcrypt-devel sqlite-devel oniguruma-devel –y

安装php和mysql关联,不然php无法连接mysql

yum install php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc

环境配置修改

编辑文件vi /etc/ld.so.conf
vi /etc/ld.so.conf

添加以下几行信息: 
/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64
保存退出...

使配置生效: 
ldconfig -v

安装libiconv库

创建libiconv文件夹并进入:
mkdir /usr/local/libiconv
cd /usr/local/libiconv

下载并解压libiconv安装包:
wget https://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.15.tar.gz
tar -zxvf libiconv-1.15.tar.gz

进入安装文件目录:
cd libiconv-1.15

编译安装内容到指定文件夹:
./configure --prefix=/usr/local/libiconv

安装
make && make install

安装cmake库

创建libiconv文件夹并进入:
mkdir /usr/local/cmake
cd /usr/local/cmake

下载并解压libiconv安装包:
wget  https://github.com/Kitware/CMake/releases/download/v3.16.0/cmake-3.16.0.tar.gz
tar -zxvf cmake-3.16.0.tar.gz

进入安装文件目录:
cd cmake-3.16.0

编译安装:
sudo ./bootstrap

安装
sudo make
sudo make install

测试版本:
cmake --version
出现以下内容表示安装成功.....
cmake version 3.16.0
CMake suite maintained and supported by Kitware (kitware.com/cmake).

安装libzip库

创建libiconv文件夹并进入:
mkdir /usr/local/libzip
cd /usr/local/libzip

下载并解压libiconv安装包:
wget https://libzip.org/download/libzip-1.5.0.tar.gz
tar -zxvf libzip-1.5.0.tar.gz

进入安装文件目录:
cd libzip-1.5.0

创建并进入文件夹:
mkdir build && cd build

编译安装:
cmake ..
make && make install

安装php流程

创建php安装目录并进入:
mkdir /usr/local/php
cd /usr/local/php

下载并解压php:
wget https://www.php.net/distributions/php-7.4.19.tar.gz
tar -zxvf php-7.4.19.tar.gz

进入安装文件目录:
cd php-7.4.19
 
执行编译:
./configure --prefix=/usr/local/php --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-iconv-dir=/usr/local/libiconv --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --enable-short-tags --enable-zend-multibyte --enable-static --with-xsl --with-fpm-user=nginx --with-fpm-group=nginx --enable-ftp --disable-fileinfo
 
安装:
make && make install

相关配置

将源码中的php.ini-development复制到PHP的目录下,并改名为PHP.ini
cp php.ini-production /usr/local/php/lib/php.ini
 
复制一份php-fpm配置文件,命名为php-fpm.conf(/usr/local/php/etc路径下)
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
 
启动
/usr/local/php/sbin/php-fpm
 
如果遇到以下错误:
解决办法:
cd /usr/local/php/etc/php-fpm.d/
cp www.conf.default www.conf
 
验证配置是否正常:
/usr/local/php/sbin/php-fpm –t
 
再次启动:
/usr/local/php/sbin/php-fpm
 
如果遇到以下错误:
解决办法:
创建一个nginx的用户
useradd nginx
 
重置密码:
password nginx
 
启动:
/usr/local/php/sbin/php-fpm
 
显示进程
ps -aux|grep php-fpm
上传文件大小设置
编辑/usr/local/php/lib中的php.ini文件
vi /usr/local/php/lib/php.ini
修改以下三项内容:
max_execution_time = 0
upload_max_filesize = 1024M
post_max_size = 1024M

添加服务到开机启动

添加文件/etc/init.d/php-fpm
vim /etc/init.d/php-fpm

添加以下内容:
#!/bin/sh  
# chkconfig:   2345 15 95
 
# description:  PHP-FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation \
  
# with some additional features useful for sites of any size, especially busier sites.
# DateTime: 2016-09-20
 
# Source function library.  
. /etc/rc.d/init.d/functions  
 
# Source networking configuration.  
. /etc/sysconfig/network  
 
# Check that networking is up.  
[ "$NETWORKING" = "no" ] && exit 0  
 
phpfpm="/usr/local/php/sbin/php-fpm"  
prog=$(basename ${phpfpm})  
 
lockfile=/var/lock/subsys/phpfpm
 
start() {  
    [ -x ${phpfpm} ] || exit 5  
    echo -n $"Starting $prog: "  
    daemon ${phpfpm}
    retval=$?  
    echo  
    [ $retval -eq 0 ] && touch $lockfile  
    return $retval  
}  
 
stop() {  
    echo -n $"Stopping $prog: "  
    killproc $prog -QUIT  
    retval=$?  
    echo  
    [ $retval -eq 0 ] && rm -f $lockfile  
    return $retval  
}  
 
restart() {  
    configtest || return $?  
    stop  
    start  
}  
 
reload() {  
    configtest || return $?  
    echo -n $"Reloading $prog: "  
    killproc ${phpfpm} -HUP  
    RETVAL=$?  
    echo  
}  
 
force_reload() {  
    restart  
}  
 
configtest() {  
  ${phpfpm} -t
}  
 
rh_status() {  
    status $prog  
}  
 
rh_status_q() {  
    rh_status >/dev/null 2>&1  
}  
 
case "$1" in  
    start)  
        rh_status_q && exit 0  
        $1  
        ;;  
    stop)  
        rh_status_q || exit 0  
        $1  
        ;;  
    restart|configtest)  
        $1  
        ;;  
    reload)  
        rh_status_q || exit 7  
        $1  
        ;;  
    status)  
        rh_status  
        ;;  
    *)  
        echo $"Usage: $0 {start|stop|status|restart|reload|configtest}"  
        exit 2  
esac 

保存退出...

给文件授权:
chmod 755 /etc/init.d/php-fpm

指令测试:
service php-fpm start    // 启动
service php-fpm stop   // 停止

添加到开机启动项:
chkconfig --add /etc/init.d/php-fpm

设置开机启动:
chkconfig php-fpm on

搞定,可以重启服务器看看是否成功...

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注