Multiple ports listening in laravel - php

I'm doing live chat server on my laravel development, I setup everything in Digital Ocean. Setup apache2 and phpmyadmin. However, when I tried to run the
"php artisan serve"(Default port:8000)
then open up my website with IP. The server commands didn't detect anything. Fine. I try my live chat server
"php artisan chat:serve --port=8887"
with different ports. But didn't work for me, it shows blank screen without errors. Suppose shows me live chat messeger interface on my website but blank. I know something deals to my apache2 server, but I have no idea how to deals with it.
By the way, I'm using emberJS chat server and follow-up this tutorial at here

php artisan serve is intended for local development, and as such, limits itself to the local network by default. Doing php artisan serve --host 0.0.0.0 will allow it to be accessible to the public internet.
Do note that php artisan serve should never be used to serve a production site. You should be serving the live site with Apache, not Artisan.

Related

Running php artisan server with LAN host not working

I'm trying to access my Laravel project APIs on my mobile phone. Since both my machine and mobile are under the same Wi-Fi, I'm trying to run the php artisan serve on my LAN like so.
php artisan serve --host=192.167.1.101
This runs fine and I do connect, but no API calls to the server go through. It doesn't even log a call.
This seems to work just fine when I use my mobile internet and hotspot my machine. But this is not convenient as my mobile internet is very limited.
I've boiled it down to be an issue with the LAN. But that's as far as my knowledge goes.
Is there anything I need to enable?
Thanks.
After months, I've finally found the solution. Turns out my Firewall was set to not trust my WiFi network (which I use for my LAN).
As soon as I added it to the trusted list, everything works!

Working Laravel in CPanel but not in localhost without Artisan

I've installed in my remote server, via Softaculous, Laravel 8.
In order to access directly to the APP, just like when running php artisan serve in my local machine, in CPanel i defined the document root to the folder Laravel\public.
Everything works exactly as it should! I type the address (ex: myDomain.com) and the App runs perfectly...
However i don't want to being always typing php artisan serve while developing, so i tried to replicate the cpanel struture in my local machine.
To achive thar, i've created a virtualhost in XAMPP httpd-vhosts.conf pointing to the folder Laravel\public, and created the host file in windows system, like always.
When accessing the location in my local machine the first page renders perfectly, but as soon as i make a request for a new view, by example:
Route::get('/posts', function () {
return view('posts.index');
});
I get a "Not Found The requested URL was not found on this server" error! I'm sure is not a coding error because the same code runs flawlessly in remote server.
Which technique is used by cpanel to allow laravel to work directly from \public folder without necessity to initiate anything and how to replicate that in local development machine?
Well...
After much reading, backs and forwards, i believe this behavior depends on the way Apache its served by XAMPP.
So, the solution i adopted was change my local development tool to LARAGON.
Everything worked just fine with a lot of new features that donĀ“t exist in XAMPP.

php artisan serve on local network

I'm working on a project in laravel and to test the site on mobile i have been running the following command:
php artisan serve --host 192.168.83.1 --port 8000
This used to work fine, and still does on my own laptop.
However it suddenly stopped working on my phone and i can't seem to figure out why.
Could their be changes i have made to my laptop that are blocking the route?
Or have i changed something in my project which does not allow for mobile devices?

Access to Laravel 5 app locally from an external device

