목차
설치 및 구성
laravel
백엔드 개발 PHP8 PHP8.0 컴파일, 설치 및 사용(자세한 설명)

PHP8.0 컴파일, 설치 및 사용(자세한 설명)

Feb 16, 2022 am 11:19 AM

PHP8.0의 공식 버전이 출시된 지 오래되었습니다. 이 기사에서는 설치 방법을 소개하고 laravel을 사용하여 PHP7을 비교합니다. [권장: PHP 비디오 튜토리얼]

설치 및 구성

이번에 사용한 운영체제는 Ubuntu 18.04.4 LTSUbuntu 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改为AppHttpControllersApi

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

설치

1. 필요한 라이브러리를 준비하세요

<?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();
    }}
로그인 후 복사
2. 8.0 공식 버전 https://www.php.net/releases/8.0/en.php

3. 압축을 풀고 설치하세요

ab -n 100 -c 10
로그인 후 복사
4. 소프트 연결을 만드세요

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)
로그인 후 복사
5. 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)
로그인 후 복사
🎜 내용은 다음과 같습니다🎜rrreee🎜구성🎜🎜fpm-fpm, php.ini 구성🎜🎜PHP7과 동일 주의하세요 사용자 권한🎜🎜opcache 구성🎜🎜PHP8에는 다음과 같은 추가 jit 구성이 있습니다.🎜rrreee🎜시작🎜rrreee🎜laravel🎜🎜laravel 프로젝트 만들기[권장: laravel 비디오 튜토리얼🎜]🎜rrreee🎜.env 파일 구성🎜🎜 nginx 구성🎜🎜nginx 구성 PHP7🎜rrreee🎜인터페이스 추가🎜🎜laravel7의 경로 작성 방법이 laravel8에서 일부 문제가 있으므로 RouteServiceProvider의 작성 방법을 변경하세요. .php.
예를 들어 API 라우팅의 경우 $this->namespaceAppHttpControllersApi로 변경합니다. 🎜rrreee🎜다른 것도 똑같으니 수정할 필요 없습니다. 🎜🎜확인할 테스트 인터페이스 추가: 🎜rrreee🎜test 인터페이스는 데이터 조각을 확인하고 🎜rrreee🎜비교 테스트 PHP7🎜🎜이번에는 PHP7.3을 사용하는데 인터페이스 코드는 동일합니다. PHP8과 마찬가지로 둘 다 opcache를 켭니다. 🎜🎜서버 구성은 1코어 2G입니다. 간단히 테스트하려면 ab를 사용하세요. 🎜rrreee🎜PHP7.3의 테스트 결과는 다음과 같습니다. 🎜rrreee🎜PHP8.0의 테스트 결과는 다음과 같습니다. 🎜rrreee

위 내용은 PHP8.0 컴파일, 설치 및 사용(자세한 설명)의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 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 옷 제거제

Video Face Swap

Video Face Swap

완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

뜨거운 도구

메모장++7.3.1

메모장++7.3.1

사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전

SublimeText3 중국어 버전

중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기

스튜디오 13.0.1 보내기

강력한 PHP 통합 개발 환경

드림위버 CS6

드림위버 CS6

시각적 웹 개발 도구

SublimeText3 Mac 버전

SublimeText3 Mac 버전

신 수준의 코드 편집 소프트웨어(SublimeText3)