首頁 > 後端開發 > PHP8 > 主體

PHP8.0的編譯安裝與使用(詳解)

藏色散人
發布: 2023-02-17 12:32:01
轉載
8291 人瀏覽過

PHP8.0的正式版早已發布,本文就介紹下它的安裝,並使用laravel對比PHP7 【建議: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.到官網下載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.安裝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/
登入後複製

6.新增一個php8 .0的system service

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
登入後複製

配置

fpm-fpm,php.ini配置

和PHP7一樣,注意下使用者權限

opcache配置

PHP8多了一個jit配置,如下

[opcache]
zend_extension=opcache.so
opcache.enable=1 
opcache.jit_buffer_size=100M
opcache.jit=1255
登入後複製

#啟動

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->namespace###改為###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'));
        });
    }
登入後複製
###其他一樣,不用修改。 ######加上測試介面看看:###
Route::get('/test','WxController@test');
登入後複製
######test###介面查一資料並回傳###
toarray();
    }}
登入後複製
###比較測試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中文網其他相關文章!

相關標籤:
來源:csdn.net
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!