double2022 2015-01-20 21:39
浏览 43

Laravel Homestead:共享主机的数据库中不会发生迁移

I have created a project using Laravel Homestead PHP and it is running fine within my development environment locally. Now I want to deploy my Laravel PHP app to a shared host on HostGator.

I have created a new database within my HostGator account and now I wish to upload data onto this live database.

So far I've tried editing the file database.php within my project's config folder using the live database host's information. However when I try running migrations, database tables are not created within my live database.

Here is my project's database.php file:

'mysql' => array(
        'driver'    => 'mysql',
        'host'      => 'MY_HOSTGATOR_IP_ADDRESS',
        'database'  => 'MY_DATABASE_NAME',
        'username'  => 'DATABASE_USERNAME',
        'password'  => 'DATABASE_USERNAME_PASSWORD',
        'charset'   => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix'    => '',
    ),

Is there another file I need to edit within my Laravel Homestead project that will establish a connection to my live database?

Any help is greatly appreciated!

  • 写回答

1条回答 默认 最新

  • duanqiao9541 2015-01-20 21:56
    关注

    There's a number of places where you can define your database connections. By default, you'll define them here:

    app/config/database.php
    

    Notice also, that your Laravel Installation has this folder:

    app/config/local/database.php
    

    Whenever I migrate a project to a live server, I add the following folder and files into Laravel:

    app/config/production/app.php
    app/config/production/database.php 
    

    The changes you make in this folder (including any database connections in database.php will be the settings used by Laravel when you're in your production environment. To check the current environment, use:

    php artisan env
    

    It should say production by default, unless you've changed these settings in bootstrap/start.php:

    $env = $app->detectEnvironment(array(
      'local' => array('local_computer_name'),
      'production' => array('server_name') 
    ));
    

    For example, my local Virtual Box has a name of timpc, so setting 'local' => array('timpc') would cause php artisan env to echo "Local".

    Hopefully that helped, here's the TL:DR

    • Create a folder in app/config called production
    • Create the files app.php and database.php and modify them as needed for your production environment.
    • Make sure you have the setting in bootstrap/start.php that applies your server's name to the Production environment.

    That should solve the issue you are facing. If not, there's is something else wrong. Quick questions, have you pushed the Laravel Project to HostGator using Git or something similar? I assume you have, and you're using HostGator's CLI to call php artisan migrate, but if not, that would be the issue.

    Cheers!

    评论

报告相同问题?

悬赏问题

  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制