I have been working on a project that requires I set it up in Heroku. The Database I have been using thus far locally is mySQL, but I am looking to use Postgre when the project is on Heroku.
I have done a large amount of searching but have yet to find an answer as to how I configure my Laravel project to use Postgres and how do I perform basic functions such as adding a new database to Postgres.
If there is an alternative way to just use mySQL as is that would be great.
Thanks for the help.
Heroku places (once you provision a Heroku Postgres instance) the database credentials in the DATABASE_URL environment variable, in the following format:
postgres://username:password#hostname:port/database
Now, you could manually fill out your DB_HOST, DB_USERNAME, etc. .env vars from this, but there's a better way: you can parse the URL in your config/database.php file.
Note: Newer versions of Laravel now support a DATABASE_URL .env value directly. No need to parse anymore.
'pgsql' => [
'driver' => 'pgsql',
'host' => parse_url(env('DATABASE_URL'), PHP_URL_HOST),
'port' => parse_url(env('DATABASE_URL'), PHP_URL_PORT),
'database' => ltrim(parse_url(env('DATABASE_URL'), PHP_URL_PATH), '/'),
'username' => parse_url(env('DATABASE_URL'), PHP_URL_USER),
'password' => parse_url(env('DATABASE_URL'), PHP_URL_PASS),
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
'sslmode' => 'prefer',
],
(Make sure you set DB_CONNECTION to pgsql so this connection is used!)
how do I perform basic functions such as adding a new database to Postgres
You don't. A Heroku Postgres instance comes with one database.
Related
I tried to install TYPO3 (8.7.7) on my Webserver (IIS) and I'd like to use my SQL Server instead of MySQL.
I found lots of instructions how to make this (on typo3.org and other websites) but none of these worked for me.
I found out, that I must install two extensions before I start the installation (ADOdb & DBAL). Probably there is my fault.
Can anybody explain step by step how to install these extensions before the TYPO3 installation?
I'm using the following configuration to successfully run TYPO3 on SQL Server on my local windows machine:
'DB' => [
'Connections' => [
'Default' => [
'charset' => 'utf-8',
'dbname' => 't3',
'driver' => 'sqlsrv',
'host' => 'localhost',
'password' => 'yourPassword',
'port' => 1433,
'user' => 'sa',
],
],
],
It's a bit complicated to set up with the installer as it is not yet "clickable". What you can do is call the install script and when it's asking you to configure the database connection you go to your file system and manually add the config section above (with your connection params of course) in the LocalConfiguration.php file.
Then reload the installer - which should now recognize the configured database connection and let you go to the last step where you can import / create the base tables and data.
Note: At the moment I know of two bigger areas where SQL Server is still a problem with TYPO3 8.7 - that's workspaces and database compare. The last one means that after you have existing data in your SQL Server tables won't let you alter them via the TYPO3 database compare tool - you have to change tables manually if you need to.
Find a gist of the table create statements on https://gist.github.com/psychomieze/9570ea1f578aee7a1fbb68c3240a21c8
With 8.7, Doctrine DBAL has been integrated into the core and ADOdb & DBAL sysexts have been removed as there is no need anymore.
Take a look at the documentation of Doctrine DBAL http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html and it should fit perfectly to the configuration of the DB in `LocalConfiguration.php``
'DB' => [
'Connections' => [
'Default' => [
'charset' => 'utf8',
'dbname' => 'typo3',
'driver' => 'mysqli',
'host' => 'mysql',
'password' => 'dev',
'port' => 3306,
'user' => 'root',
],
],
],
Now my Typo3 is working.
I solved my problem a little bit complicated.
I made a test environment and installed Typo3 with MySQL.
Then I copied the database with the "Microsoft SQL Server Migration Assistant 7.6 for MySQL"
(https://www.microsoft.com/en-us/download/details.aspx?id=54257) to my main environment.
After that I copied all the created folders (typo3conf, typo3temp etc.) to my main environment
and edited the databaseconnection in the LocalConfiguration.php file like Georg Ringer proposed.
When I am installing Typo3 and MSSQL next time I will do it like susi proposed.
Thanks for your help.
I have installed cakephp 2.7.5 on xampp but when I run my application I get an error message >CakePHP is NOT able to connect to the database.
Database connection "Mysql" is missing, or could not be created.< I suspect that my mysql server is not properly configured and I have particular concerns over the PDO and pdo_mysql settings in the php.ini file. How do I enable them? (I am totally lost here)Thanks in advance.
You don't mention configuring the connection, so your problem is most probably that of a missing initial database configuration.
You will obviously need to create a database (and maybe a user with sufficient permissions in that DB) before you setup the configuration. Don't mess with PDO configuration in php.ini, it should run out of the box with XAMPP.
Rename file name from database.php.default to database.php .Create a database in mysql. Open the file and change your mysql login,password and database from default variable.Then run your application.
public $default = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'user',
'password' => 'password',
'database' => 'database_name',
'prefix' => '',
//'encoding' => 'utf8',
);
I'm trying to connect to my mssql database with laravel 5 but it's not working. I've tried to connect with different mssql databases so it's not a firewall issue. Also my credentials are correct. I found on google that you need SQL Server Native Client 11.0 and I've already installed that.
This is my connection array in config/database.php:
'sqlsrv' => [
'driver' => 'sqlsrv',
'host' => env('nvt'),
'database' => env('nvt'),
'username' => env('nvt'),
'password' => env('nvt'),
'charset' => 'utf8',
'prefix' => '',
],
And I've set the default to "sqlsrv" :
'default' => env('sqlsrv','sqlsrv'),
But when I'm trying to create a table I receive the error:
PDOException in Connector.php line 50: could not find driver
What could be wrong???
EDIT:
I've installed pdo for sqlsrv from here:
http://msdn.microsoft.com/en-us/sqlserver/ff657782.aspx
And I added it to my php.ini file:
extension=\Installaties\php_pdo_sqlsrv_53_nts.dll
But stil I receive the error?
Try to remove the eve() method, i mean use the following method
'sqlsrv' => [
'driver' => 'sqlsrv',
'host' => 'nvt',
'database' => 'nvt',
'username' => 'nvt',
'password' => 'nvt',
'charset' => 'utf8',
'prefix' => '',
],
I ran into a similar issue. Try putting in the server info directly rather than using env. If it works, then you know Laravel is having an issue reading the .env file.
I encountered your problem the last time I tried my connection in sqlsrv. I am using xampp. Try putting yung php_pdo_sqlsrv_53_nts.dll in the ext folder, replace extension=\Installaties\php_pdo_sqlsrv_53_nts.dll with extension=php_pdo_sqlsrv_53_nts.dll and try installing odbc 11 on your computer. It worked for me but not sure why. (not an expert) if it worked good to help a fellow person and if not, sorry for the trouble. Thank you for the time reading.
You may try any of the following solutions
Check that you have entered the right connection parameters. Test by connecting to the DB with a client tool.
Make sure you have the right version of sqlsrv configured for your machine. Check the PHP logs to be sure your web server was able to load the extension correctly.
Set the port to null in your env file
As a tip, I won't advise anyone to set the connection parameters anywhere but in the .env (Setting it in config/database is a security risk).
they are all configured identically.
the environment is definitely set to production.
the database credentials do not get read at all - it wants to use ''#localhost password: NO as the default.
i set
'mysql' => array(
'driver' => 'mysql',
'host' => getenv('DB_HOST'),
'database' => getenv('DB_NAME'),
'username' => getenv('DB_USERNAME'),
'password' => getenv('DB_PASSWORD'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
in all 4 of the sites app/config/database.php, and i set the related environment variables in forge. i have tried leaving the environment field blank, and also typing in 'production'. i also tried using $_ENV['environmentvariable'] in database.php.
this gives me a different error of Undefined Index DB_HOST. so clearly the env vars aren't getting read.
i've taken everything down and re-created the repo and the laravel server many times. all 3 other sites are configured identically. it detects the environment in bootstrap/start with
$env = $app->detectEnvironment(function()
{
return getenv('ENV') ?: 'development';
});
i appreciate any help guys. it works fine on homestead btw.
edit: i can ssh into forge and do whatever i want in any of the sites or databases as well, except in the problem one any php artisan command fails with the 'Access Denied for ''#localhost password: NO', even if i run it with --env="production".
I am not entirely sure if you are using .env files at root to specify different environment vars, but after going through this myself I realized that while when environment is 'local' it reads '.env.local.php', when environment is 'production', it wants '.env.php'.
It's in the docs, but I forget almost every time. I'm hoping that typing this out will help. :)
I have added DB credentials as environment variables (using nginx), so that i can use them like so:
return array(
'connections' => array(
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => getenv('DB_NAME'),
'username' => getenv('DB_USER'),
'password' => getenv('DB_PASS'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
)
)
);
The problem is that when I use artisan the environment variables do not seem to be available, so when i run migrate or seed i get errors.
Is there a way around that or should i just write my DB credentials directly in my config file ?
To edit my previous answer (sorry for misunderstandig):
Yes, environment variables are created by server, so they can't be reached or modified from CLI. Before deploying, server is generating those variables, so they can be "injected" into application at runtime.
I am thinking that it is maybe possible to reach those variables through remote Laravel package and SSH ? For example php artisan tail command is reading locally errors from the server side.