php部署到服务器(php部署到服务器端口)
- 服务器
- 2022-12-19 01:06:44
- 19
今天给各位分享php部署到服务器的知识,其中也会对php部署到服务器端口进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:
- 1、php项目如何部署在服务器上
- 2、如何使用SVN的FTP将Php部署到远程服务器
- 3、Thinkphp5项目在nginx服务器部署
- 4、怎么搭建php服务器?
- 5、前端vue与后端Thinkphp在服务器的部署
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修改文件权限
如何使用SVN的FTP将Php部署到远程服务器
你可以用svn2web通过FTP将每个已提交的文件上传到服务器。Svn2web是一组php脚本,你可以使用它作为SVN的hook。你可以将ftp服务器的地址、用户名和密码设置为目录上的SVN属性。效果很好!
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服务器?
php服务器搭建有两种方式
一种是linux+apache+mysql+php方式。
另外一种是windows+IIS+mysql+php方式。
还有一种方式,就是在windows模式下,用apache作为服务器。
这种情况。第一种配置较为复杂。而且一般作为服务器居多,个人电脑测试用,一般以windows为主。
所以下面的配置方式以windows7为例:
首先,你需要去下载php的原始文件,绿色版的,安装版的均可。
1.将下载的php压缩解压。得到如下的目录
、
2.添加IIS,windows7默认情况下是不安装IIS的。
打开控制面板-程序和功能-打开或关闭windows功能。安装好IIS后如下:
3,添加处理程序映射
请求路径设为*.php,模块选择fastCgiModule。在windows+IIS模式下。fastCGI模式比传统的isapi模式效率要高很多。
可执行文件选择刚才解压的目录。文件类型选择.exe,选择对应的文件即可。下面的名称可任意。
然后确定。重启IIS。服务器就好了。另外所谓的MYSQL。直接下载安装版的就行了。
前端vue与后端Thinkphp在服务器的部署
vue在服务端部署时,我们都知道通过npm run build 指令打包好的dist文件,通过http指定是可以直接浏览的,Thinkphp通过域名指向index.php文件才可以浏览。要使前端正常调用后端数据,有两种方法:1、前端跨域调用后端数据,2、前端打包文件部署在后端的服务器文件夹下(同域)。
web服务器: apache
一、跨域
在服务器配置站点:
在路径/home/www/ 下创建test项目文件夹,用来放项目文件。
找到httpd-vhosts.conf文件配置站点
前端站点:
ServerName test.test.com
DocumentRoot "/home/www/test/dist"
DirectoryIndex index.html
后端站点:
ServerName test.testphp.com
DocumentRoot "/home/www/test/php"
DirectoryIndex index.php
将前端打包好的dist文件放在/home/www/test/ 文件夹下,运行可浏览,当路径改变时,刷新会出现404错误。此时dist文件下创建一个.htaccess文件,当路径不存在时,路径指向能解决此问题。
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
在/home/www/test文件夹下创建项目根目录php文件夹,将thinkphp文件放在php下。TP5的入口文件在public文件下,在这将public下的入口文件index.php挪到php文件夹下(个人习惯将入口文件放在项目根目录), 后端绑定Index模块。
前端调用后端接口,存在跨域,跨域解决方法有好几种,在这我将在后端php做配置,解决跨域问题,在公用控制器设置跨域配置:
class Common extends Controller
{
public $param;
// 设置跨域访问
public function _initialize()
{
parent::_initialize();
isset($_SERVER['HTTP_ORIGIN']) ? header('Access-Control-Allow-Origin: '.$_SERVER['HTTP_ORIGIN']) : '';
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS');
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, authKey, sessionId");
$param = Request::instance()-param();
$this-param = $param;
}
}
前端调用登录接口: this.axios.post('', {user: '', password: ''})。
(可在webpack.base.conf.js文件下可定义接口:)
二、同域
后端配置同上,公共配置器中的header配置注释。将前端的dist文件下的所有文件(包含.htaccess),放在php文件夹下。将后端index控制器的index方法的路径重定向php下的index.html文件:
namespace app\index\controller;
use think\Controller;
class Index extends Controller
{
public function index() {
$this-redirect('/index.html');
}
}
前端调用登录接口: this.axios.post('/index.php/base/login', {user: '', password: ''})
转自:
php部署到服务器的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于php部署到服务器端口、php部署到服务器的信息别忘了在本站进行查找喔。
本文由admin于2022-12-19发表在靑年PHP官网,如有疑问,请联系我们。
本文链接:http://qnphp.com/post/20906.html