mysql 远程连接_Centos7下无法远程连接mysql数据库的原因与解决

第一步:添加apphttpControllers文件夹里面创建我们要存放前端和后端或者接口的文件夹

列如: Home(前端)  Admin(后端)   App(接口)  文件夹

36c53269c3f09be5f1fc15f65230c05c.png

第二步:修改apphttpprovidersRouteServiceProvider.php

  1. <?php
  2. namespace AppProviders;
  3. use IlluminateSupportFacadesRoute;
  4. use IlluminateFoundationSupportProvidersRouteServiceProvider as ServiceProvider;
  5. class RouteServiceProvider extends ServiceProvider
  6. {
  7. /**
  8. * This namespace is applied to your controller routes.
  9. *
  10. * In addition, it is set as the URL generator's root namespace.
  11. *
  12. * @var string
  13. */
  14. protected $namespace = 'AppHttpControllers';
  15. protected $homeNamespace = 'AppHttpControllersHome';//PC端
  16. protected $adminNamespace = 'AppHttpControllersAdmin';//管理后台
  17. /**
  18. * Define your route model bindings, pattern filters, etc.
  19. *
  20. * @return void
  21. */
  22. public function boot()
  23. {
  24. //
  25. parent::boot();
  26. }
  27. /**
  28. * Define the routes for the application.
  29. *
  30. * @return void
  31. */
  32. public function map()
  33. {
  34. //$this->mapApiRoutes();
  35. //$this->mapWebRoutes();
  36. $sld_prefix = explode('.',$_SERVER['HTTP_HOST'])[0];
  37. if(config('route.admin_url') == $sld_prefix){
  38. $this->mapAdminRoutes();
  39. }elseif(config('route.home_url') == $sld_prefix){
  40. $this->mapHomeRoutes();
  41. }elseif(config('route.api_url') == $sld_prefix){
  42. $this->mapApiRoutes();
  43. }
  44. }
  45. /**
  46. * Define the "web" routes for the application.
  47. *
  48. * These routes all receive session state, CSRF protection, etc.
  49. *
  50. * @return void
  51. */
  52. protected function mapWebRoutes()
  53. {
  54. Route::middleware('web')
  55. ->namespace($this->namespace)
  56. ->group(base_path('routes/web.php'));
  57. }
  58. /**
  59. * Define the "api" routes for the application.
  60. *
  61. * These routes are typically stateless.
  62. *
  63. * @return void
  64. */
  65. protected function mapApiRoutes()
  66. {
  67. Route::prefix('api')
  68. ->middleware('api')
  69. ->namespace($this->namespace)
  70. ->group(base_path('routes/api.php'));
  71. }
  72. /**
  73. * 管理后台
  74. */
  75. protected function mapAdminRoutes()
  76. {
  77. Route::middleware('web')
  78. ->namespace($this->adminNamespace)
  79. ->group(base_path('routes/admin.php'));
  80. }
  81. /**
  82. * PC端
  83. */
  84. protected function mapHomeRoutes()
  85. {
  86. Route::middleware('web')
  87. ->namespace($this->homeNamespace)
  88. ->group(base_path('routes/home.php'));
  89. }
  90. }

第三步:在config下创建文件route.php,并在里面添加:

  1. <?php
  2. return array(
  3. 'admin_url'=>'admin',
  4. 'home_url'=>'www',
  5. 'api_url'=>'api'
  6. );

第四步:在routes目录下创建admin.php 和home.php 路由

67303080fbe7c8a151a0a6335f51e7e9.png

第五步:分别在appHttpControllersAdmin和appHttpControllersHome

  1. <?php
  2. namespace AppHttpControllersAdmin;
  3. use AppHttpControllersController;
  4. class AdminController extends Controller
  5. {
  6. public function index()
  7. {
  8. echo "this is admin";
  9. }
  10. }
  1. <?php
  2. namespace AppHttpControllersHome;
  3. use AppHttpControllersController;
  4. class HomeController extends Controller
  5. {
  6. public function index()
  7. {
  8. echo "this is home";
  9. }
  10. }

第六步:分别在admin.php 和home.php 新建路由

  1. Route::get('/', 'AdminController@index');
  2. 2.Route::get('/','HomeController@index');

第七步:添加nginx配置日志

  1. server {
  2. listen 80;
  3. listen 443 ssl;
  4. server_name

The PHP Framework For Web Artisans

admin.laravel.com;

  1. charset utf-8;
  2. #access_log logs/www.polypm.com.cn.access.log main;
  3. root /data/webroot/http://kangsf.com.cn/public;
  4. index index.html index.php;
  5. ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  6. ssl_certificate ssl/cert.pem;
  7. ssl_certificate_key ssl/cert.key;
  8. location / {
  9. try_files $uri $uri/ /index.php?$args;
  10. }
  11. # redirect server error pages to the static page /50x.html
  12. #
  13. #error_page 500 502 503 504 /50x.html;
  14. #location = /50x.html {
  15. # root html;
  16. #}
  17. # proxy the PHP scripts to Apache listening on 127.0.0.1:80
  18. #
  19. #location ~ .php$ {
  20. # proxy_pass http://127.0.0.1;
  21. #}
  22. # pass the PHP scripts to FastCGI server listening on 127.0.0.1:5443
  23. #
  24. location ~ .php$ {
  25. fastcgi_pass 127.0.0.1:7113;
  26. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  27. include fastcgi_params;
  28. }
  29. # deny access to .htaccess files, if Apache's document root
  30. # concurs with nginx's one
  31. #
  32. #location ~ /.ht {
  33. # deny all;
  34. #}
  35. }

第八步:测试

3f0157105a3143ac1f1d457d625a563e.png

bdc44683ab3ae2de7710f646922e496c.png

读者福利,可直接点击链接领取相关学习福利包:

石墨文档

石墨文档-远程办公系统/解决方案_多人协同办公软件_远程在线办公/协作工具​shimo.im
2dd15bb6b8b131e2d9e662af45a82897.png

是安全网站放心,继续访问就可以领取了哦

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值