php项目在服务器上,php一般搭建在什么服务器上

发布时间:2022-11-19

本文目录一览:

  1. Thinkphp5项目在nginx服务器部署
  2. PHP项目如何上传到服务器
  3. php项目如何部署在服务器上
  4. Eclipse上写的php文件怎么在服务器上运行

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/;
          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(/|$) {
              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;
          }
          location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
              expires 30d;
          }
          location ~ .*\.(js|css)?$ {
              expires 12h;
          }
          location ~ /\.(ht|svn|bzr|git|hg|cvs) {
              deny all;
          }
      }
      

PHP项目如何上传到服务器

用FTP上传工具上传即可。这里以8UFTP软件为例:

  1. 下载安装FTP软件,输入服务器IP地址,FTP的用户名和密码进行连接。
  2. 连接FTP后,找到要上传的PHP项目文件,上传到服务器即可。

php项目如何部署在服务器上

一、阿里ECS服务器配置

  1. 因为线上已经有几个站点了,所以要配置nginx多站点。
  2. 阿里云ECS目录结构:nginx在/etc/nginx/目录下,配置的地方主要是nginx.conf文件。或者在conf.d新建一个配置文件然后在nginx.conf中include。
  3. nginx.conf新建站点信息:
    server {
        listen 80;
        server_name www.你的域名.com;
        root 站点的相对路径;
        index index.php index.html index.htm;
        location / {
            root /opt/www/pcweb/ytyy_pc;
            index index.php index.html index.htm;
            if (!-e $request_filename) {
                rewrite ^(.*)$ /index.php?s=$1 last;
                break;
            }
        }
        error_page 404 /404.html;
        location = /40x.html {
        }
        error_page 500 502 503 504 /50x.html;
        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服务器,把站点文件放到对应的目录下面。我直接git clone过去的。

二、ThinkPHP项目文件转移

本来以为上传完就结束了。上传上去碰到的第一个问题就是访问页面报错,页面被电信的114页面劫持了。 解决方法:

  1. Internet高级选项 - 隐私 - 站点,新建阻止站点。
  2. 控制面板 - 网络和Internet - 本地连接 - 属性 - IPv4,使用如下IP。 最终结论是文件目录权限引起的。ThinkPHP的runtime目录没有写入权限。解决问题很简单:
chmod -R 777 [目录]  # Linux修改文件权限

Eclipse上写的php文件怎么在服务器上运行

  1. 源码在服务器上面,通过URL运行。
  2. 源码在本地服务器上,通过服务器运行,和服务器差不多。
  3. 配置Eclipse的PHP CLI模式,不需要任何一种Web服务器(包括Apache或MS IIS等),只需要安装PHP就可以,这也是最常用的方法。