How to view html file in remote unix server? - html

I currently have an html file on a remote unix server that I ssh to. I have been using SFTP to constantly transfer it to my local machine to view it after my edits, but I am tired of this.
What is the best program/method for Mac users to have a browser window view of the html file that is stored in a remote unix server? Or is there an ssh client that can easily edit html files?

It is possible, but with some playing around on the server.
Once you have ssh'ed into the server, install a web server in that box.
Say the file is named index.html, you should make it available at the URL http://localhost:8000/index.htmlor port number can be anything.
The simplest method I can think of starting a web server at that location is
cd /directory/where/html/is/present
python -m SimpleHTTPServer 8000 # For python 2
python3 -m http.server 8000 # For python 3
This works provided python is installed on the server. It should not be that hard to install it as python is available from almost every package manager in every flavor of linux.
Now that html is available at python
http://localhost:8000/index.html
on that machine.
But we have not yet configured the browser in such way.
To do that you need to ssh into the server again, but with a -D option this time
ssh servername -D 7000
-D specifies application level tunneling when connecting via ssh
Then in Firefox, preferences/options -> Advanced -> Networks -> Connection Settings -> Choose Manual Proxy configuration
SOCKS HOST should be localhost , port no 7000.
Then the html should be directly available at
http://localhost:8000/index.html
in your Firefox browser.
This feature is only available in the Firefox browser.

You can mount the remote directory with sshfs which gives you easy access to all the files.
E.g.:
sshfs user#server:/directoryToMount /localDirectory

Related

How to securely connect to a database in Next.js app (using Prisma and MySQL) deployed to Vercel (serverless)

My MySQL database on DigitalOcean is locked down to only be accessible via local connection.
I'd strongly prefer to keep it secure like that (i.e. not to open it up).
I'm used to using SSH tunnels to connect to it (such as ssh -L 3306:localhost:3306 -i ~/.ssh/id_rsa myusername#myhost).
Now that I'm deploying a Next.js app (with Prisma) to Vercel, I'm trying to figure out the appropriate DATABASE_URL environment variable.
How can I set the DATABASE_URL environment variable (or whatever other relevant setting) such that my Next.js backend is able to securely connect to my remote database that is only open to local connections?
I couldn't tell from the docs.

Connecting to API via remote browser

I'm running a process on one system that hosts a JSON API at 127.0.0.1:42000. I would like to connect this API from a remote system. In particular, I would like to route the data to a web browser.
I've tried using my browser to connect to the local IP address of the machine on that port, but the browser is reporting that there is no response. I don't know much TCP, HTTP, and the like so unfortunately I can't really think of what to try next or even what to search for. Any help would be appreciated.
EDIT
I found a work-around that does what I need. I set up an HTTP server for a directory ~/my-http-server on port 54321 using python -m SimpleHTTPServer 54321. I also set up a repeating script to dump the contents of API call into a file named api.html in that directory: watch -n1 wget 127.0.0.1:42000 -q -O - | cat >> ~/my-http-server/api.html. It is far from a perfect solution, but I am at least able to access a cached version of the API call.
Are remote system and host on the same network? if yes then get the IP address of the host system and use that ip address instead of 127.0.0.1.

phpstorm debugging mamp but not my remote server

