Home > Backend Development > PHP8 > Compilation, installation and use of PHP8.0 (detailed explanation)

Compilation, installation and use of PHP8.0 (detailed explanation)

藏色散人
Release: 2023-02-17 12:32:01
forward
8652 people have browsed it

The official version of PHP8.0 has been released for a long time. This article will introduce its installation and compare it with PHP7 using laravel. [Recommended: PHP Video Tutorial]

Installation and Configuration

The operating system used this timeUbuntu 18.04.4 LTS

Installation

1. Prepare necessary libraries

apt-get install -y autoconf libxml2-dev libsqlite3-dev \
libcurl4-openssl-dev libssl-dev libonig-dev libtidy-dev zlib1g-dev
Copy after login

2.Go to the official website to download the official version of 8.0 https://www.php.net/releases/8.0 /en.php

3. Unzip and install

tar php-8.0.0.tar.gzcd php-8.0.0
./configure --prefix=/opt/php8 --with-config-file-path=/opt/php8/etc \
--enable-fpm --enable-mysqlnd --enable-opcache --enable-pcntl \
--enable-mbstring --enable-soap --enable-zip --enable-calendar \
--enable-bcmath --enable-exif --enable-ftp --enable-intl --with-mysqli \
--with-pdo-mysql --with-openssl --with-curl --with-gd --with-gettext \
--with-mhash --with-openssl --with-mcrypt --with-tidy --enable-wddx \
--with-xmlrpc --with-zlibmakemake installcp php.ini-production /opt/php/etc/php.inicd /opt/php8/etccp php-fpm.conf.default php-fpm.confcp ./php-fpm.d/www.conf.default ./php-fpm.d/www.conf
Copy after login

4. Make a soft link

ln -s /opt/php8/bin/php /usr/bin/php8
Copy after login

5. Install composer

cd /opt/php8/bin/curl -sS https://getcomposer.org/installer | php8ln -s /opt/php8/bin/composer.phar /usr/bin/composer8
composer8 config -g repo.packagist composer https://mirrors.aliyun.com/composer/
Copy after login

6. Add a php8 .0 system service

vim /lib/systemd/system/php8.0-fpm.service
Copy after login

The content is as follows

[Unit]
Description=The PHP 8.0 FastCGI Process Manager
Documentation=man:php-fpm8.0(8)
After=network.target

[Service]
Type=simple
PIDFile=/var/run/php8.0-fpm.pid
ExecStart=/opt/php8/sbin/php-fpm --nodaemonize --fpm-config /opt/php8/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID

[Install]
WantedBy=multi-user.target
Copy after login

Configuration

fpm-fpm, php.ini configuration

Same as PHP7, pay attention to user permissions

opcache configuration

PHP8 has an additional jit configuration, as follows

[opcache]
zend_extension=opcache.so
opcache.enable=1 
opcache.jit_buffer_size=100M
opcache.jit=1255
Copy after login

Start

systemctl start php8.0-fpm
Copy after login

laravel

Create a laravel project[Recommended: laravel video tutorial]

cd /opt/web
composer8 create-project --prefer-dist laravel/laravel php8
Copy after login

Configure it .env file

nginx configuration

nginx configuration is consistent with PHP7

server {
    listen 94;

    access_log  /tmp/test94.log main;

    root /opt/web/php8/public;
    index index.php index.html index.htm;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php {
        fastcgi_pass unix:/run/php/php8.0-fpm.sock;
        fastcgi_index /index.php;

        include fastcgi_params;

        fastcgi_split_path_info       ^(.+\.php)(/.+)$;
        fastcgi_param PATH_INFO       $fastcgi_path_info;
        fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}
Copy after login

Add an interface

laravel7's route writing method is somewhat problematic in laravel8. Change the writing method of RouteServiceProvider.php.
For example, for API routing, change $this->namespace to App\Http\Controllers\Api.

public function boot()
    {
        $this->configureRateLimiting();

        $this->routes(function () {
            Route::prefix('api')
                ->middleware('api')
		->namespace('App\Http\Controllers\Api')
                ->group(base_path('routes/api.php'));

            Route::middleware('web')
                ->namespace($this->namespace)
                ->group(base_path('routes/web.php'));
        });
    }
Copy after login

Others are the same, no need to modify.

Add a test interface to see:

Route::get('/test','WxController@test');
Copy after login

testThe interface checks a piece of data and returns it

<?phpnamespace App\Http\Controllers\Api;use App\Models\WareHouses;use Illuminate\Foundation\Auth\Access\AuthorizesRequests;use Illuminate\Foundation\Bus\DispatchesJobs;use Illuminate\Foundation\Validation\ValidatesRequests;use Illuminate\Http\Request;use Illuminate\Routing\Controller as BaseController;class WxController extends BaseController{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;

    public function test(Request $request)
    {
        return WareHouses::find(1)->toarray();
    }}
Copy after login

Comparison test PHP7

This I used PHP7.3 for the first time, the interface code is the same as PHP8, and opcache is enabled on both.

The server configuration is 1 core 2G, use ab to simply test.

ab -n 100 -c 10
Copy after login

The test results of PHP7.3 are as follows:

This is ApacheBench, Version 2.3 <$Revision: 1843412 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 192.168.10.10 (be patient).....done


Server Software:        nginx/1.14.0
Server Hostname:        192.168.10.10
Server Port:            94

Document Path:          /api/test
Document Length:        255 bytes

Concurrency Level:      10
Time taken for tests:   0.400 seconds
Complete requests:      10
Failed requests:        0
Total transferred:      5720 bytes
HTML transferred:       2550 bytes
Requests per second:    25.00 [#/sec] (mean)
Time per request:       399.994 [ms] (mean)
Time per request:       39.999 [ms] (mean, across all concurrent requests)
Transfer rate:          13.97 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        8   10   2.1     11      13
Processing:   101  159  42.8    174     228
Waiting:      101  159  42.8    174     228
Total:        114  170  42.0    186     235

Percentage of the requests served within a certain time (ms)
  50%    186
  66%    186
  75%    197
  80%    219
  90%    235
  95%    235
  98%    235
  99%    235
 100%    235 (longest request)
Copy after login

The test results of PHP8.0 are as follows:

This is ApacheBench, Version 2.3 <$Revision: 1843412 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 192.168.10.10 (be patient).....done


Server Software:        nginx/1.14.0
Server Hostname:        192.168.10.10
Server Port:            94

Document Path:          /api/test
Document Length:        255 bytes

Concurrency Level:      10
Time taken for tests:   2.441 seconds
Complete requests:      100
Failed requests:        33
   (Connect: 0, Receive: 0, Length: 33, Exceptions: 0)
Non-2xx responses:      33
Total transferred:      268489 bytes
HTML transferred:       234720 bytes
Requests per second:    40.97 [#/sec] (mean)
Time per request:       244.096 [ms] (mean)
Time per request:       24.410 [ms] (mean, across all concurrent requests)
Transfer rate:          107.42 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        7   15  18.1     10     132
Processing:    47  210 224.4    106     817
Waiting:       17  118 107.4    101     787
Total:         55  226 222.1    122     828

Percentage of the requests served within a certain time (ms)
  50%    122
  66%    137
  75%    164
  80%    289
  90%    640
  95%    809
  98%    820
  99%    828
 100%    828 (longest request)
Copy after login

The above is the detailed content of Compilation, installation and use of PHP8.0 (detailed explanation). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template