-1

i need to configure: laravel 8 php 7.4 apache 2.4 debian 10 (buster)

when i create a new project "laravel new project", i run this command, php artisan serve and all works ok, but when I configure a virtual host something goes wrong, the browser says

http://develop.test

   <?php

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

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

/*
|--------------------------------------------------------------------------
| Check If Application Is Under Maintenance
|--------------------------------------------------------------------------
|
| If the application is maintenance / demo mode via the "down" command we
| will require this file so that any prerendered template 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); 

and the aplication is not in maintenance mode, i never run command like php artisan down. with that problem i try to run php artisan down and next php artisan up, but nothing happen, the error is always there.

here is my apache conf file

 <VirtualHost *:80>
    ServerAdmin yvasquez@develop.test
    ServerName develop.test
    ServerAlias www.develop.test
    DocumentRoot /var/www/html/develop/public


    <Directory /var/www/html/develop/public>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        ReWriteEngine On
        Require all granted
        <FilesMatch \.php$>
            # Change this "proxy:unix:/path/to/fpm.socket"
            # if using a Unix socket
            # SetHandler "proxy:fcgi://127.0.0.1:9000"
        </FilesMatch>
        
    </Directory>

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

</VirtualHost>

I followed this article for this conf file Setting document root for Laravel project on Apache virtual host

YuberV
  • 7
  • 7
  • Your is empty, contains only comments. – Gerard H. Pille Jan 19 '21 at 23:14
  • thats right but i do not what i must put there – YuberV Jan 20 '21 at 01:47
  • Maybe nothing, but then remove the FilesMatch section. Else uncomment the SetHandler directive. – Gerard H. Pille Jan 20 '21 at 02:38
  • Gerard H. Pille thanks for your patience, I follow your recommendatios. i delete FilesMatch section and uncomment de SetHanlder too. I try with a new project and the problem is the same and always there. When i run "php artisan serve" all works ok but with a little problem, when i loading images in storage, the image not found because the url image is not with the 8000 port – YuberV Jan 20 '21 at 15:13
  • "the browser says http://develop.test" What does the browser "say" ? You are the only one who can access develop.test. – Gerard H. Pille Jan 20 '21 at 16:03
  • What is the 8000 port you mention? Develop.test can only be found on port 80: !! – Gerard H. Pille Jan 20 '21 at 16:43
  • when i run "php artisan serve" it enables localhost:8000 and all works ok, but the application dont load images that are en Storage folder because it points to http://localhost/storage/images/.... and the application not put por 8000.00 i am working with "php artisan serve" because my php configuration don't work. , remember in my problem i can't run develop.test. – YuberV Jan 21 '21 at 02:48
  • firefox on http://develop.test says make(Kernel::class); $response = tap($kernel->handle( $request = Request::capture() ))->send(); $kernel->terminate($request, $response); – YuberV Jan 21 '21 at 02:49
  • When Laravel is running on port 8000, the SetHandler "proxy:fcgi://127.0.0.1:9000" should refer to 8000, not 9000. Also, do you find anything else in your apache configuration referring to PHP ? – Gerard H. Pille Jan 21 '21 at 09:51
  • concerning the images not loading, I would change " 'url' => env('APP_URL', 'http://localhost')," in app.php and add the port number. – Gerard H. Pille Jan 21 '21 at 15:09
  • thanks for your answer, i will work with "php artisan serve" for now, Also, do you find anything else in your apache configuration referring to PHP ? all is by default – YuberV Jan 22 '21 at 02:07
  • "all is by default " Is that a "no"? It seems develop.test is not configured to handle php. No php = no laravel. – Gerard H. Pille Jan 22 '21 at 02:49
  • I recently install xampp 8.0.0-2 now, i am working on it very well with the same project, and I will be left wondering how the configuration is without xampp. Thanks for your patience Gerard H. Pille. I am so sorry for my english – YuberV Jan 23 '21 at 22:01
  • I have no problems with your english. Es mucho mejor que mi español, si eso es lo que hablas. This morning, just past midnight here, I finally managed to configure Apache, PHP-FPM and Laravel to work together. I will try to document my configuration in an answer below. It took me two days because I have never used Laravel before. – Gerard H. Pille Jan 24 '21 at 10:40
  • gracias, well, I wait patiently for your answer, thanks a lot, – YuberV Jan 24 '21 at 17:04
  • You are (a) very (good) patient. – Gerard H. Pille Feb 04 '21 at 09:46
  • "Something goes wrong" is pretty broad, what does that mean? Please share more details by editing your question – Nico Haase Feb 04 '21 at 09:54

1 Answers1

1

I added the FQDN to /etc/hosts

127.0.0.1   localhost me.me.be example.me.be

and then a rather simple apache configuration

<VirtualHost _default_:*>
        ServerName example.me.be
        ServerAdmin me@me.be
        DocumentRoot /var/www/html/example.me.be/public/
        DirectoryIndex /index.php index.php
        ErrorLog ${APACHE_LOG_DIR}/error_example.log
        CustomLog ${APACHE_LOG_DIR}/access_example.log combined
        ProxyPassMatch "^/(.*\.php(\?.*)?)$" "fcgi://127.0.0.1:9000/var/www/html/example.me.be/public/$1"
        <Directory /var/www/html/example.me.be/public/>
                AllowOverride ALL
        </Directory>
</VirtualHost>

/var/www/html/example.me.be is where Laravel has been "installed" - without any use of composer or "laravel install", just download a create-project from php-download.com.

127.0.0.1:9000 is where php-fpm is listening. This may need a change to its configuration, if by default it only listens on a socket.

/etc/php/7.4/fpm/pool.d/www.conf:

listen = 9000

Laravel needed some extensions to be activated (and installed if not).

/etc/php/7.4/fpm/php.ini:

extension=pdo
extension=mysqlnd
extension=pdo_mysql
extension=json
extension=tokenizer

pdo_mysql depends on mysqlnd, some debugging was needed to find this. Also, make sure you have a page with phpinfo(), very enlightening. MySQL is no must, it's MariaDB anyhow, PostgreSQL works too.

Gerard H. Pille
  • 2,528
  • 1
  • 13
  • 17