I'm trying to create a file upload where admin would upload file from admin application to another application for regular users (they are on different domains).
I got it working with FTP filesystem but I would like to test it on localhost, before I fully deploy it.
I made a config entry in filesystem.php:
'ftp' => [
'driver' => 'ftp',
'host' => env('FTP_HOST'),
'username' => env('FTP_USERNAME'),
'password' => env('FTP_PASSWORD'),
'root' => '',
'port' => 21,
'timeout' => 30,
'ssl' => true,
]
And on my test function in admin_app I do this:
Storage::disk('ftp')->put('/public_app/storage/test3.png', $file);
I have to separate laravel applications: admin_app and public_app. How could I test the same thing on localhost? Another config entry point or do I need to download FTP for localhost?
What about using something like remote server that contain your assets?
For example use S3 and upload all your files there and access it from your second app or any other app.
Check this Article
I am trying to change the Laravel configuration variables based on environment, but I do not know how.
Code to get config is
Config::get( 'contants.api_url' );
I am trying to have a separate results for the live environment and the development environment.
Real life scenario
I need to override some config files, so everybody who is using the development environment, has the same base configuration. I cannot use the .env file for this, because it is not shared between the team and everybody has their own version of it.
What did I try:
I read here Laravel 5 configuration - environments and overriding that you can create subfolders within your /config folder, that match the environment, to override the default config files. Alas it did not work for me and the Laravel 5.4 documentation on the subject matter (https://laravel.com/docs/5.4/configuration#retrieving-environment-configuration) did not speak about this option, thus I believe it might have been deprecated.
One option could be to use a service provider. If you're only going to be overriding one or two values then you might as well just use your AppServiceProvider, otherwise I would suggest creating a new service (e.g. ConfigServiceProvider).
In the boot() method of your service provider you could add something like:
if (app()->environment() === 'local') {
config()->set('contants.api_url', 'http://example.com');
}
To change the configuration variables based on environment, this will do:
Example file: config/database.php
'mysql' => [
'driver' => mysql,
'url' => env('DATABASE_URL'),
'host'=> (env('APP_ENV') === 'local' ? env('DB_HOST_LOCAL') : env('DB_HOST_PRODUCTION')),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'default'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', ''),
'options' => (env('APP_ENV') === 'local' ? [
'some_option' => env('SOME_ENV')
] : []),
],
Tested and works on Laravel 5.8.
I have a Heroku app where I'm hosting my Laravel app. I started the development initially with MySQL, so I wanted to continue doing so using Amazon's RDS service. I create the instance there and managed to successfully connect via my MySQL client, the console etc.
The problem is that the Laravel app can't connect the database after numerous desperate attempts for me to fix it. I have found some articles suggesting the use of DATABASE_URL environment variable is mandatory, so I added it via the Heroku app settings. It looks like so:
mysql://myusername:mypass#myhostnamefromamazon/mydb?sslca=/app/storage/certs/amazon-rds-ca-cert.pem
I found this solution on Heroku's website. I have placed the amazon-rds-ca-cert.pem file on my Laravel's storage folder, like so: /app/storage/certs/amazon-rds-ca-cert.pem
This didn't solve my issue, so then I kept looking and found a Stackoverflow question which had this issue on Lumen. I adjusted my config/database.php according to the answer, but it's still not working for me!
<?php
$credentials = get_db_credentials();
$config = [
'default' => env('DB_CONNECTION', 'mysql'),
'connections' => [
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', $credentials->host),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', $credentials->database),
'username' => env('DB_USERNAME', $credentials->username),
'password' => env('DB_PASSWORD', $credentials->password),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
],
];
if (env('APP_ENV') == 'production') {
$config['connections']['mysql']['options'] = [PDO::MYSQL_ATTR_SSL_CA => '../storage/certs/amazon-rds-ca-cert.pem'];
}
return $config;
The get_db_credentials() function simply parses the DATABASE_URL environment variable.
The exact exception that I get is:
[2018-10-25 19:32:16] production.ERROR: SQLSTATE[HY000] [2002] Connection timed out {"exception":"[object] (Doctrine\\DBAL\\Driver\\PDOException(code: 2002): SQLSTATE[HY000] [2002] Connection timed out at /tmp/build_05920c42a6de0a378402b798320d3f04/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:50
I'm totally lost on this and unsure how to proceed.
Your AWS Security Groups must permit traffic from Heroku's IP address range.
https://devcenter.heroku.com/articles/amazon-rds
You must grant Heroku dynos access to your RDS instance. The recommended way to do this is to configure the RDS instance to only accept SSL-encrypted connections from authorized users and configure the security group for your instance to permit ingress from all IPs, eg 0.0.0.0/0.
Following this Setup Laravel 5 Application without command-line access
I have a question about second criteria.
I'm using free hosting and I have the "htdocs" folder that is basically my "public_html"(I think so), because the displayed "index.html" file that comes by default is in it. So, following the second criteria from the above topic, I need to change the "htdocs" for "laravel_folder/public", correct? If so, how can I do this by .htaccess, please?
I just deployed a Laravel 5.7 app on 000webhost which is free hosting website.
First of all, you have to generate a key for your app and erase the cache.
Use the command: php artisan key: generate
Then php artisan config: clear
and finally php artisan cache: clear.
Now you take the folder / root directory or where you have your app, you have to compress it in a zip file.
Create a new folder in the root of the File Manager, for example a folder called App.
Upload the zip file to the App directory on https://files.000webhost.com/ by clicking on the "Upload Files" button on top right.
When it's done, you have to click on the zip file and select "Extract". Also make sure to write "." to extract the contents directly into App.
Make sure all the files are in App just like that.
Move all the files in the public folder (App/public) to the public_html folder.
Now that we have everything, we are going to configure what is necessary.
A previous step is to create a new database for them you will have to go to the section "Manage databases" and create one. Then manage the base in phpmyadmin and import the database of your project / application.
Once this step is completed, the following is:
1.-Configure index.php, in the directory public_html/index.php, you must add the App folder to the addresses of autoload.php and app.php.
Change require __DIR__.'/../vendor/autoload.php';
by require __DIR__.'/../App/vendor/autoload.php';
Change $app = require_once __DIR__.'/../bootstrap/app.php';
by $app = require_once __DIR__.'/../App/bootstrap/app.php';
Below this line add the following
$app->bind('path.public', function() {
return base_path().'/public_html';
});
2.- Go to the .env file and modify the host, the database, the user and the password with the values of the database that we made in the previous step. Copy the APP_KEY also, we will use it later.
3.- In config/app.php, find the line : 'debug' => env('APP_DEBUG', false),
and change the value to true :
'debug' => env('APP_DEBUG', true),
find tehe line: 'key' => env('APP_KEY'),
and add a comma followed by base64_decode ('copy the key that was in the .env file here').
For example:
'key' => env('APP_KEY',base64_decode('AsAAAAA+AWERSDFT4Y123Ywpj123PNaleLdPwcd0000=')),
4.- In the same directory but in the database.php file (config/database.php),
find:
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
Add this line after host: 'options' => [PDO::ATTR_EMULATE_PREPARES => true,],
Modify the host, database, user, and password with the values in the database as in step 1.
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'options' => [PDO::ATTR_EMULATE_PREPARES => true,],
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'databaseNamehere'),
'username' => env('DB_USERNAME', 'userNamehere'),
'password' => env('DB_PASSWORD', 'passwordHere'),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
Now we can go to the address of the server and you can see your app running correctly.
I hope it helps you, greetings.
No, there you need to copy all the files inside the public folder (~/MyAwesomeProject/public/) into the public_html folder (~/public_html).
This blog article will help you to deploy Laravel project on Shared Hosting Server Using cPanel Options:
Laravel: Deploy Laravel Projects On Shared Hosting
From memory of working on shared hosting this is going to be difficult. What you could do, assuming FTP access, is upload everything to your root level, and then in the Laravel configurations you can change the name of your public directory, so to htdocs
Though I think you might struggle with some of Laravels features without having command line access
I'm assuming you're developing for a production environment, if so you can get a cheap VPS or Droplet where you could effectively utilise Laravel alternatively VirtualBox or something for development would work well
Laravel quite heavily relies on Artisan (their Cli interface) as well as various tools within there (such as Migrate which works with Eloquent to deploy tables) so I think you might struggling using this on a shared box.
The reason for all of this reliance is because Laravel was built for Enterprise usage, where generally shared boxes aren't utilised.
I think there are some hosts out there who will give you command line access, however.
If you need to use a different MVC framework without having command line access CodeIgniter is a good one
I just deployed a Laravel app on 000webhost which is free hosting website. I faced some problems, but here's how I solved them:
1- Go to your app's root directory (where app, public, resources and other directories exist) and zip them all into a one zip file (it is important for it to be zip not rar).
2- Upload the zip file to the public_html directory on https://files.000webhost.com/ by clicking on the "Upload Files" button on top right.
3- It will take some time to upload. When it's done, you have to click on the zip file and select "Extract". Also make sure to write "." to extract the contents directly into public_html.
4- Now if you go to the URL 000webhost provides for your site, let's call it $url, then add /public to it which is where your entry point index.php file resides, you'd suppose to see the homepage of your site: $url/public . But you won't.
5- For some reason I didn't understand, the .env file which is a shortcut of your config files in the config directory could not be read. So, you'll have to update your config files, mainly config/app.php and config/database.php.
6- The first problem you'll have is the key issue. In config/app.php, find the line :
'key' => env('APP_KEY'),
and replace env('APP_KEY') with the actual key that you see in you .env file (in case it is empty for you, you'll have to generate a key by sending the command on your computer php artisan key:generate)
7- If you are using a database (such as MySQL), then you'll have to also go to config/database.php and replace all values of env with actual values, mainly these values :
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
P.S: there should be NO env variable whatsoever. Remove all envvariables that you don't use and replace the rest with real values.
I couldn't figure out a way to do virtual host for the free version (maybe you can configure a vhost for the paid version..). So, you'll have to remember that the url provided by 000webhost should be appended by /public (I say this again because you might have to change your navbar links as well by applying this logic).
And voila! It should work now. Well, in case you face any more issues, there's 2 things you can really do to figure them out:
1- In config/app.php, change the debug value from false to true to see the errors instead of a "whoops" message :
'debug' => env('APP_DEBUG', true),
2- You can check the storage/logs/laravel.log file to see the errors you are getting.
Good luck!
I'm getting this error when trying to connect to an SQL Server DB from Laravel 4.2.
Here's my DB config:
'connections' => array(
'sqlsrv' => array(
'driver' => 'sqlsrv',
'host' => 'example.noip.me',
'database' => 'db',
'username' => 'sa',
'password' => 'pass',
'prefix' => '',
),
),
//...
It works perfectly in my home computer, but not in production. This project is in a hosting service, so I can't change much of the config (can still use ini_set though).
I tried adding the port to the server address but it didn't work.
Edit: I forgot to mention that the hosting and the database server are on different computers, so it could be a security configuration problem.
I contacted tech support and it turned out to be a matter of configuration in the hosting server (Remote Database Access Hosts, which I thought was for MySQL only).