CentOS7.X install php-7.x.x

My personal website

Install php

  1. Installation preparation

    yum install \
    vim \
    gcc \
    gcc-c++ \
    wget \
    make \
    re2c \
    libtool \
    automake \
    autoconf \
    curl-devel \
    libpng-devel \
    libxml2-devel \
    libxslt-devel \
    openssl-devel \
    freetype-devel \
    bzip2-devel \
    libicu-devel \
    libuuid-devel \
    libmcrypt-devel \
    postgresql-devel \
    -y
  2. Install php

    cd /root
    wget http://cn2.php.net/distributions/php-7.2.6.tar.gz
    tar -zxvf php-7.2.6.tar.gz
    cd php-7.2.6
    ./configure \
    --prefix=/usr/local/php \
    --enable-mysqlnd \
    --with-openssl \
    --enable-fpm
    
    # If you have installed apache under the path of / usr/local/apache / and want php to run under apache, you need to add:
    # --with-apxs2=/usr/local/apache/bin/apxs
    # Or -- with-apxs2=/usr/local/apache/bin/apxs2
    # Apxs has been renamed apxs2 in some apache distributions
    
    make
    make install
    
    # If apache is installed in / usr/local/apache / path and you want php to run in apache, apache does not need to be recompiled
    # At this time, there is an additional libphp7.so file under / usr/local/apache/modules /
    # Edit / etc/httpd/httpd.conf to add the following line:
    
    LoadModule php7_module modules/libphp7.so
    DocumentRoot "/www"
    <FilesMatch \.php$>
        SetHandler application/x-httpd-php
    </FilesMatch>
    
    # Edit / www/index.php as follows:
    
    <?php
    phpinfo();
    
    # Restart apache
    # Visit http://xxx.xxx.xxx.xxx/index.php
  3. Generate php.ini, php-fpm.conf, www.conf

    # Check if php.ini is placed correctly (only if the first line is not none)
    /usr/local/php/bin/php --ini
    
    //Deployment environment execution:
    cp ./php.ini-production /usr/local/php/lib/php.ini
    
    //Development environment execution:
    cp ./php.ini-development /usr/local/php/lib/php.ini
    
    # Copy php-fpm.conf
    cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
    
    # PHP7 is executed (in PHP5, the configuration item of www.conf is PHP FPM. CONF)
    cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
  4. php.ini general configuration

    # Download cacert.pem
    cd /usr/local/php/lib
    wget https://curl.haxx.se/ca/cacert.pem
    
    vim /usr/local/php/lib/php.ini
    
    ;php Version information hiding
    expose_php=Off
    
    ;Prevent display php Error output,Off: Do not output but log
    display_errors=Off
    
    ;Prevent users from masquerading executable files as static files(Such as pictures and documents)After uploading, access WEB Page to execute the file
    cgi.fix_pathinfo=0
    
    ;Allow single file upload up to 20 M
    upload_max_filesize=20M
    
    ;session.name If you develop your own program, you can change it,But if you are deploying an existing project,Modification may result in session Abnormal related functions
    session.name=self_key
    
    ;10 per request session Of key,Check 1 times key Need to expire deletion
    session.gc_probability=1
    session.gc_divisor=1000
    
    ;Set up session Default 5 minutes(300 second)Be overdue
    session.gc_maxlifetime=1440
    
    ;Time zone Shanghai, China
    date.timezone=Asia/Shanghai
    
    ;curl,openssl To configure cacert.pem
    curl.cainfo=/usr/local/php/lib/cacert.pem
    openssl.cafile=/usr/local/php/lib/cacert.pem
    
    ESC
    :wq
  5. Configure php-fpm.conf

    vim /usr/local/php/etc/php-fpm.conf
    
    pid=run/php-fpm.pid
    error_log=log/php-fpm.log
    # If the configuration is enabled ↓, the next step cannot be skipped
    rlimit_files=51200
    
    ESC
    :wq
  6. Adjust the maximum number of open files (the value is for reference only, rlimit_files is not configured in the previous step, this step can be skipped)

    # Add at the end of the file
    vim /etc/security/limits.conf
    
    * soft nproc 65535
    * hard nproc 65535
    * soft nofile 65535
    * hard nofile 65535
    
    ESC
    :wq
  7. Configure www.conf (two schemes with large memory and small memory)

    vim /usr/local/php/etc/php-fpm.d/www.conf
    
    user=www
    group=www
    
    # Static allocation subprocess (1G memory, 640M memory planned for php)
    pm=static
    pm.max_children=20
    pm.start_servers=15
    pm.min_spare_servers=10
    pm.max_spare_servers=20
    pm.process_idle_timeout=10s
    pm.max_requests=500
    slowlog=log/$pool.log.slow
    php_admin_value[memory_limit]=32M
    
    # Dynamic allocation of subprocesses (1G memory, 640M memory planned for php)
    pm=dynamic
    pm.max_children=20
    pm.start_servers=15
    pm.min_spare_servers=10
    pm.max_spare_servers=20
    pm.process_idle_timeout=10s
    pm.max_requests=500
    slowlog=log/$pool.log.slow
    php_admin_value[memory_limit]=32M
    
    ESC
    :wq
    
    # The following configurations are for information only and are not recommended
    listen=127.0.0.1:9000 If changed to listen=/usr/local/php/var/run/php-fpm.sock
    //Then nginx configures fastcgi_pass 127.0.0.1:9000; to change to fastcgi_pass UNIX: / usr / local / PHP / var / run / PHP fpm.sock;
  8. Add php to environment variables

    vim /etc/profile
    
    export PATH=$PATH:/usr/local/php/bin
    
    ESC
    :wq
    
    source /etc/profile
  9. Install composer

    # Download (zlib extension needs to be installed first)
    cd /usr/local/php/bin
    curl -sS https://getcomposer.org/installer | /usr/local/php/bin/php
    mv ./composer.phar ./composer
    composer -V
  10. Start php and set the startup

    # Add www user
    useradd www
    mkdir /www
    chown -R www:www /www
    chown -R www:www /usr/local/php
    
    # Enter the unit file directory
    cd /etc/systemd/system
    vim php7.service
    
    [Unit]
    Description=Start php7 on boot.
    After=network.target
    
    [Service]
    User=root
    Group=root
    Type=forking
    ExecStart=/usr/local/php/sbin/php-fpm
    ExecReload=/bin/kill -USR2 `cat /usr/local/php/var/run/php-fpm.pid`
    ExecStop=/bin/kill -INT `cat /usr/local/php/var/run/php-fpm.pid`
    PrivateTmp=true
    
    [Install]
    WantedBy=multi-user.target
    
    ESC
    :wq
    
    # Modify the file permission so that only root can edit the file
    chown -R root:root /etc/systemd/system/php7.service
    chmod -R 644 /etc/systemd/system/php7.service
    
    # Update systemd
    systemctl daemon-reload
    systemctl enable php7
    systemctl start php7
  11. View operation

    # View main process and sub process
    ps aux | grep php-fpm
    
    # View pid file (success if it exists)
    ll /usr/local/php/var/run/
  12. php process operations

    # Smooth closing
    kill -INT `cat /usr/local/php/var/run/php-fpm.pid`
    # graceful restart
    kill -USR2 `cat /usr/local/php/var/run/php-fpm.pid`
  13. Install php extension

    cd /root/php-7.2.6/ext/xxxx
    /usr/local/php/bin/phpize
    
    -----------------------------------------------------------
    | phpize Pay attention to the following:
    | If you don't find it here config.m4
    | cp ./config0.m4 ./config.m4
    -----------------------------------------------------------
    
    ./configure --with-php-config=/usr/local/php/bin/php-config
    
    -----------------------------------------------------------
    | install GD library configure Pay attention to the following:
    | It's added here for typesetting'|',Hold down Alt Key selection....
    | yum install \
    | libXpm-devel \
    | libpng-devel \
    | libjpeg-devel \
    | libwebp-devel \
    | -y \
    |
    | ./configure \
    | --with-xpm-dir \
    | --with-png-dir \
    | --with-jpeg-dir \
    | --with-webp-dir \
    | --with-zlib-dir \
    | --with-freetype-dir \
    -----------------------------------------------------------
    
    make
    
    -----------------------------------------------------------
    | make Notice the following:
    | Repeat installation PHP Precompiled extensions,Report wrong
    | Installing shared extensions:
    | /usr/local/php/lib/php/extensions/no-debug-non-zts-20151012/
    | cp: cannot stat 'modules/*': No such file or directory
    | make: *** [install-modules] Error 1
    | So do not re install,adopt php -m View installed extensions.
    -----------------------------------------------------------
    
    -----------------------------------------------------------
    | Notice here,install mcrypt Install first. libmcrypt(Some versions Linux system)
    | cd /usr/local/src
    | wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz
    | cd libmcrypt-2.5.7
    | ./configure
    | make
    | make install
    -----------------------------------------------------------
    
    make install
    
    vim /usr/local/php/lib/php.ini
    
    extension=xxxx.so
    
    ESC
    :wq
    
    Zend extend:
    -----------------------------------------------------------
    | Set up opcache.max_accelerated_files Time
    | Execute the following command to get php Number of files
    | find . -type f -print | grep php | wc -l
    | Then, in the following prime number set, find a value that is exactly larger than the value
    | 223, 463, 983, 1979, 3907, 7963, 16229, 32531, 65407, 130987
    | opcache install,To configure php.ini:
    |
    | zend_extension=opcache.so
    | opcache.enable_cli=1
    | opcache.memory_consumption=256
    | opcache.interned_strings_buffer=16
    | opcache.max_accelerated_files=32531
    | opcache.validate_timestamps=1
    | opcache.revalidate_freq=60
    | opcache.fast_shutdown=1
    -----------------------------------------------------------
  14. The best setting of ZendOpcache Reference link
  15. Common extension ('-' indicates the extension that may have been installed. Check the installed extension before installation to prevent repeated installation)

    bcmath
    - ctype
    curl
    - date
    - fileinfo
    gd
    - hash
    - iconv
    intl
    - json
    mbstring
    mcrypt
    - mysqlnd
    - openssl
    - pcre
    - PDO
    pdo_mysql
    pdo_pgsql
    sockets
    zip
    zlib
    
    mongo (wget http://pecl.php.net/get/mongo-1.6.14.tgz [php7.x.x no longer needed])
    mongodb (wget http://pecl.php.net/get/mongodb-1.2.9.tgz)
    redis (wget http://pecl.php.net/get/redis-3.1.2.tgz)
    uuid (wget http://pecl.php.net/get/uuid-1.0.4.tgz)
    fastcommon (see FastDFS install)
    fastdfs_client (see FastDFS install)
    
    Zend:
        opcache (Document address: http://php.net/manual/zh/opcache.installation.php)
  16. php recompile

    cd /root/php-7.2.6
    
    make distclean
    
    ./configure \
    --prefix=/usr/local/php \
    --enable-mysqlnd \
    --with-openssl \
    --enable-fpm \
    
    make
    make install
  17. Alipay red envelopes support authors

Keywords: Linux PHP Apache vim Session

Added by Nick Zaccardi on Tue, 17 Mar 2020 16:04:49 +0200