安装与配置
本次使用的操作系统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/
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配置
opcache配置
[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配置
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
接口查一条数据并返回
<?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(); }}
对比测试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)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。