Laravel通過Swoole提升效能 Centos7Yum安裝配置指定版本nginx
阿新 • • 發佈:2018-12-12
1、安裝配置laravel
1.1、composer下載laravel
composer create-project --prefer-dist laravel/laravel blog "5.5.*"
1.2、給storage
目錄和 bootstrap/cache
目錄配置讀寫許可權
chmod -R 777 storage chmod -R 777 bootstrap/cache
1.3、配置.env檔案的資料庫資訊
DB_HOST=伺服器ip DB_DATABASE=資料庫名 DB_USERNAME=使用者名稱 DB_PASSWORD=密碼
2、安裝配置nginx
2.1、安裝nignx
2.2、配置nginx
#強制跳轉https
server { listen 80; server_name www.xxxxx.com; rewrite ^(.*) https://$server_name$1 permanent; } server { listen 443; ssl on; server_name www.xxxxx.com; index index.html index.htm index.php; root/usr/share/nginx/html/code/blog/public/; ssl_certificate cert/xxxx.pem; ssl_certificate_key cert/xxxx.key; ssl_session_timeout 5m; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on;
#優雅連結 location/ { try_files $uri $uri/ /index.php?$query_string; } #將php請求交給php-fpm處理 location ~ \.php { fastcgi_index index.php; #fastcgi_pass web_server; fastcgi_pass 127.0.0.1:9000; include fastcgi_params; set $path_info ""; set $real_script_name $fastcgi_script_name; fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html/code/xxxx/public/$real_script_name; fastcgi_param SCRIPT_NAME $real_script_name; fastcgi_param PATH_INFO $path_info; } }
3、輸入域名即可看到Laravel歡迎頁面:
4、編譯安裝Swoole
git clone https://github.com/swoole/swoole-src.git && \ cd swoole-src && \ phpize && \ ./configure && \ make && make install
在
並重啟phpphp.ini中新增
extension=swoole.so
5、安裝Laravels拓展包
直接在Laravel專案中整合Swoole,不用改底層程式碼
5.1、通過composer安裝Laravels
composer require "hhxsv5/laravel-s:~3.0" -vvv
5.2、Laravel
: 修改檔案config/app.php
,Laravel 5.5+支援包自動發現,可跳過這步
'providers' => [ //... Hhxsv5\LaravelS\Illuminate\LaravelSServiceProvider::class, ],
5.3、釋出配置檔案(每次升級LaravelS後,建議重新發布一次配置檔案)
php artisan laravels publish
5.4、修改配置config/laravels.php
:監聽的IP、埠等,參考配置項
5.5、啟動Laravels
在執行之前,請先仔細閱讀:注意事項
php artisan laravels start //啟動 php artisan laravels start -d //守護程序模式執行
5.6、配置Nginx,由laravels接管php-fpm處理動態資源
gzip on; gzip_min_length 1024; gzip_comp_level 2; gzip_types text/plain text/css text/javascript application/json application/javascript application/x-javascript application/xml application/x-httpd-php image/jpeg image/gif image/png font/ttf font/otf image/svg+xml; gzip_vary on; gzip_disable "msie6"; upstream laravels { # 通過 IP:Port 連線 server 127.0.0.1:5200 weight=5 max_fails=3 fail_timeout=30s; keepalive 16; } server { listen 80; server_name www.xxxxx.com; rewrite ^(.*) https://$server_name$1 permanent; } server { listen 443; ssl on; server_name www.xxxxx.com; index index.html index.htm index.php; root /usr/share/nginx/html/code/blog/public/; ssl_certificate cert/xxx.pem; ssl_certificate_key cert/xxx.key; ssl_session_timeout 5m; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; #關閉目錄瀏覽 autoindex off; # Nginx處理靜態資源(建議開啟gzip),LaravelS處理動態資源。 location / { try_files $uri @laravels; } location @laravels { # proxy_connect_timeout 60s; # proxy_send_timeout 60s; # proxy_read_timeout 120s; proxy_http_version 1.1; proxy_set_header Connection ""; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Real-PORT $remote_port; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_set_header Scheme $scheme; proxy_set_header Server-Protocol $server_protocol; proxy_set_header Server-Name $server_name; proxy_set_header Server-Addr $server_addr; proxy_set_header Server-Port $server_port; proxy_pass http://laravels; } }