Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 让Laravel 5为OSX使用xampp_Php_Mysql_Laravel_Xampp_Laravel 5 - Fatal编程技术网

Php 让Laravel 5为OSX使用xampp

Php 让Laravel 5为OSX使用xampp,php,mysql,laravel,xampp,laravel-5,Php,Mysql,Laravel,Xampp,Laravel 5,我已经安装了Laravel 5,并在localhost:8888上运行了一个测试站点,使用PHP的内置服务器,如5:05教程所述 我想实现一个类似的功能,但是通过根为xampp的站点提供服务http://localhost/laravel或类似内容。我这样做的原因是我在xampp中设置了许多其他项目和数据库,现在我希望保持我的开发环境的一致性 我用PHP版本5.4.30运行OSX Mavericks,我的编辑器是Coda 2。我已经在xampp中创建了一个MySQL数据库,并将必要的详细信息添加

我已经安装了Laravel 5,并在
localhost:8888
上运行了一个测试站点,使用PHP的内置服务器,如5:05教程所述

我想实现一个类似的功能,但是通过根为
xampp的站点提供服务http://localhost/laravel
或类似内容。我这样做的原因是我在xampp中设置了许多其他项目和数据库,现在我希望保持我的开发环境的一致性

我用PHP版本5.4.30运行OSX Mavericks,我的编辑器是Coda 2。我已经在xampp中创建了一个MySQL数据库,并将必要的详细信息添加到我的项目
.env
文件中,但无法显示该网站

更新:显然,我所要做的就是在xampp上重新启动服务器,并将
/public
添加到我的根url末尾以查看该站点。然而,现在我面临着另一个问题。当我尝试迁移数据库时

php artisan migrate
我没有收到任何效果,但是下面的消息突然出现了

exception 'PDOException' with message 'SQLSTATE[HY000] [2002] No such file or directory' in /Applications/XAMPP/xamppfiles/htdocs/laravel-test/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:47
Stack trace:
#0 /Applications/XAMPP/xamppfiles/htdocs/laravel-test/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php(47): PDO->__construct('mysql:host=loca...', 'laravel-user', 'YdVNRS5fDbJMLh6...', Array)
#1 /Applications/XAMPP/xamppfiles/htdocs/laravel-test/vendor/laravel/framework/src/Illuminate/Database/Connectors/MySqlConnector.php(20): Illuminate\Database\Connectors\Connector->createConnection('mysql:host=loca...', Array, Array)
#2 /Applications/XAMPP/xamppfiles/htdocs/laravel-test/storage/framework/compiled.php(10598): Illuminate\Database\Connectors\MySqlConnector->connect(Array)
#3 /Applications/XAMPP/xamppfiles/htdocs/laravel-test/storage/framework/compiled.php(10594): Illuminate\Database\Connectors\ConnectionFactory->createSingleConnection(Array)
#4 /Applications/XAMPP/xamppfiles/htdocs/laravel-test/storage/framework/compiled.php(10512): Illuminate\Database\Connectors\ConnectionFactory->make(Array, 'mysql')
#5 /Applications/XAMPP/xamppfiles/htdocs/laravel-test/storage/framework/compiled.php(10467): Illuminate\Database\DatabaseManager->makeConnection('mysql')
#6 /Applications/XAMPP/xamppfiles/htdocs/laravel-test/vendor/laravel/framework/src/Illuminate/Database/Migrations/DatabaseMigrationRepository.php(167): Illuminate\Database\DatabaseManager->connection(NULL)
#7 /Applications/XAMPP/xamppfiles/htdocs/laravel-test/vendor/laravel/framework/src/Illuminate/Database/Migrations/DatabaseMigrationRepository.php(135): Illuminate\Database\Migrations\DatabaseMigrationRepository->getConnection()
#8 /Applications/XAMPP/xamppfiles/htdocs/laravel-test/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php(371): Illuminate\Database\Migrations\DatabaseMigrationRepository->repositoryExists()
#9 /Applications/XAMPP/xamppfiles/htdocs/laravel-test/vendor/laravel/framework/src/Illuminate/Database/Console/Migrations/MigrateCommand.php(101): Illuminate\Database\Migrations\Migrator->repositoryExists()
#10 /Applications/XAMPP/xamppfiles/htdocs/laravel-test/vendor/laravel/framework/src/Illuminate/Database/Console/Migrations/MigrateCommand.php(54): Illuminate\Database\Console\Migrations\MigrateCommand->prepareDatabase()
#11 [internal function]: Illuminate\Database\Console\Migrations\MigrateCommand->fire()
#12 /Applications/XAMPP/xamppfiles/htdocs/laravel-test/storage/framework/compiled.php(922): call_user_func_array(Array, Array)
#13 /Applications/XAMPP/xamppfiles/htdocs/laravel-test/vendor/laravel/framework/src/Illuminate/Console/Command.php(115): Illuminate\Container\Container->call(Array)
#14 /Applications/XAMPP/xamppfiles/htdocs/laravel-test/vendor/symfony/console/Symfony/Component/Console/Command/Command.php(253): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#15 /Applications/XAMPP/xamppfiles/htdocs/laravel-test/vendor/laravel/framework/src/Illuminate/Console/Command.php(101): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#16 /Applications/XAMPP/xamppfiles/htdocs/laravel-test/vendor/symfony/console/Symfony/Component/Console/Application.php(874): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#17 /Applications/XAMPP/xamppfiles/htdocs/laravel-test/vendor/symfony/console/Symfony/Component/Console/Application.php(195): Symfony\Component\Console\Application->doRunCommand(Object(Illuminate\Database\Console\Migrations\MigrateCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#18 /Applications/XAMPP/xamppfiles/htdocs/laravel-test/vendor/symfony/console/Symfony/Component/Console/Application.php(126): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#19 /Applications/XAMPP/xamppfiles/htdocs/laravel-test/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(91): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#20 /Applications/XAMPP/xamppfiles/htdocs/laravel-test/artisan(36): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#21 {main}
有人知道如何解决这个问题吗

谢谢

Dan

我在堆栈溢出的其他地方找到了解决问题的方法。我所要做的就是将
unix\u socket
行添加到我的
database.php
文件的mysql部分

'mysql' => [
        'driver'    => 'mysql',
        'unix_socket'   => '/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock',
        'host'      => env('DB_HOST', 'localhost'),
        'database'  => env('DB_DATABASE', 'forge'),
        'username'  => env('DB_USERNAME', 'forge'),
        'password'  => env('DB_PASSWORD', ''),
        'charset'   => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix'    => '',
        'strict'    => false,
    ],

而且效果很好。

你在找这样的东西吗@MalteKöhrer感谢您的链接,这很有帮助。我刚刚使用了错误的路径,但是我仍然无法使数据库连接正常工作。我在问题中添加了更多细节。太棒了。CentOS上的/opt目录下的XAMPP也存在类似问题。添加行
'unix_socket'=>'/opt/lampp/var/mysql/mysql.sock'
,事情看起来很好。谢谢