【问题标题】:Apache2 LinuxMint LararvelApache2 Linux Mint Laravel
【发布时间】:2021-11-25 17:55:42
【问题描述】:

我在 laravel 中配置了 apache 虚拟主机链接项目。 但我猜自动加载器不起作用。 这是我的情况。

在 /etc/apache2/sites-avaible 中为虚拟主机写入了我的文件(我尝试过 并且不起作用)。

<VirtualHost medfx.lo:80>

    ServerAdmin webmaster@medfx.lo
    DocumentRoot /var/www/medfx/public

    <Directory "/var/www/medfx/public">
            Options FollowSymLinks MultiViews
        ReWriteEngine On
    </Directory>

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

我 /var/www/ 我创建了我的项目 medfx 并创建了 laravel 项目。

root@tecnico57-System-Product-Name:/var/www/medfx# ls -l
drwxr-xr-x 11 root root   4096 ott  5 12:43 app
-rwxr-xr-x  1 root root   1686 ott  5 12:43 artisan
drwxr-xr-x  3 root root   4096 ott  5 12:43 bootstrap
-rwxr-xr-x  1 root root   1827 ott  5 12:43 composer.json
-rwxr-xr-x  1 root root 302152 ott  5 14:29 composer.lock
drwxr-xr-x  2 root root   4096 ott  5 12:43 config
drwxr-xr-x  5 root root   4096 ott  5 12:43 database
-rwxr-xr-x  1 root root    767 ott  5 12:43 package.json
-rw-r--r--  1 root root 776150 ott  5 12:43 package-lock.json
-rwxr-xr-x  1 root root   1202 ott  5 12:43 phpunit.xml
drwxr-xr-x  8 root root   4096 ott  5 12:43 public
-rwxr-xr-x  1 root root   3810 ott  5 12:43 README.md
drwxr-xr-x 10 root root   4096 ott  5 12:43 resources
drwxr-xr-x  2 root root   4096 ott  5 12:43 routes
-rwxr-xr-x  1 root root    563 ott  5 12:43 server.php
drwxr-xr-x  5 root root   4096 ott  5 12:43 storage
drwxr-xr-x  4 root root   4096 ott  5 12:43 tests
drwxr-xr-x 49 root root   4096 ott  5 14:29 vendor
-rwxr-xr-x  1 root root    520 ott  5 12:43 webpack.mix.js

现在,如果我继续http://medfx.lo,它是视图:

<?php

use Illuminate\Contracts\Http\Kernel;
use Illuminate\Http\Request;

define('LARAVEL_START', microtime(true));

/*
|--------------------------------------------------------------------------
| Check If The Application Is Under Maintenance
|--------------------------------------------------------------------------
|
| If the application is in maintenance / demo mode via the "down" command
| we will load this file so that any pre-rendered content can be shown
| instead of starting the framework, which could cause an exception.
|
*/

if (file_exists(__DIR__.'/../storage/framework/maintenance.php')) {
    require __DIR__.'/../storage/framework/maintenance.php';
}

/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| this application. We just need to utilize it! We'll simply require it
| into the script here so we don't need to manually load our classes.
|
*/

require __DIR__.'/../vendor/autoload.php';

/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request using
| the application's HTTP kernel. Then, we will send the response back
| to this client's browser, allowing them to enjoy our application.
|
*/

$app = require_once __DIR__.'/../bootstrap/app.php';

$kernel = $app->make(Kernel::class);

$response = tap($kernel->handle(
    $request = Request::capture()
))->send();

$kernel->terminate($request, $response);

我的 /etc/hosts:

127.0.0.1   localhost
127.0.1.1   tecnico57-System-Product-Name

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

谁能帮帮我?

最好的问候。

【问题讨论】:

  • 我在 /etc/apache2/sites-avaiable 中的文件是“medfx.lo.conf”
  • 您是否启用了虚拟主机/站点?例如:a2ensite /etc/apache2/sites-available/medfx.lo.confln -s /etc/apache2/sites-available/medfx.lo.conf /etc/apache2/sites-enabled/medfx.lo.conf
  • 是的,它已经启用。我应该在 /etc/hosts 中找到我的虚拟主机?现在,主机是这样的: 127.0.0.1 localhost 127.0.1.1 tecnico57-System-Product-Name # 以下行对于支持 IPv6 的主机是可取的 ::1 ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters
  • 不,不是/etc/hosts,但medfx.lo.conf 是否已软链接到/etc/apache2/sites-enabled/
  • 是的,在执行 a2ensite medfx.lo.conf 后被软链接。我猜虚拟主机是正确的,但没有解释 index.php,所以不加载项目

标签: php linux laravel apache2 virtualhost


【解决方案1】:

解决方案是 PHP。 Apache2 没有解释 Laravel 项目,没有正确运行 php 并且它在没有解释的情况下打印代码到屏幕。

解决方案是重新安装全局 php 并将 apache2 链接到新版本的 php。留下代码。

sudo add-apt-repository ppa:ondrej/php

sudo apt-get update

sudo apt-get install php7.1

sudo apt-get install php7.1-cli php7.1-common php7.1-json php7.1-opcache php7.1-mysql php7.1-mbstring php7.1-mcrypt php7.1-zip php7.1-fpm

sudo a2dismod php7.2

sudo a2enmod php7.1

sudo service apache2 restart

在运行之前在命令中使用你喜欢的版本 php。

最好的问候 无论如何,泰克里斯蒂安!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-12-18
    • 2014-11-11
    • 1970-01-01
    • 2020-11-25
    • 1970-01-01
    • 1970-01-01
    • 2014-08-18
    • 2015-09-02
    相关资源
    最近更新 更多