一、安装配置laraveljavascript
1.一、composer下载laravelphp
composer create-project --prefer-dist laravel/laravel blog "5.5.*"
1.二、给storage
目录和 bootstrap/cache
目录配置读写权限css
chmod -R 777 storage chmod -R 777 bootstrap/cache
1.三、配置.env文件的数据库信息html
DB_HOST=服务器ip DB_DATABASE=数据库名 DB_USERNAME=用户名 DB_PASSWORD=密码
二、安装配置nginxjava
2.一、安装nignxnginx
Centos7Yum安装配置指定版本nginxlaravel
2.二、配置nginxgit
#强制跳转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; } }
三、输入域名便可看到Laravel欢迎页面:github
四、编译安装Swooleweb
git clone https://github.com/swoole/swoole-src.git && \
cd swoole-src && \ phpize && \ ./configure && \ make && make install
在
并重启phpphp.ini中添加
extension=swoole.so
五、安装Laravels拓展包
直接在Laravel项目中集成Swoole,不用改底层代码
5.一、经过composer安装Laravels
composer require "hhxsv5/laravel-s:~3.0" -vvv
5.二、Laravel
: 修改文件config/app.php
,Laravel 5.5+支持包自动发现,可跳过这步
'providers' => [ //...
Hhxsv5\LaravelS\Illuminate\LaravelSServiceProvider::class, ],
5.三、发布配置文件(每次升级LaravelS后,建议从新发布一次配置文件)
php artisan laravels publish
5.四、修改配置config/laravels.php
:监听的IP、端口等,参考配置项
5.五、启动Laravels
在运行以前,请先仔细阅读:注意事项
php artisan laravels start //启动
php artisan laravels start -d //守护进程模式运行
5.六、配置Nginx,由laravels接管php-fpm处理php文件
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;
} }
经测试,ab压测同一个接口,使用Swoole之后提升了两倍性能