目次
インストールと構成
laravel
今回初めて PHP7.3 を使用しました。インターフェイス コードは PHP8 と同じで、両方で opcache が有効になっています。
ホームページ バックエンド開発 PHP8 PHP8.0のコンパイル・インストール・使い方(詳細説明)

PHP8.0のコンパイル・インストール・使い方(詳細説明)

Feb 16, 2022 am 11:19 AM

PHP8.0の正式版がリリースされて久しいですが、この記事ではそのインストール方法と比較方法を紹介します。 [推奨: PHP ビデオ チュートリアル ]

インストールと構成

今回使用したオペレーティング システムUbuntu 18.04.4 LTS

インストール

1. 必要なライブラリを準備します

apt-get install -y autoconf libxml2-dev libsqlite3-dev \
libcurl4-openssl-dev libssl-dev libonig-dev libtidy-dev zlib1g-dev
ログイン後にコピー

2. 公式 Web サイトにアクセスして、正式バージョン 8.0 https をダウンロードします。 ://www.php.net/releases/8.0 /en.php

3. 解凍してインストールします

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
ログイン後にコピー

4. ソフト リンクを作成します

ln -s /opt/php8/bin/php /usr/bin/php8
ログイン後にコピー

5. インストールしますコンポーザー

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/
ログイン後にコピー

6. php8 .0 システムサービスを追加します

vim /lib/systemd/system/php8.0-fpm.service
ログイン後にコピー

内容は次のとおりです

[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
ログイン後にコピー

Configuration

fpm-fpm、php.ini 設定

PHP7 と同様、ユーザー権限に注意してください

opcache 設定

PHP8 には次のような追加の jit 設定

[opcache]
zend_extension=opcache.so
opcache.enable=1 
opcache.jit_buffer_size=100M
opcache.jit=1255
ログイン後にコピー

Start

systemctl start php8.0-fpm
ログイン後にコピー

laravel

laravel プロジェクトを作成する[推奨: laravel ビデオチュートリアル]

cd /opt/web
composer8 create-project --prefer-dist laravel/laravel php8
ログイン後にコピー

.env ファイルを設定します

nginx 設定

nginx 設定は 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;
    }
}
ログイン後にコピー

インターフェースの追加

laravel7のルート記述方法がlaravel8では若干問題があるため、RouteServiceProvider.phpの記述方法を変更します。
たとえば、API ルーティングの場合、$this->namespaceApp\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'));
        });
    }
ログイン後にコピー

その他は同じなので、変更する必要はありません。

Route::get('/test','WxController@test');
ログイン後にコピー

test

インターフェイスはデータの一部をチェックし、それを返します<div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false">&lt;?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)-&gt;toarray();     }}</pre><div class="contentsignin">ログイン後にコピー</div></div>比較テスト PHP7

今回初めて PHP7.3 を使用しました。インターフェイス コードは PHP8 と同じで、両方で opcache が有効になっています。

サーバー構成は 1 コア 2G です。単純にテストするには ab を使用します。

ab -n 100 -c 10
ログイン後にコピー

PHP7.3 のテスト結果は次のとおりです:

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)
ログイン後にコピー

PHP8.0 のテスト結果は次のとおりです:

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)
ログイン後にコピー

以上がPHP8.0のコンパイル・インストール・使い方(詳細説明)の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。

ホットAIツール

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

写真から衣服を削除するオンライン AI ツール。

Undress AI Tool

Undress AI Tool

脱衣画像を無料で

Clothoff.io

Clothoff.io

AI衣類リムーバー

AI Hentai Generator

AI Hentai Generator

AIヘンタイを無料で生成します。

ホットツール

メモ帳++7.3.1

メモ帳++7.3.1

使いやすく無料のコードエディター

SublimeText3 中国語版

SublimeText3 中国語版

中国語版、とても使いやすい

ゼンドスタジオ 13.0.1

ゼンドスタジオ 13.0.1

強力な PHP 統合開発環境

ドリームウィーバー CS6

ドリームウィーバー CS6

ビジュアル Web 開発ツール

SublimeText3 Mac版

SublimeText3 Mac版

神レベルのコード編集ソフト(SublimeText3)