让 Laravel 5 与 xampp 一起工作 OSX
Get Laravel 5 working with xampp for OSX
我已经在 this tutorial for installing Laravel 4 之后安装了 Laravel 5,并在 localhost:8888
上建立了一个测试站点,并使用 PHP 的内置服务器作为该教程在 5:05.
中进行了解释
我想实现类似的目的,但通过 xampp 以 http://localhost/laravel
或类似的方式为网站提供服务。我这样做的原因是我在 xampp 中设置了许多其他项目和数据库,现在我想保持我的开发环境一致。
我是运行OSX小牛PHP版本5.4.30,我的编辑器是Coda 2。我在[=45=中创建了一个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}
有谁知道如何解决这个问题?
谢谢
段
我在 Stack Overflow 的其他地方找到 this answer 解决了我的问题。我所要做的就是将 unix_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,
],
而且效果很好。
我已经在 this tutorial for installing Laravel 4 之后安装了 Laravel 5,并在 localhost:8888
上建立了一个测试站点,并使用 PHP 的内置服务器作为该教程在 5:05.
我想实现类似的目的,但通过 xampp 以 http://localhost/laravel
或类似的方式为网站提供服务。我这样做的原因是我在 xampp 中设置了许多其他项目和数据库,现在我想保持我的开发环境一致。
我是运行OSX小牛PHP版本5.4.30,我的编辑器是Coda 2。我在[=45=中创建了一个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}
有谁知道如何解决这个问题?
谢谢
段
我在 Stack Overflow 的其他地方找到 this answer 解决了我的问题。我所要做的就是将 unix_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,
],
而且效果很好。