当前位置: 首页 > 工具软件 > Deepin Clone > 使用案例 >

deepin 编译安装 php7.4

楚钊
2023-12-01

deepin 编译安装 php7.4


扩展的安装

  • 基础的扩展包
    sudo apt-get install -y gcc autoconf automake libtool cmake m4 bison re2c
    
  • 依赖的扩展包
    sudo apt-get -y install libwebp-dev libjpeg-dev libxpm-dev libzip-dev libxslt1-dev libmcrypt-dev libsqlite3-dev libcurl4-openssl-dev libssl-dev
    
  • Oniguruma 扩展
    • Oniguruma是一个新式灵活的正则表达式库,mbstring的正则表达式处理功能对它有依赖性。
    • 编译安装
      	$ git clone https://github.com/kkos/oniguruma.git
      	$ cd oniguruma/
      	# 生成 configure
      	$ ./autogen.sh
      	# 检测
      	$ ./configure  --prefix=/usr/local
      	# 编译及安装
      	$ make && make install
      	```
      
  • Sodium 扩展
    • Sodium 是一个先进而且易用的加密库,主要用于加密、解密、签名和生成密码哈希等,可用于替代 mcrypt 扩展。
    • 编译安装
      $ wget https://download.libsodium.org/libsodium/releases/libsodium-1.0.18-stable.tar.gz
      $ tar -xf libsodium-1.0.18-stable.tar.gz 
      $ cd libsodium-stable/
      $ ./configure  --prefix=/usr/local
      $ make && make install
      

PHP7 的安装

  • Step 1:(目录
    $ mkdir -p /opt/php/7.4.27
    # 设置当前用户的权限
    $ sudo chown -R [用户名]:[用户组]  /opt/php/7.4.27
    
  • Step 2:(./configure
    $ ./configure --prefix=/opt/php/7.4.27 \
          --with-openssl \
          --with-curl \
          --enable-opcache \
          --enable-fpm \
          --enable-mbstring \
          --enable-sockets \
          --enable-ftp \
          --enable-phpdbg \
          --enable-debug \
          --enable-shmop \
          --enable-intl \
          --enable-pcntl \
          --enable-bcmath \
          --enable-sigchild \
          --enable-sysvmsg \
          --enable-sysvsem \
          --enable-sysvshm \
          --enable-inline-optimization \
          --enable-calendar \
          --disable-short-tags \
          --without-pear \
          --with-mhash \
          --with-zlib \
          --with-bz2 \
          --enable-xml \
          --enable-soap \
          --with-xmlrpc \
          --with-xsl \
          --with-pcre-jit \
          --with-zip \
          --with-ffi \
          --with-sodium \
          --enable-gd \
          --with-webp \
          --with-jpeg \
          --with-xpm \
          --with-freetype \
          --enable-exif \
          --with-gettext \
          --enable-mysqlnd \
          --with-mysqli \
          --with-pdo-mysql \
          --with-pdo-sqlite \
          --enable-zts
    ......
    Generating files
    configure: patching main/php_config.h.in
    configure: creating ./config.status
    creating main/internal_functions.c
    creating main/internal_functions_cli.c
    config.status: creating main/build-defs.h
    config.status: creating scripts/phpize
    config.status: creating scripts/man1/phpize.1
    config.status: creating scripts/php-config
    config.status: creating scripts/man1/php-config.1
    config.status: creating sapi/cli/php.1
    config.status: creating sapi/fpm/php-fpm.conf
    config.status: creating sapi/fpm/www.conf
    config.status: creating sapi/fpm/init.d.php-fpm
    config.status: creating sapi/fpm/php-fpm.service
    config.status: creating sapi/fpm/php-fpm.8
    config.status: creating sapi/fpm/status.html
    config.status: creating sapi/phpdbg/phpdbg.1
    config.status: creating sapi/cgi/php-cgi.1
    config.status: creating ext/phar/phar.1
    config.status: creating ext/phar/phar.phar.1
    config.status: creating main/php_config.h
    config.status: main/php_config.h is unchanged
    config.status: executing default commands
    
  • Step 3:(编译及安装)
    # 如果没有设置安装目录的权限,需要加 sudo
    $ make -j8 && make install
    

PHP 的配置

  • 设置配置文件
    php-7.4.27$ cp php.ini-development /opt/php/7.4.27/etc/php.ini
    php-7.4.27$ cd /opt/php/7.4.27/etc
    etc$ cp php-fpm.conf.default  php-fpm.conf
    etc$ cp php-fpm.d/www.conf.default   php-fpm.d/www.conf
    
  • 创建 www 用户
    sudo groupadd www
    sudo useradd -s /sbin/nologin -g www www
    
  • 配置 php-fpm.conf
    $ vim /opt/php/7.4.27/etc/php-fpm.conf
    # 修改以下内容
    pid = /run/php-fpm.pid
    error_log = /var/log/php-fpm.log
    
  • 配置 www.conf
    $ vim /opt/php/7.4.27/etc/php-fpm.d/www.conf
    # 修改以下内容
    user = www
    group = www
    listen = 127.0.0.1:9000
    
  • 软连接的设置
    # 不设置,则在执行 php 命令时会出错
    ln -s /opt/php/7.4.27/etc/php.ini   /opt/php/7.4.27/lib/php.ini
    sudo ln -s /opt/php/7.4.27/bin/php   /usr/local/bin/php
    sudo ln -s /opt/php/7.4.27/bin/phpize   /usr/local/bin/phpize
    sudo ln -s /opt/php/7.4.27/bin/php-config  /usr/local/bin/php-config            
    
  • 检测配置是否成功
    $ cd /opt/php/7.4.27/sbin/
    $ ./php-fpm -t
    ....../php/7.4.27/etc/php-fpm.conf test is successful
    

Systemd 服务配置

  • 新建 php-fpm 服务
    $ sudo vim /usr/lib/systemd/system/php-fpm.service
    
    # 加入以下内容
    [Unit]
    Description=service The PHP-FPM HTTP Server
    After=syslog.target network.target
    
    [Service]
    Type=forking
    Restart=always
    User=root
    ExecStart=/opt/php/7.4.27/sbin/php-fpm -c /opt/php/7.4.27/etc/php.ini -y /opt/php/7.4.27/etc/php-fpm.conf
    ExecStop=kill -SIGQUIT `cat /run/php-fpm.pid`
    ExecReload=kill -SIGUSR2 `cat /run/php-fpm.pid`
    
    [Install]
    WantedBy=multi-user.target
    
  • 设置服务
    # php-fpm 软连接
    sudo ln -s /usr/lib/systemd/system/php-fpm.service  /etc/systemd/system/
    # 设置服务自启开机
    sudo systemctl enable php-fpm.service
    # 启动
    sudo systemctl start php-fpm.service
    
  • 查看 php-fpm 服务启动状态
    sudo systemctl status php-fpm.service
    
 类似资料: