PHP脚本未运行

问题描述 投票:1回答:2

我正在尝试使用ubuntu上的PHP mysql在visual studio代码中编写一个基本的登录/注册系统。但是,当我尝试使用Web浏览器或实时服务器打开代码时,会下载而不是运行。

无论代码如何,只要使用.php扩展名命名文件,就会出现此问题。任何帮助将不胜感激,抱歉新手问题。

我可以使它工作的唯一方法是将代码放在/ var / www / html中,然后在地址栏中输入我的ip。但是,这有点烦人,我非常想使用visual studio live server。

php sql-server login-script
2个回答
1
投票

问题是你的应用服务器,无论你使用nginx还是apache,都需要配置可以执行的文件类型。能够使用域名访问您公共IP的位置;虚拟主机配置。

**Configuration for Apache:**
    <VirtualHost *: 80>
         ServerAdmin [email protected]
         ServerName yourlocaldomain.com
         ServerAlias www.yourlocaldomain.com
         DocumentRoot / var / www / sites / yourproject #Route to your project
         ErrorLog $ {APACHE_LOG_DIR} /error.log
         CustomLog $ {APACHE_LOG_DIR} /access.log combined
    </ VirtualHost>

**Configuration for nginx**
    server {
             listen 80;
             root / var / www / sites / yourproject; #Route to your project
             index index.html index.php; #Type of files that you can run
             server_name yourlocaldomain.com;
             location / {
                     try_files $uri $uri / = 404;
             }
    }

0
投票

围绕这个没有办法轻松。除非你把它放在一个文件夹中,其中apache(或你正在运行的任何web服务器)可以使用你的代码访问和处理文件,它只会给你自己的文件(“下载它”)。

您有没有理由不将整个代码库放在/var/www/html文件夹中?

© www.soinside.com 2019 - 2024. All rights reserved.