0

I am trying to run a laravel project on a remote server without executing artisan command. The design is executing properly. But I am not able to connect with the database. I edited the .env and databse.php file as per my requirements. Here I am attaching the connection code

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=mydb
DB_USERNAME=user
DB_PASSWORD=secret

'mysql' => [
        'driver' => 'mysql',
        'url' => env('DATABASE_URL'),
        'host' => env('DB_HOST', '127.0.0.1'),
        'port' => env('DB_PORT', '3306'),
        'database' => env('DB_DATABASE', 'mydb'),
        'username' => env('DB_USERNAME', 'user'),
        'password' => env('DB_PASSWORD', 'secret'),
        'unix_socket' => env('DB_SOCKET', ''),
        'charset' => 'utf8mb4',
        'collation' => 'utf8mb4_unicode_ci',
        'prefix' => '',
        'prefix_indexes' => true,
        'strict' => true,
        'engine' => null,
        'options' => extension_loaded('pdo_mysql') ? array_filter([
            PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
        ]) : [],

What should i do for this issue?

Pooja s p
  • 9
  • 6
  • is your database on same host? I mean on localhost and you are able to access the database using port 3306? Is your mySql running on port 3306? Where is your database situated? – Deepesh Thapa Mar 04 '21 at 11:01
  • I hosted my laravel project on a VM. Mysql is situated in the same vm. The database connecting only when i run php artisan serve command. – Pooja s p Mar 04 '21 at 11:05
  • Have you pointed your server host document root to public folder? Have you created a .htaccess file on you laravel root app. ? – Deepesh Thapa Mar 04 '21 at 11:12
  • https://stackoverflow.com/questions/28788285/how-to-run-laravel-without-artisan This will help you – Deepesh Thapa Mar 04 '21 at 11:21
  • I pointed server host to public folder and my project is running without executing the php artisan command. But the database is not connecting with it. – Pooja s p Mar 04 '21 at 11:25
  • Show me the error message – Deepesh Thapa Mar 04 '21 at 11:27
  • What does log file say? What is the error code. Display the error too – Deepesh Thapa Mar 04 '21 at 11:27
  • I am running my project by using "http://ip:port/laravel/public/" url. The initial page is running properly. But if i trying to login into the system, It is showing 404 not found error. I am fetching some db values to the initial page. This is also not working. – Pooja s p Mar 05 '21 at 03:26
  • Not Found The requested URL was not found on this server. Apache/2.4.29 (Ubuntu) Server at vm_ip Port – Pooja s p Mar 05 '21 at 03:34

1 Answers1

0

Steps for running laravel project without executing artisan command

  1. Need to install laravel framework on /var/www/html/laravel

  2. Change the index.php file to

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

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

  3. Edit server.php

    if ($uri !== '/' && file_exists(DIR.'/public'.uri)) { return false; }

    require_once DIR.'/index.php';

  4. Create laravel.conf file in /etc/apache2/sites-available/

    Listen 8000

    <VirtualHost *:80>

    ServerName ip_of_server

    ServerAdmin username@ipaddress

    DocumentRoot /var/www/html/laravel // specify the project location

    <Directory /var/www/html/laravel>

    Options Indexes MultiViews

    AllowOverride None

    Require all granted

    ErrorLog ${APACHE_LOG_DIR}/error.log

    CustomLog ${APACHE_LOG_DIR}/access.log combined

  1. Finally run the project

http://ip of the vm/index.php

Pooja s p
  • 9
  • 6