本文目錄一覽:
Thinkphp5項目在nginx服務器部署
1,切換到nginx的配置目錄,找到nginx.conf文件
cd /usr/local/nginx/conf
vim nginx.conf
2,如果是單項目部署的話,只需要在nginx.conf文件裏面加上以下
server{
listen 80;
# 域名,本地測試可以使用127.0.0.1或localhost
server_name ;
# php項目根目錄
root /home/data-www/blog;
location /{
# 定義首頁索引文件的名稱
index index.php index.html index.htm;
# 影藏入口文件
if (-f $request_filename/index.html){
rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php){
rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
rewrite (.*) /index.php;
}
try_files $uri $uri/ /index.php?$query_string;
}
# PHP 腳本請求全部轉發到 FastCGI處理. 使用FastCGI協議默認配置.
# Fastcgi服務器和程序(PHP)溝通的協議
.location ~ .*\.php${
# 設置監聽端口
fastcgi_pass 127.0.0.1:9000;
# 設置nginx的默認首頁文件
fastcgi_index index.php;
# 設置腳本文件請求的路徑
fastcgi_param SCRIPT_FILENAME$document_root$fastcgi_script_name;
# 引入fastcgi的配置文件
include fastcgi_params;
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
set $path_info $fastcgi_path_info;
fastcgi_param PATH_INFO $path_info;
try_files $fastcgi_script_name =404;
}
}
3,如果多項目部署,就需要配置vhost
第一步:編輯nginx.conf文件,在最後加上 include vhost/*.conf;
第二步:進入vhost文件夾,創建 域名.conf 文件,如創建一個:quanma.meyat.com.conf
第三步:編輯quanma.meyat.com.conf文件,內容如下:
server
{
listen 80;
server_name quanma.meyat.com;
index index.html index.htm index.php default.html default.htm default.php;
root /data/wwwroot/default/quanma/public/;
#error_page 404 /404.html;
location / {
index index.html index.php;
if (-f $request_filename/index.html){
rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php){
rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
rewrite (.*) /index.php;
}
try_files $uri $uri/ /index.php?$query_string;
}
location ~ [^/]\.php(/|$)
{
# comment try_files $uri =404; to enable pathinfo
#try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
set $path_info $fastcgi_path_info;
fastcgi_param PATH_INFO $path_info;
try_files $fastcgi_script_name =404;
#include fastcgi.conf;
#include pathinfo.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
# Disallow access to .ht, .svn, .bzr, .git, .hg, .cvs directories
location ~ /\.(ht|svn|bzr|git|hg|cvs) {
deny all;
}
#access_log /date/nginx/bmp.com.conf/access.log main;
}
PHP項目如何上傳到服務器
用FTP上傳工具上傳即可。這裡以8UFTP軟件為例:
1、下載安裝FTP軟件,輸入服務器IP地址,FTP的用戶名和密碼進行連接。
2、連接FTP後,找到要上傳的PHP項目文件,上傳到服務器即可。
php項目如何部署在服務器上
一、阿里ECS服務器配置
1.因為線上已經有幾個站點了.所以要配置ngnix多站點
2.阿里雲ecs目錄結構,ngxin 在/etc/nginx/目錄下,配置的地方主要是nginx.config文件。或者在conf.d新建一個配置文件然後在include到nginx.config文件中
3.nginx.config新建站點信息
server {
listen 80;
server_name www.你的域名.com;
root 站點的相對路徑;
index index.php index.html index.htm;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
#try_files $uri $uri/ /index.php;
root /opt/www/pcweb/ytyy_pc;
index index.php index.html index.htm; if (!-e $request_filename) { rewrite ^(.*)$ /index.php?s=$1 last; break; }} url重寫(可以沒有)
# redirect server error pages to the static page /40x.html
#
error_page 404 /404.html; 40錯誤頁面配置
location = /40x.html {
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html; 50錯誤頁面配置
location = /50x.html {
}
location ~ \.php$ {
root 站點相對路徑;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
配置文件的基本內容如上;
配置完成後測試配置文件是否正確
這樣配置就可以使用了
然後重啟nginx服務器
這樣nginx配置就結束了可以使用了。吧站點文件放到對應的目錄下面。我直接git clone過去的。
二.thinkphp項目文件轉移
本來以為上傳完就結束了。上傳上去碰到的第一個問題就是訪問頁面報錯,頁面被電信的114頁面劫持了。。。麻蛋 看不到報錯
萬能百度大法
解決方法1.internet高級選項-隱私-站點 新加阻止站點
解決方法2:控制面板-網絡和internet-本地連接-屬性-ipv4 使用如下ip
終於搞定可以看到報錯頁面了。。。。。。麻蛋。再次開啟萬能百度大法
得到最終結論是文件目錄權限引起的。thinkphp 的runtime目錄沒有寫入權限。。thinkphp文件上傳到阿里的好像都有這個問題。解決問題很簡單
進入到項目文件目錄
直接跟文件最高權限
chmod -R 777 [目錄] //linux修改文件權限
Eclipse上寫的php文件怎麼在服務器上運行
1,源碼在服務器上面,通過url運行
2,源碼在本地服務器上,通過服務器運行,和服務器差不多
3,配置eclipse的php cli模式,不需要任何一種Web服務器(包括Apache或MS IIS等),只需要安裝php就可以,這也是最常用的的方法~
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hk/n/250789.html