LNMP环境搭建ThinkPHP5.1站点
- LNMP环境搭建
- 时间:2020-11-27
- 163人已阅读
1.安装composer
https://www.beambitious.cn/articleInfo/58
2.安装ThinkPHP5.1
cd /
mkdir www
cd /www/
composer create-project topthink/think=5.1.* tp5
3.更改nginx配置文件
vi /usr/local/nginx/conf/nginx.conf
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name 139.155.243.26;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /www/tp5/public;
index index.html index.htm index.php;
if (!-e $request_filename){
rewrite ^(.*)$ /index.php?s=$1 last; break;
}
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
#当请求网站下php文件的时候,反向代理到php-fpm
location ~ \.php$ {
#请求资源的根目录
root /www/tp5/public;
#将进入到该location内的uri请求看做是cgi程序,并将请求发送到9000端口,交由php-fpm处理。
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
}
4.保存nginx配置文件,在浏览器输入139.155.243.26,即可看到下图
5.查询数据库
本地已经远程连接了数据库
修改tp5.1的数据库配置文件
创建模型
控制器内调用
浏览器输入路由即可看到效果