网站首页linux

编译安装PHP8.1及yaf,swoole,redis等扩展

发布时间:2016-05-10 22:04:37编辑:slayer.hover阅读(11662)

           

    基于阿里云vps, 安装php8.1.4到/www/server/php/81目录下。

    编译安装openResty (可选)

    #yum -y install pcre-devel openssl openssl-devel
    #wget https://openresty.org/download/openresty-1.13.6.2.tar.gz 
    #tar -zxvf openresty-1.13.6.2.tar.gz
    #cd openresty-1.13.6.2
    #./configure --prefix=/opt/openresty --with-luajit
    #make && make install


    一、下载编译安装php8.1:

    1.添加www用户组
        groupadd www
    2.添加www用户
        useradd -g www www    
    3.预先安装所有可能会用到的包.
        yum -y install pcre pcre-devel gcc gcc-c++ openssl openssl-devel libicu-devel 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    
        
    在./configure时可能会出现的报错,如:configure: error: Cannot find ldap libraries in /usr/lib 
    解决方法执行拷贝文件:
    #cp -frp /usr/lib64/libldap* /usr/lib/    
        
    4.下载php8.1源码,编译&&安装
    a>#wget https://www.php.net/distributions/php-8.1.4.tar.gz
    b>#tar -zxvf php-8.1.4.tar.gz
    c>#cd php-8.1.4
    d>#./configure --prefix=/www/server/php/81 \
    --with-config-file-path=/www/server/php/81/etc \
    --with-curl \
    --with-freetype \
    --enable-gd \
    --with-jpeg  \
    --with-gettext \
    --with-kerberos \
    --with-libdir=lib64 \
    --with-libxml \
    --with-mysqli \
    --with-openssl \
    --with-pdo-mysql \
    --with-pdo-sqlite \
    --with-pear \
    --enable-sockets \
    --with-mhash \
    --with-ldap-sasl \
    --with-xsl \
    --with-zlib \
    --with-zip \
    --with-bz2 \
    --with-iconv  \
    --enable-fpm \
    --enable-pdo \
    --enable-bcmath \
    --enable-mbregex \
    --enable-mbstring \
    --enable-opcache \
    --enable-pcntl \
    --enable-shmop \
    --enable-soap \
    --enable-sockets \
    --enable-sysvsem \
    --enable-xml \
    --enable-sysvsem \
    --enable-cli \
    --enable-opcache \
    --enable-intl \
    --enable-calendar \
    --enable-static \
    --enable-mysqlnd

    其它的未找到库文件之类的报错,按错误提示挨个安装:(如果有的话)

    yum install -y libxslt libxslt-devel libxml2 libxml2-devel pcre-devel bzip2 bzip2-devel


    若有报错error: Package requirements (sqlite3 > 3.7.4) were not met

    No package 'sqlite3' found

    解决:

    yum install libsqlite3x-devel -y


    若有报错error: Package requirements (oniguruma) were not met

    No package 'oniguruma' found

    解决:

    yum install oniguruma-devel -y


    最终不在报错,则继续编译安装:(8核CPU可使用-j8, 编译速度更快)

    e>#make -j8

    超长时间的等待.......

    f>#make install

    完工, 拷贝配置文件:

      #cp ./php.ini-production /www/server/php/81/etc/php.ini

      #cp /www/server/php/81/etc/php-fpm.conf.default    /www/server/php/81/etc/php-fpm.conf

      #cp /www/server/php/81/etc/php-fpm.d/www.conf.default    /www/server/php/81/etc/php-fpm.d/www.conf

    至此,php8.1.4已经成功安装到/www/server/php/81目录下。


    二、配置php8.1的php-fpm:
    1. 修改php-fpm/www.conf文件中的下列几行

    user = www
    group = www
    
    listen = /tmp/php-cgi-81.sock
    
    listen.owner = www
    listen.group = www

    2. 配置自启动的php-fpm服务

    a>复制php8源文件夹中的init.d.php-fpm到/etc/init.d/目录:
    #cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm-81
    
    编辑php-fpm-81文件, 并对照更新下面几行,主要是php-fpm的运行文件、配置文件、pid的路径要一一对应。
    #vim /etc/init.d/php-fpm-81
    
    prefix=/www/server/php/81
    exec_prefix=${prefix}
    
    php_fpm_BIN=${exec_prefix}/sbin/php-fpm
    php_fpm_CONF=${prefix}/etc/php-fpm.conf
    php_fpm_PID=${prefix}/var/run/php-fpm.pid
    b>#chmod a+x /etc/init.d/php-fpm-81
    c>启动php-fpm-81
    #/etc/init.d/php-fpm-81 start


    三、配置更新nginx,使用php-fpm-81解析php文件。

    a>#vim /usr/local/nginx/conf/nginx.conf

    修改此段,fastcgi_pass unit:/tmp/php81-cgi.sock;  使php8解析器工作:


            location ~ [^/]\.php(/|$)
            {
                try_files $uri =404;
                fastcgi_pass  unix:/tmp/php-cgi-81.sock;
                fastcgi_index index.php;
                include fastcgi.conf;
            }


    b>重新启动nginx


    四、安装redis

    a>安装redis服务器

    #yum install redis

    b>安装redis的php扩展

    #wget -c http://pecl.php.net/get/redis-5.3.7.tgz 
    #tar zxvf redis-5.3.7.tgz
    #cd redis-5.3.7.tgz
    #/www/server/php/81/bin/phpize
    #./configure --with-php-config=/www/server/php/81/bin/php-config
    #make
    #make install

    此编译过程中,出了点意外,报个library.lo不是合法的libtool库文件什么什么的, 

    网上找了一圈,解决方法是清除之前编译的可执行文件及配置文件, 重新编译:

    #make clean
    #make && make install

    在php.ini中添加redis.so

    #vim /www/server/php/81/etc/php.ini
    extension=redis.so



    五、安装PHP的yaf扩展

    a>下载

    #wget http://pecl.php.net/get/yaf-3.3.4.tgz

    b>解压、编译、安装,步骤同上面的redis扩展

    #tar -zxvf yaf-3.3.4.tgz
    #cd yaf-3.3.4.tgz
    #/www/server/php/81/bin/phpize
    #./configure --with-php-config=/www/server/php/81/bin/php-config
    #make && make install

    在php.ini中添加yaf.so

    #vim /www/server/php/81/etc/php.ini
    extension=yaf.so



    六、安装PHP的swoole扩展

    a>下载

    #git clone https://gitee.com/swoole/swoole.git

    b>解压、编译、安装,步骤同上:

    #cd swoole
    #/www/server/php/81/bin/phpize
    #./configure --with-php-config=/www/server/php/81/bin/php-config
    #make && make install

    在php.ini中添加swoole.so

    #vim /www/server/php/81/etc/php.ini
    extension=swoole.so



    七、安装mysql数据库(MariaDB)

    使用阿里云的10.4版本,更新mariaDB yum源,直接在shell下执行

    cat <<EOF > /etc/yum.repos.d/mariadb.repo
    [mariadb]
    name = MariaDB
    baseurl = http://mirrors.aliyun.com/mariadb/yum/10.4/centos7-amd64/
    gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
    enabled=1
    gpgcheck=1
    EOF


    a>#yum install mariadb-server mariadb #安装MariaDB
    
    b>#systemctl start mariadb  #启动MariaDB
    
    c>#systemctl stop mariadb  #停止MariaDB
    
    d>#systemctl restart mariadb  #重启MariaDB
    
    e>#systemctl enable mariadb  #设置开机启动


    MariaDB修改root密码和以往的方式不太一样, 使用下面的命令:

    MariaDB> SET PASSWORD FOR root@localhost = PASSWORD("your_password");   
    MariaDB> flush privileges;



    八、最后重启一下php-fpm-81, 启动redis server, 上面安装的就全部生效了。

    a>service php-fpm-81 restart
    b>service redis start

    完工。


评论