怎样在Linux下安装独立PHP环境

By admin, 10 六月, 2020

此方法允许同时安装多个PHP版本。

PHP-8.1.13

安装:

 

$ sudo apt install autoconf build-essential curl libtool   libssl-dev libcurl4-openssl-dev libxml2-dev libreadline-dev libzip-dev openssl   pkg-config zlib1g-dev libsqlite3-dev libonig-dev libpng-dev libfreetype6-dev freetype2-demos libjpeg-dev

$ ./configure --prefix=/var/www/php-8.1.13     --enable-mysqlnd     --with-pdo-mysql     --with-pdo-mysql=mysqlnd    --enable-bcmath     --enable-fpm     --with-fpm-user=www-data     --with-fpm-group=www-data     --enable-mbstring     --enable-phpdbg     --enable-shmop     --enable-sockets     --enable-sysvmsg     --enable-sysvsem     --enable-sysvshm     --with-zip   --with-zlib     --with-curl     --with-pear     --with-openssl     --enable-pcntl     --with-readline --enable-gd --enable-calendar --with-freetype --with-jpeg --with-mysqli

$ make

$ make test

$ make install

安装libcurl:

如果上面的libcurl4-openssl-dev和libssl-dev冲突装不上,需要手动到下面地址从源码安装libcurl: https://curl.se/download.html

./configure --with-openssl && make && make test

make install

配置php.ini

$ cp php.ini-production /var/www/php-8.1.13/lib/php.ini

change follow line in php.ini:

pdo_mysql.default_socket=/var/run/mysqld/mysqld.sock

zend_extension=opcache.so

opcache.enable=1

memory_limit=2G

配置www.conf

$ cd /var/www/php-8.1.13/etc;
$ cp php-fpm.conf.default php-fpm.conf
$ cp php-fpm.d/www.conf.default php-fpm.d/www.conf

$ vi php-fpm.d/www.conf

listen = 127.0.0.1:9002

pm.max_children = 20

pm.max_requests = 500

request_terminate_timeout = 3600

$ sudo /var/www/php-8.1.13/sbin/php-fpm

配置nginx:

    

        location ~ \.php[?]* {

                fastcgi_split_path_info ^(.+\.php)(/.+)$;

                fastcgi_pass 127.0.0.1:9002;

                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

                fastcgi_index index.php;

                include fastcgi_params;

                fastcgi_read_timeout 3600;

        }

$ sudo service nginx restart

PHP-7.4.6

安装:

 

$ sudo apt install autoconf build-essential curl libtool   libssl-dev libcurl4-openssl-dev libxml2-dev libreadline-dev libzip-dev openssl   pkg-config zlib1g-dev libsqlite3-dev libonig-dev libpng-dev libfreetype6-dev freetype2-demos libjpeg-dev

$ ./configure --prefix=/var/www/php-7.4.6     --enable-mysqlnd     --with-pdo-mysql     --with-pdo-mysql=mysqlnd    --enable-bcmath     --enable-fpm     --with-fpm-user=www-data     --with-fpm-group=www-data     --enable-mbstring     --enable-phpdbg     --enable-shmop     --enable-sockets     --enable-sysvmsg     --enable-sysvsem     --enable-sysvshm     --with-zip   --with-zlib     --with-curl     --with-pear     --with-openssl     --enable-pcntl     --with-readline --enable-gd --enable-calendar --with-freetype --with-jpeg --with-mysqli

$ make

$ make install

配置php.ini: 

$ cp php.ini-production /var/www/php-7.4.6/lib/php.ini

change follow line in php.ini:

pdo_mysql.default_socket=/var/run/mysqld/mysqld.sock

zend_extension=opcache.so

配置php-fpm: 

$ cd /var/www/php-7.4.6/etc;
$ cp php-fpm.conf.default php-fpm.conf
$ cp php-fpm.d/www.conf.default php-fpm.d/www.conf

change port from 9000 to 9001 in php-fpm.d/www.conf if you are running more than one php-fpm.

$ sudo /var/www/php-7.4.6/sbin/php-fpm

配置nginx:

    

    location ~ ^/test/drupal9/.*\.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass 127.0.0.1:9001;
    }
 

参考:

https://www.php.net/manual/en/install.unix.debian.php#122244

标签

评论

Restricted HTML

  • 允许的HTML标签:<a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id> <img src>
  • 自动断行和分段。
  • 网页和电子邮件地址自动转换为链接。
验证码
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.
1 + 2 =
计算出这道简单的算术题并键入答案。例如、1+3,就输入 4。