I have tried many ways to debug my remote server but I am unable to do so. My ftp and sftp and remote db is configures to my phpstorm 9 but I cannot debug my remote server it is connecting to my mamp server and debugging ,y local files but not connecting to server username and password . Basically it fails at mysql_connect but works for mamp.How can I make it deubug with server.Everything else is synced with server but I cannot debug. I really appreciate any help.
Edit: Should I install x-debug on my server(cpanel) also ?
php.ini
[xdebug]
zend_extension="/usr/local/opt/php55-xdebug/xdebug.so"
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
xdebug.idekey=PHPSTORM
xdebug.remote_connect_back=1
Maybe I didn't understand your question/problem. These are the ways you can debug your code
Debug the local code that uses the local database
This is the easiest setup and it probably already works on your system. You have all the files on the local computer and also you have an instance of MySQL running on it. The code connects to localhost:3306, the xdebug extension is installed and it can connect to PhpStorm, everybody is happy.
Debug the local code that uses the remote database
You can have all the PHP files on localhost and use the local mamp stack to debug it; you control the environment, xdebug works and happily collaborates with PhpStorm. You want the code to be able to use the remote (live) database.
In this case you need a way to access the database. Either you create a MySQL user that allows you to connect from the IP address of the local computer (a firewall along the way might prevent this), or start a ssh session that creates a tunnel from the local port 3306 (or any other open port you choose) to port 3306 of the database server (assuming the host where you ssh is allowed to connect to it). You can do this by running
ssh user#remote_host -L 3306:database_host:3306
(replace user, remote_host and database_host with your actual values)
If you have a MySQL server installed and running on localhost then the local port 3306 is not open and ssh cannot use it as the source port of the tunnel. Use another port instead (let's say you use 13306):
ssh user#remote_host -L 13306:database_host:3306
Modify the local configuration files of your application to use localhost as database server and 13306 as database port.
Debug the remote code
If you want to debug the live code (it uses the live database) then you have to upload the code on the web server (the live environment) and make it work there (be able to connect to the database etc).
In order to be able to debug it you need to have the xdebug PHP extension installed on the server and properly configured in the server's php.ini configuration file.
The debugger (the remote xdebug extension) needs to connect to your local computer where PhpStorm is listening on port 9000. This is either impossible or making it happen requires changing configuration here and there in several places (that might be out of your control); we better forget about it.
We can use the ssh tunnel trick: start a ssh connection to the server that creates a tunnel from local port 9000 to the servers port 9000:
ssh user#remote_host -L 9000:localhost:9000
Test if it works
PhpStorm provides a tool that uploads a script on the web server then tries to access it to check if the xdebug extension is properly configured. Depending on the version of PhpStorm you use, you can find it either in the menu (Run -> Web Server Debug Validation, on PhpStorm 9) or somewhere in the Settings (PHP -> Servers or around, on older versions).

How to ssh into HA application gears?

As was explained in the answer to this question: https://stackoverflow.com/questions/11730590/what-are-some-of-the-tricks-to-using-openshift it should be possible to ssh into some of the other gears when using a scaled app with openshift.
Unfortunately the link mentioned there (https://openshift.redhat.com/community/faq/can-i-access-my-applications-gear) seems to be gone.
Via [my app url]/haproxy-status/ I can see the names of the other gears. They are long names like gear-[long number]-[app name]. Using that name I can no longer ssh into them when I'm ssh'ed into the main gear. ssh there just immediately returns without any error.
If I do ssh blala the same thing happened, so it looks like ssh had been replaced by a noop command on the primary gear?
When I examine the haproxy conf file, I see entries like;
server gear-[long number]-[app name] ex-std-node[number].prod.rhcloud.com:[number] check fall 2 ...
I tried ssh'ing into this ext-std-node... address as well, both from the main/primary application gear as well as from my desktop, but it didn't work in both cases.
How can I get shell access to my other gears?
This command shows how to access individual gears:
rhc app show <appname> --gears
The last column of output is the ssh URL. It is of the form $UUID#$UUID-$NAMESPACE.rhcloud.com . You can ssh into them directly, and they are also accessible via ssh from the "head" gear; they have to be, since git pushes are synchronized from the head gear to the others via ssh.

vagrant environment with sublime text

it's possible to use vagrant to setup a environment for php development with some tools like PHP_CodeSniffer, PHP Mess Detector, etc, and then use sublime text plugin sublime-phpcs in the host machine to use this tools from vagrant?
I wanted to avoid install all this tools in my Host machine(mac os) but still use the sublime text with the plugin to develop in the host machine.
Thanks!
Technically you could probably point the sublime-phpcs plugin to an executable bash script which could run PHP on the VM through SSH. Something like this lets you run your VM's PHP:
ssh -i '/path/to/vagrant.pem' vagrant#vmip php
Where vagrant.pem is the SSH key that comes with vagrant.
It would also need to convert the local file path into a path that the VM could actually reach locally as well - either that or perform a reverse SSH connection back to the host.
In the end it's probably going to be very complicated and you might just be better off installing PHP locally.