Unable to make my app show with lightsail virtual server - javascript

I am trying to upload my site. it's a node.js repo on a linux instance on amazon light sail services.
I uploaded my source code repository to my Virtual Server Instance with static IP using FileZilla through a SSh pem key(all fine i guess..), also I modified the file for the apache server as mentioned in the walk-though tutorial but, I am not able to make it show when I write http://54.87.121.120/spanishwithalex/server/
Before I upload my repo I tried with a simple app that worked perfectly,but now i don't know why it doesn't work. I tried various ports, different locations and various forms but I think I am walking in circles.
I attached some pictures to show where I located my files and the error messages.
I hope it's some how clear.
Thanks
location in my instance
structure repo
error message
apache conf

I'm not great on apache config, but I walked through this enough to get you going:
SFTP or SCP your code to a new folder called /opt/bitnami/apache2/spanishwithalex
Edit /opt/bitnami/apache2/conf/bitnami/bitnami.conf using VIM or whatever and replace every line that has this /opt/bitnami/apache2/htdocs
with this: /opt/bitnami/apache2/spanishwithalex
Restart Apache:
sudo /opt/bitnami/ctlscript.sh restart apache
Let me know if that gets it working for you.

Related

How to stop a NodeJs file on Ubuntu server

I paid someone to install a Js script on my server
but when i tried making some changes on scripts/files i just couldnt see the changes on browser
while browsing and googling for like 24 hours i figured out that js scripts should be restarted in order to show the result on browser
and i figured out that in order to start a node js file i should type in terminal
node /dir/example.js
but can someone help me how to refresh/restart it
Iam stuck here like 24 hours
please help
I just want to let you know too that iam using Putty software in order to connect to the ubuntu server, ubuntu version is 20.04
EDIT: you will need an ssh connection to your server with access to a terminal..
Your node.js scripts, if they are on a server, should typically be ran using a process manager such as pm2.
Try to type pm2 list in a terminal. If you see some information you have hit the spot. Just after that run pm2 restart id. id being the number of your process and your changes should be visible.
You can just try this or try your luck with other process managers that run on your server providers. Just read what your server provider recommends for default and usually your previous developer would have used it.

How to start big nodejs project virtual classroom?

Developers i'm a nodejs developer with a experience of 1.5 years working in the company my question is i'm doing a project which is called a virtual classroom like a webinar platform where chat support, drawing and etc functionalities are available, so from last 2 month had been done of working in project i had gone through the each component directory and file with it's documents also they have used of docker, redis, proxy server, nginx, session, mongodb these kind of services and it's working fine on server end side but can't able to stablish on my local machine and it's a linux based project where have numbers of powershell files with PM2 library to make it run... so i followed a docs with some code also i success to make the service on and registered a local domain also in hosts file or nginx custom configuration it is working fine... but when i hit my ulr on browser with the local domain it not going to any of the route....
Example - like if we make a node simple project with hello world and it will working on 4500 port so we write localhost:4500 and it will print our responce on browser
but if the run my project through a PM2 or a simple node app.js bcoz this app.js have connected with all nodes services and virtual classroom and you the linux platform we don't need to make serivice on it's by default in runing state monogoDB, redis, docker, nginx but the real question is while firing the command node app.js it shows some json and told port:2178 but when in hit this on browser localhost:2178 not responce to GET request why??? but there is route called localhost:2178/landing/session/v1/classid(which is encrypted code) this url not working what to do ??

Applying node.js server to a web server

