Running socket.io on A2hosting VPS hosting - socket.io

A2hosting seems not pass socket = io("https://localhost:45678") to the server.
I have done the following and check below article but still can't figure out.
Running socket.io on Shared Hosting
ssh into the server
go to /public_html directory
npm install socket.io and go to node_modules directory
edit server.js below and node server.js
const { createServer } = require("http");
const { Server } = require("socket.io");
const httpServer = createServer();
const io = new Server(httpServer, { cors: {
origin: '*',
} });
io.on("connection", (socket) => {
console.log("connection")
});
httpServer.listen(45678);
5. revise the .htaccess file in the public_html directory with
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteRule ^$ http://127.0.0.1:45678/ [P,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://127.0.0.1:45678/$1 [P,L]
</IfModule>
6. from the client side, just create php file and excute below
const socket = io("https://localhost:45678");
but the console said "Failed to load resource", it seems the request do not go to server.
7. if item 6 is changed to socket = io("https://muazkhan.com:9001/") it is ok.
I have ask A2hosting but they can check the port is open but not able to fix the problem.
Please help me. Thanks a lot.

Related

Laravel 7: External link not working in localhost

The external links of CSS and JS are not working when I try access my Laravel project from localhost by www.localhost/myproject this. But others porject run well. I have to run php artisan serve command to run my project perfectly. When I upload it to Cpanel hosting it shows the error This site can’t be reached.
This is the app URL in env file APP_URL=http://localhost
This is how I declare the links {{ asset('backend/mystyle.css') }}
All of my CSS, Js files are under public folder. I think there might some problem in .htaccesss.
File structure:
-app
-public
--backend
--css
--robots.txt
--web.config
-.env
-.htaccess
-index.php
-server.php
.htaccess file
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /hrm-payroll-v3-2021/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
AddHandler application/x-httpd-php70 .php
<IfModule mod_suphp.c>
suPHP_ConfigPath /opt/php70/lib
</IfModule>
Index.php file
<?php
define('LARAVEL_START', microtime(true));
require __DIR__.'/vendor/autoload.php';
$app = require_once __DIR__.'/bootstrap/app.php';
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
$response = $kernel->handle(
$request = Illuminate\Http\Request::capture()
);
$response->send();
$kernel->terminate($request, $response);
Server.php file
$uri = urldecode(
parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)
);
if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) {
return false;
}
require_once __DIR__.'/index.php';
Can you please tell me why this problem may occur? What is the possible solution to this problem?
Thanks
you need to change your APP_URL to your domain
If you run php artisan serve without any arguments, Laravel starts a local web server on port 8000. Therefore you should consider this in your .env file by adding the port number in your APP_URL.
When you upload your project to a cpanel, make sure the web server is referring to YourProject\public as document-root directory.
I have solve my problem with updating htaccess file.
htaccess file:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Options -MultiViews -Indexes
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_URI} !(\.css|\.js|\.png|\.jpg|\.gif|robots\.txt)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(css|js|images|trainer-cv)/(.*)$ public/$1/$2 [L,NC]
then rename the server.php file to index.php

Laravel Forbidden You don't have permission to access / on this server ONLY ON HTTPS

I have deployed my 7.11.0 version Laravel app to production. Everything went well except when I try to access my website over HTTPS I get the "Forbidden You don't have permission to access / on this server." error.
If I access my site over HTTP it works normally. I have tried updating my APP_URL in .env file to HTTPS but that doesn't make a difference.
In my public directory the .htaccess file is the default one.
In my root directory I have this .htaccess file:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ ^$1 [N]
RewriteCond %{REQUEST_URI} (\.\w+$) [NC]
RewriteRule ^(.*)$ public/$1
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ server.php
I have solved the problem by creating a symbolic link from private_html to public_html directory.
Most hosting providers have an option for that in the admin panel.

Laravel on a shared hosting server returns error 500

I'm using a shared hosting server, I installed my first Laravel 5.4 application and everything is still working fine. A few days ago I installed another Laravel 5.4 application on a different domain, but same server, but when I try to access the URL, I get 500 INTERNAL SERVER ERROR.
Below is my .htaccess code
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
I also tried the following, but same error:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
### Add two lines for fix error 500 ###
Options -Indexes
php_flag xcache.cacher 0
#######################################
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
You moved everything inside your public_html folder which you should not do. Only files inside /public needs to be in public_html, hence the name public. The Laravel files should be placed higher directory where it is not accessible from the public.
Install Laravel with Softaculous, or with composer via SSH in /home/username/laravel
Move everything in /home/username/public_html folder to
/home/username/laravel
Move everything in /home/username/laravel/public to /home/username/public_html and delete the public folder after move.
Edit this file: /home/username/public_html/index.php
Change to require '/home/username/laravel/vendor/autoload.php';
Change to $app = require_once '/home/username/laravel/bootstrap/app.php';
Save this file and close window.
Edit this file: /home/username/laravel/server.php
Change to:
if ($uri !== '/' && file_exists('/home/username/public_html'.$uri)) {
return false;
}
require_once '/home/username/public_html/index.php';
Replace username with your hosting username. :)

Laravel routing triggers 500 error on subdomain

I am trying to put my laravel project on a live server. It is supposed to run on subdomain http://api.domain.com. The problem is it shows 500 internal error on any route except:
Route::get('/', function () {
return view('welcome');
});
Folder structure:
/
--laravel
--subdoms
----api
--www
When I put content of public folder of laravel project into www folder it runs on domain.com perfectly, database, authenticating, routing, it works.
When I put that content into api folder and I visit api.domain.com it loads welcome view. But when I add another route:
Route::get('testing', function() {
return "Tested.";
});
This shows 500 internal error.
Thank you for any feedback.
Edit: my .htaccess file in public:
<IfModule mod_rewrite.c>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

New to Laravel - Route does not work

I just started learning Laravel from this series: https://laracasts.com/series/laravel-5-from-scratch/episodes/2
I use windows 10 with Wamp.
My site sits under: sites/highland.lar
I created the virtual host.
The route has this code:
Route::get('/', function () { return view('welcome'); });
When I go to: http::highland.lar I get the page: Index of/ instead of the Welcome.blade.php view.
I added an index.php file to the root folder to test, and this file works fine.
After installing laravel the public/htaccess looked like:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
Reading this link: enter link description here
I changed it to:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
Nothing helps. What am I doing wrong?
Ok, solved the problem with this link:
enter link description here

Resources