I've looked for a solution in the web, but I've not found a solution yet.
I need to access to my Laravel 5 app from my iPhone, but I'm in develop, so I don't want to publish my app on a web server.
If you have a link to follow, that you assure it works, It's perfect for me.
Thank you!
If you're not bound to using Apache or nginx for some special reason and this is for development purposes only, you could serve the application using the PHP built-in server and artisan. It's by far the easiest thing to setup, and will only require you to run one command in the Laravel application directory:
php artisan serve --host 0.0.0.0
The default port it will be listening to will be 8000 to avoid any conflicts, so you can now access the application from your phone via the IP address of your computer:
http://192.168.1.101:8000
If you want to listen to another port (for example the default HTTP port of 80) you can pass that as a parameter, just make sure no other server is running on that port. So if you run this instead:
php artisan serve --host 0.0.0.0 --port 80
You can now access your application with just the IP address:
http://192.168.1.101
Its simple, first you have to run the server
php artisan serve --host 0.0.0.0
Then you need to know what`s your IP address, run this command to get IP:
In windows:
ipconfig
In Linux:
hostname -I
For example, my IP is: 192.168.1.68
Once you get your IP, then you have to go to this address on your mobile. Like:
192.168.1.68:8000
And that's it.
There are so many ways to do this.
Access your web via IP address from your iPhone, e.g. http://192.168.1.100/laravel
If your iPhone is jailbroken, you can edit iPhone's /etc/hosts file, the access your website via domain, e.g. laravel.com 192.168.1.100
Upload laravel app to web server and config it a test domain, e.g. dev.domain.com, or dev.domain.com:8080
If you can config your WiFi router, you can give your computer a "port forwarding" or set "DMZ"
Upload your website, and config "IP forbidden" roles, e.g. for Apache, edit your laravel's .htaccess file:
Deny from all
Allow from 180.159.251.175
You can use Laravel Homestead, an official pre-packaged Vagrant "box" to develop your project and access your local website from multiple machines within the same private network.
Here you can find more information about homestead and how to use it:
http://laravel.com/docs/5.0/homestead
And here a sample Vagrant private network setup:
http://docs.vagrantup.com/v2/networking/private_network.html
If you are having trouble using the accepted answers method, and you get page not found or similar errors, this is likely due to your firewall settings.
If
php artisan serve --host 0.0.0.0
doesn't seem to work.
Try php artisan serve --host 0.0.0.0 --port 80.
And access just using your IP address. For instance:
http://192.168.1.101

Run PHP code on local MacOS Jekyll site, port 4000

I've build a Jekyll website on my localhost (MacOS Mavericks). The website is served at http://localhost:4000/website/ and everything regarding Jekyll is running just fine.
However, I now want to have a contact form in PHP that allows me to receive emails. I placed a contact.php file in the website/ folder and have the form POST to that file. On my remote web server, this is working perfectly. However, on the localhost, the PHP isn't parsed, and plain text is displayed on contact.php. However, PHP is parsed perfectly on localhost/contact.php.
How do I get my localhost (Apache? PHP?) to process PHP files on my local Mac http://localhost:4000/ (without breaking my Jekyll website that listens on the same :4000 port)?
You can't use the same port. The port determines the application endpoint that will handle the request on the IP address. The Jekyll server (WEBrick library) uses port 4000 as a default.
The typical way to handle this problem, is to use a "web service" to add dynamic functionality. For instance, the jekyll docs suggest using something like FormKeep, or SimpleForm.
What you're asking is to setup a "web service" yourself. To do this it would need to be on another port or another IP address. The "service" will simply act as an endpoint to accept and process your form post. In this case you could setup a webserver using Apache/PHP on a different port than Jekyll -- such as the standard port 80 -- then write a PHP script (e.g., webform.php) that in combination with the static form is setup to respond and process your form.
Note: It is possible to configure both Jekyll and Apache to respond to requests on port 4000. However, both applications (aka servers) can't be running at the same time. The ip:port combination determines which application an internet request is sent to.
I realize the post is old but this may help someone...
The answer by Mike Stewart is excellent and describes what needs to be done to accomplish the goal.
To add to that answer, here are the specifics of how I do this type of development on a Mac.
Configure CORS in Apache
Run the Jekyll site on default port 4000
Run MAMP stack on default port 8888
Code goes in MAMP's htdocs folder (htdocs/your_project)
PHP resides in a separete "php" or other folder inside the "your_project" folder
Jekyll watches the "your_project" folder and compiles to _site as normal
The CORS issues you'll experience can be resolved locally during development several ways. Here is a good resource for enabling CORS on Apache: http://enable-cors.org/server_apache.html
Once you have CORS configured you'll be able to make Ajax calls to the PHP on port 8888.
I'm running the PHP built-in web server alongside the Jekyll server. I opened a second Terminal window and navigated to the _site folder. The command is php -S localhost:8000 (or whatever port you want to use that is not 4000).
Note that I'm using viewing localhost:8000 in the browser, but having the Jekyll server running simultaneously is nice because Jekyll keeps the build updated as I make changes to the source code (refresh required).

Categories