I am trying to learn how to use Node.js and web sockets to create simple multi-user interactive javascript programs. I used this tutorial series by Daniel Shiffman to create this example project. My next step would be to upload it, using WinSCP, to my RaspberryPi apache2 web server, but I haven't found a way to edit the code in a way to allow for that to work, and furthermore, I do not know what piece of the programs to execute to make it function properly.
Any assistance would be great. The extent of my Node / Socket.io knowledge comes entirely from the video series mentioned above, so you can assume I know almost nothing else.
Apache is a web server and it serves your file and send them to client for you, so when you have some client side things like html site with some css, javascript and images you can use apache to send them to client for you.
In node.js you can create this web server simply by following code and express library:
// Create the app
var app = express();
// Set up the server
var server = app.listen(3000, () => {
console.log('http server is ready')
});
as you created in your code too. by this web server you can host your files and do many more things like setup socket.io server and ... because you write web server yourself. with following code you serve static files in public directory (html, css, javascript and images ...):
app.use(express.static('public'));
after you finishing this process you can run it simply by:
npm install
node server.js
if you want you can run you code inside docker by creating Dockerfile and ...
About your question, you must move all your project files into raspberry and at the end you have following directory tree in somewhere in raspberry:
|- server.js
|- package.json
\ public
at this directory run above commands and your server will be up and running and you can access to it by http://raspberry_ip:3000.

mail to myself a user's submitted form - hybrid app

