How can seeding data in production server - Laravel 5.2? - php

I have made a db seeder. And used command for data seed:
php artisan db:seed --class=UsersTableSeeder
Its perfectly working in localhost. Now i want to generate demo data into production server. Is there any way how i run this artisan command? Or tell me how can i load demo data into database table. Thanks in advance.

When you run the php artisan db:seed --class=UsersTableSeeder command on localhost your doing that in your terminal / console right?
You have to find your console on your web server and run the command from there. When your using a dedicated or VPS server this should be easy. When you have shared hosting it can be a little tricky, so you might need to contact your host to ask if something is possible.
So step by step:
Go to the terminal from your server
Navigate to your laravel project
Run the command
EDIT: You can also run the command on localhost and export the database. And than import it on your host. It's not the best option (And I recommend using the terminal!), but it works.

I am guessing that you are using a shared hosting server with som kind of ftp for file transferring. Because if you would have a terminal on your production server, you would've known how to execute commands on them.
If you do have a VPS or dedicated server, you can log in with SSH and execute the command just like you normally would. It could be possible that you get a warning to protect you from seeding in a production environment. But you could simply answer yes to continue seeding.

Related

laravel server not responding to requests unless restarting the CLI but works fine in www folder

I'm running a Laravel app with php artisan serve. When I start it from the CLI, it works the first time fine. But when refreshing the URL, it stops responding and the link becomes pending in a loop in Chrome's Inspect Network tab. Then when I close the CLI and reopen it again, it works fine again the first time, but still doesn't work when restarting the server only.
But when I run the app from the www folder in WAMP it works fine.
So what's the problem?
Is it with the env file?
If you are using the latest version for Laravel 5.X, you will see that sometimes the php artisan serve command doesn’t work properly. If you face this type of problem, you can use the below command and start your server locally.
So there is a different solution: you can use your php cli server command instead of the artisan command
php -S localhost:8000 -t public/
make sure that your PHP is in your global variables

Laravel 5 application moved from local machine to hosting server causing errors

I developed an application in laravel 5.0 in local machine using xampp and it's working fine. After i uploaded the project to hosting server using ftp now i am getting following errors one below the other.
The issue is you don't have right permission on project/storage/framework/sessions folder, so give the permission to 0777 i.e read write execute and after that run the following command:
php artisan config:cache
through terminal or putty on server and every thing will be fine.

How to solve the error "The localhost page isn’t working" in laravel

I am developing a web application in Laravel 5. I created the project in a local machine at my workplace and it runs just fine. But when i run the machine in another windows machine, it gives me an error The localhost page isn’t working with HTTP ERROR 500 as a server internal error.
I have also tried to look at the laravel.log file and found an exception Call to undefined function site_url() but don't know how to fix this.
Any idea on how to work around this is much appreciated.
This error is coming because you forgot to start laravel service.
If you wish to run your project on http://localhost:8000 Try with the following command :
php arisan serve
If you wish to choose specific port then try with the following command :
php artisan serve --port={port number}
Happy Coding :)
If you run local server by php artisan serve it will give url localhost:8000 by default and will run only in your machine to run in another machine of LAN you need to first find Local IP by ipconfig suppose you get this (192.168.2.10) then use this command.
`php artisan serve --host 192.168.2.10`
this will give url 192.168.2.10:8000 and can be access from any LAN connected machine.
In case none of this was working for you, there may be a more sinister explanation.
In our case, someone who shall go unnamed accidentally deleted the public/index.php file, and committed that to git! So taboo I didn't even think to look. This will stop ANYTHING in your site from running, including logging, but the server will go ahead, so there is nothing to go on, just a 500 error with no response or preview.
Again, seems ridiculous, but it was SO ridiculous who would even look for it?
please change your php version. you need to install php 7.2 version for laravel 5.6 version.

why should I keep running artisan serve command to keep the server working?

I'm learning laravel, and at the beginning I had run the command
php artisan serve
and keep my terminal window open so I can keep the server running, but later I wanted to just work with my app just like working on a normal php application so I created a virtual host directed to my laravel application "public" folder.
here is the problem:
I still have to run the "php artisan serve" and open my virtual server url
http://brk.localhost:8000
and then close the terminal, all that before I can normally open this link without defining the port number 8000.
and If I left my computer and get back to continue work, I found that I can't access it unless I do the whole process again.
and If I made a modification to any of the application views I get the same problem.
what am I missing?
Just add the and symbol '&' to the end of the command. This will keep it running in the background.
There are 3 main ways that you can access your Laravel app while you are developing it.
1) Using artisan serve
This method is probably the easiest method but it does mean that you have to remember to do this every time you start working on your project, which you have said that you do not want to do.
2) Using Laravel Homestead
This method requires a little more configuration but the documentation is very good. You won't have to remember to keep the terminal window open when you use it, but you'll still have to remember to keep the virtual machine running.
3) Set up LAMP / MAMP / WAMP or even LEMP
Setting up a local Apache or Nginx daemon on your own machine will require the most amount of configuration but it will mean that your web server automatically starts with your OS so whatever you put in your web directory will always be accessible through the web browser. You will not need to run and terminal commands or run a virtual machine.
Please note, however, that by using a local Apache/Nginx daemon you will be sacrificing a lot of flexibly and you will not have the luxury of deleting it all and starting again in a few minutes if you mess up the config.
Still, a lot of people still prefer to run their own Apache/Nginx daemon locally for development. I am one of them.
I encountered a similar situation where, if I were to save any modification to project files, I had to run "php artisan serve" and quit it before apache2 can serve the site.
I fixed it by modifying the file system permissions for my project.
I found this , which fixed the permission issue.
This solved the situation where I had to run php artisan serve, over and over again.
Primary cause of this is running package managers as sudo. Every file is created with bad permissions.

PHP socket server

I'm very new to socket programming, but do lot of coding with php.
I have tested some socket server example codes and worked fine with localhost. I use CLI to run the server. But my concern is how do I run the socket server .php file at my hosting server? Do hosting providers normally give access to CLI to run the servers? How do I make sure my server is always running? If the hosting server is restarted, what happens to my server? In case, my server crashes (whatever reason), do I have to run it manually?
Can someone help?
If you are talking about a hosting server I expect you are talking about shared hosting. In that case it will be difficult to keep it stable if you even manage to run the service etc. I would suggests using at least a VPS for it. That way you can run it in the background, automatically start it at reboot but also install software to check the process and restart it if it failed.
For example: Testing whether the reboot startup works is impossible at shared hosting.
I don't know if your provider give you ssh access. Some provider do it but this are managed server or root server.
Then you can run your script over the CLI.
When you can run your server over CLI and when you have enough rights you can insert the script to the runlevel. And there is something that is called "shebang". With this you can give your script direct the php interpreter and run the script without the php command before.
php test.php or /usr/bin/php testScript.php
You can run direct run your script with test.php or name your script only testScript.
When you put your script to /usr/local/bin (for debian) you can run it everytime over the command like the php command.
Edit: I have forgotten something. For this solution you have to copy the /etc/init.d/skeleton to /etc/init.d/runPHPSocketServer for example and change the script values on top. Then you can insert it to the runlevel.
#: testScript or runPHPSocketServer start
When the script is under a executable directory you can insert it to your system runlevel.
#: update-rc.d runPHPSocketServer defaults
So you see there are some solution but for the most solutions you need ssh access.

Categories