I am trying to build a hybrid app, I am using jquery mobile. The app is supposed to be installed on the mobile and not a web-app. I tried doing some research but still couldn't understand how to accomplish what I want.
I want to insert a form for the user to fill (such as: mail, name, telephone, text) and I want that when submitted the fields will be mailed to myself.
I understand that it isn't possible to insert php to jquery mobile because it doesn't support it or something like that. However, I saw that it's possible to call a php script through AJAX. But I don't get how it's done because PHP is server side it has to be hosted somewhere right?
So I need to host on the web a php file and call it through the app by it's URL?
I have found a php script that does exactly what I want but I don't understand if it's useable through hybrid app.
I also read that javascript can't mail something straight to my email address, it only has the mailto function which opens a mail form.
I couldn't find an answer to that, and I would really appreciate if someone could explain to me how it works and if it's even possible.
Its very easy, but for a beginner it may be a daunting task to set up so ill write Plenty of Notes and Installation tasks to get you started.
Prerequisites for a Home Setup with PHP and EMAIL Capabilities. For Remote Hosting Setup I guess everything is Installed for you but may require some Cost, so for Home use and doing it by yourself the bonus is that its Free.
1) A Spare Computer with at least 1gig of ram and 10gigs of hard disk. if you don't have a spare one or cant afford one at he moment you may be able to Virtualize one on top of your current computer using something like Virtual box which is free. If you want 100% live service the computer must be on all the time and connected to the Internet.
2) A Server OS preferably Linux one. In this example will use UBUNTU Server. Why? Because its Very easy to setup and install extra utilities, frameworks and programs, easy to manage and has all the features you will ever need and its Fast.
3) A Mail Account. GMAIL as an example for sending emails.
4) an Internet Connection.
5) A network Cable to connect the computer to your Router. Even if you choose Wireless over a Network Cable to connect you may need to download additional drivers to get your Wireless card Working and Connecting Most likely you will need a Net Cable first. It is advisable not to use Wireless for Such Setup for a number of Reasons such as Security, Loss of Connection (Weak Signal) etc
That's it. Total Installation time About 35 minutes. 25 mins for installing the OS and 10 mins for the rest of setup so you can send emails Via PHP.
The Setup
1) Install UBUNTU Server Visit Ubuntu to Download the Latest Version.
Server not the Desktop Version as its a bit slower than the Server version. However the downside to using the Server version is that you need to learn some basic commands on how to edit, copy, move, delete, change permissions of files around the server via command line. But its not rocket science.
On the good side hosting websites on Linux Server which may hold 100's of files of scripts, CSS, and Web pages, what you can do is install SAMBA server which enables you to share your web folder(s) or any folder for that matter over your Local Network or from Outside so on another PC using Lets say Windows can connect to that folder and will enable you to use all your favorite software on windows for editing and Saving those files on your Linux Server which is easier rather than using editing utilities directly on the server. takes about a minute to install and setup a Samba server. I will add that to the bottom of this Guide.
once that's done
2) Install LAMP Server
This will Install
Apache Web Server, Mysql Database, and PHP
Pretty much all you need to start hosting websites (Apache), have databases (Mysql) for web uses and a server side language to handle all the work (PHP).
command
(sudo is required in ubuntu in front of commands so you can run them in admin mode which is more Secure. It will ask you for your account password, before running the rest of the command)
sudo tasksel install lamp-server
Let it run, It will Auto download the required files so make sure you are connected to the internet. The only question you will be asked is type in a password for the root access of Mysql database.
Apache, Mysql, PHP can be further configured so there is some basic learning curve for the future.
I never had to configure Mysql, for Apache configuration i usually change the Path to where my website is and some Security settings. The default directory where your web related files go into is (/var/www/html). This html directory is where all the PHP, HTML files go into. However, there's no Reason why you cant rename this folder and reconfigure apache to directly use it as your root web folder. Ill explain how to do this near the end of this guide. For PHP configuration, you may need at some point to install extra extensions such as php5-imagick which is a library for editing images using PHP. There are many extensions that can enable PHP to do many things.
Halfway there
Email Setup using Postfix which is a way to send emails
command
sudo apt-get install postfix mailutils libsasl2-2 ca-certificates libsasl2-modules
After a few moments it will Present You with Some Options In setting Up Mail.
You want (Internet Site) i think its the 3rd option Down. Choose this
You will then see your hostname. No action Required here, Continue
That's the Mail Done, but we need to configure some bits to it so it knows about the mail configuration
open your postfix config file
command
sudo nano /etc/postfix/main.cf
add the following in the file, you can put it add the end of the file
relayhost = [smtp.gmail.com]:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_tls_CAfile = /etc/postfix/cacert.pem
smtp_use_tls = yes
you may see (relayhost =) already in the file. what you can do is delete that line and add all the above there.
nano is a text editor, so freely move with the cursor keys up down, delete, type etc. When you finish editing. do CNTRL X and press Y (Yes) to write and exit the file. If you made a mistake in the file press N (No) to just exit without writing to the file.
Almost there
edit the Postfix email Account Information file and insert (In our example Gmail account) logging information.
command
sudo nano /etc/postfix/sasl_passwd
should be a blank file, so insert
[smtp.gmail.com]:587 USERNAME#gmail.com:PASSWORD
change USERNAME#gmail.com to your email account and PASSWORD to the emails password. It needs this info so Postfix can connect to Gmail and send mails
I suggest creating a new fresh email account with your App's Name.
my_app_name#gmail.com so you have a distinguished account name for sending emails through your app.
CNTRL X and Y to save and exit the file
Now we fix some permissions to the files
Fix permission and update postfix config to use sasl_passwd file:
commands
sudo chmod 400 /etc/postfix/sasl_passwd
sudo postmap /etc/postfix/sasl_passwd
Next, validate certificates. You say what??? Just run the following command, Do you see a bunch of Random characters about 200 of them? If so that's your servers Certificate for sending Mails.
command (no further action is required as cat is the command to just list a file on screen)
cat /etc/ssl/certs/Thawte_Premium_Server_CA.pem | sudo tee -a /etc/postfix/cacert.pem
ALL DONE You can send mails now, However we made some changes to the files above so lets reload Postfix first to take in the changes.
command
sudo /etc/init.d/postfix reload
Do a test
command to send an email from the server
echo "This is my first test mail from my server" | mail -s "From Me" myemail#gmail.com
Check did you get the mail?
If yes then you are able to send mails directly from the server
Ok now that you can send emails from your web server you need to use Ajax Post to post the form data in your java script files over to a PHP file on your web server and compose the email and send it.
Before you consider buying a domain name (mywebsitename.com) you can start testing using the WAN address of your home router.
If you don't know the current address open a browser and type (What is my WAN address)
eg.
http://wanip.info/
this will show your WAN address. xxx.xxx.xxx.xx
this is the number you put in to your AJAX requests
example
$.ajax({
method: "POST",
url: "http://xxx.xxx.xxx.xxx/some.php",
data: { name: "John", location: "Boston" }
})
.done(function( msg ) {
alert( "Data Saved: " + msg );
});
More info about Ajax here
http://api.jquery.com/jquery.ajax/
But first we finish off completing some minor tasks
You router needs to know your webeservers IP address so it can send HTTP requests and Data to it.
How to find the Webserver IP and Routers IP addresses using Linux
command
ifconfig
you will something like this
eth0 Link encap:Ethernet HWaddr 08:00:27:87:35:25
inet addr:192.168.2.15 Bcast:192.168.2.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fe87:3525/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:861 errors:0 dropped:0 overruns:0 frame:0
TX packets:549 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:125639 (125.6 KB) TX bytes:63563 (63.5 KB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:56 errors:0 dropped:0 overruns:0 frame:0
TX packets:56 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:3360 (3.3 KB) TX bytes:3360 (3.3 KB)
You are Interested in the Ethernet Network Card eth0 (if you have installed more than one network card you may also see (eth1, eth2 etc) and this inet addr:192.168.2.15 is your servers address. Not Static Yet
command
route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.2.1 0.0.0.0 UG 0 0 0 eth0
192.168.2.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
this 192.168.2.1 (under the Gateway next to 0.0.0.0) is the Routers Local Address
Please note, yours may be different
open a browser and type that in
http://192.168.2.1
you will be presented with your routers home page. Log in and find Virtual Servers settings. Should be in the General Firewall Options.
You should see a Table like this
Depending on your routers model you should see something similar. Use the drop down menu and choose WEB HTTP. Click add. The 80 80 .. that's the ports the firewall will open for WEB communication. Enter the last 2 digits of your web servers address and click Save. Your router may reboot to save the changes.
Lets install SAMBA server so you can share your web folder to your Local Network so you can access it from a local PC. In this example we use Windows.
command
sudo apt-get install samba
After it has finished Installing edit the samba configuration file so we can add the folder we want to share in our case /var/www/
command
sudo nano /etc/samba/smb.conf
go to the bottom of the file and add
[share]
comment = Ubuntu File Server Share
path = /var/www/
browsable = yes
guest ok = yes
read only = no
create mask = 0777
CNTRL X and Y to save and exit the file
i suggest checking the net for samba share configuration as the above setup does not have much security in mind. You can do much more like request a password to connect, disable guests, etc.
we change the Permissions of the web Folders to full. Although not recommended, as you have a blank web folder you should inherit normal user permissions as you create files and when you learn about changing permissions of files and directories on Linux in the future you change them.
command
sudo chmod -R 777 /var/www/
basically the 777 is spread into 3 levels of permissions and it represents binary 111/ 111/111 -- binary number (111) is in the real world 7 so READ(1), WRITE(1), EXECUTE(1) are all turned on for those 3 levels which its not very secure. I suggest you read more about the chmod command and file permissions to get a better understanding about its use.
It's time to give the server a Reboot
sudo shutdown -r now
Now The Reboot is done, Lets connect to that shared Web Folder
Assuming you have a PC running windows connected to the same Local Network as the web server (Mac should be something similar but check on how to connect to a shared drive)
Open Computer, choose Map Network Drive type in the web servers IP address e.g \\192.168.2.23\ - click Browse You should see the folder we shared in the SAMBA configuration file. Connect to it.
Treat that drive like any drive to save your files only this one is the root folder of your web server website(s) folder.
However on the webserver if you don't want the default html folder eg you want a custom name for your website, on windows right click on the folder and rename it.
If you do rename it you need to let Apache know by doing the following
command
sudo nano /etc/apache2/sites-enabled/000-default.conf
change DocumentRoot /var/www/html to DocumentRoot /var/www/thenewname
CNTRL X and Y to exit nano
restart apache webserver to take in the change
sudo /etc/init.d/apache2 restart
do a test page
write a simple index.html webpage or index.php php page and save it in the web folder
open a browser and type in your WAN adress
here is a link on how to compose and send an email with PHP
https://css-tricks.com/sending-nice-html-email-with-php/
Ok last note
You have everything running, but Home Routers Have Reserve IP address that give each local PC automatically when they connect to the network. Not a big issue, but its best to give the web server a static IP address
Log in to your router again and go to your Lan Setup specifically we want to check the DHCP Server IP Pool Settings. Dhcp is responsible for giving out IP address automatically to each PC in a local network so it reserves around 100 of these out of possible 253 address on a home router. We need to check the range and choose one above that range.
You should see something like this. From 192.168.2.2 to 192.168.2.100 are reserved by the Dhcp service. So logic has it we can choose 192.168.2.101 as an address for the server as this is not used by the Dhcp service. In fact 192.168.2.101 to 192.168.2.254 are free as the complete range of a routers IP address are from 2 to 254 the 0, 1 and 255 are used by the router.
edit the network file on your webserver
command
sudo nano /etc/network/interfaces
Copy what you see below, (without the //remarks) and delete the existing setup in the configuration file for eth0 which is the Ethernet card 0.
# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.2.101 //the chosen IP address for the webserver
gateway 192.168.2.1 // the routers address
netmask 255.255.255.0 // leave this as is
network 192.168.2.0 // change x.x.2.x if you are on the 1 network. ie 192.168.1.0 some routers are on the 1 network
broadcast 192.168.2.255 // same as above
dns-nameservers 8.8.8.8 //check below
CNTRL X and Y to exit nano
Just to clarify dns-nameservers 8.8.8.8 uses a Google Public DNS server to translate web address to IP addresses. Its a general use one. You can change that to any Public DNS Address you know, but it is required because we now have manual settings for the webserver.
Reboot the server again to load in the changes to the network and lastly log in to your router and change the IP number for your Virtual server to send HTTP Requests as shown in the above Step we did earlier.
I hope this guide helps you

Node.js /socket.io/socket.io.js not found express 4.0

So I'm trying to get chat working on my website, and when I was testing locally it worked great, because port 8080 on my localhost was available and all that good stuff. But now I pushed my code to my Heroku app, and when I try and load my chat page, I get the error stating that it can't get localhost:8080/socket.io/socket.io.js.
I've seen node.js /socket.io/socket.io.js not found
and tried the suggestions, but none worked, even moving the socket.io.js file into a resource file did not work. I'm guessing this is because I'm using express 4.0?
Any help would be appreciated
Thanks
Edit:
So to add more details, since my question could seem a little vague, here is my relevant app.js code:
var client = require('socket.io').listen(8080).sockets;
In my jade file for the chat page, I have:
script (src = `'http://localhost:8080/socket.io/socket.io.js`')
and later on
var socket = io.connect(`'http://localhost:8080`');
and all this works on localhost (I load up on port 5000, socket.io is connected to port 8080). I do this using 'foreman start' with the heroku toolbelt.
When I try and change these to work on heroku, it breaks and I'm not sure how to fix it. I hope this clarifies the question a bit.
Edit 2:
I'm running:
express 4.0.0
socket.io 0.9.16
node 0.10.x
Thanks
Do you have an explicit route in express which catches all other routes? Something like this perhaps:
app.get("/", handlers.home);
app.get("/..." ...);
...
app.get("*", handlers.error);
This might keep socket.io from being able to host it's own js file for the client. There is an easy way to fix this, since you probably already have a public or static folder setup in express. Something like:
app.use(express.static("public"));
Make a new folder called socket.io and copy over the appropriate socket.io.js file into said folder, and all should be well. However note that there are two files named socket.io.js!! So, if you see something like "Uncaught ReferenceError: require is not defined" it means you copied the "node-ey" server side file. Here is the correct client file to copy:
app_dir/node_modules/socket.io/node_modules/socket.io-client/dist/socket.io.min.js
Note #BHendricks: I would have just posted as a reply to your comment, but I currently lack the required reputation.
Edit:
The OPs question probably has more to do with the "localhost" issue. When connecting from a client (say your home IP), as far as your browser knows - localhost implies a connection with the machine which is locally hosting stuff. Since your home machine (or phone) does not host socket.io, this is failing.
What you need to do is have your server embed the socket connection information (either a fully qualified hostname, ip etc). This can be done when the server "renders" the page with the client connection.
What happens when you go to http://localhost:8080/socket.io/socket.io.js?
Does it 404? If it does you need to make sure you have it in a directory that Express is set to serve statically.
app.use(express.static(__dirname + '/public'));
Then put your socket.io.js file in public/socket.io/socket.io.js (relative to your app.js file)
Restart your server and see if that fixes it.
Basically, Express doesn't serve files statically from the file system unless you explicitly tell it where to map from.

Categories

Resources