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
Related
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.
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 ??
Is it possible for a HTML5/JavaScript web page in google-chrome on Ubuntu 16 to control keyboard LEDs?
I have a NUC5PCYH with a custom keyboard that accepts CapsLock, ScrollLock and NumLock signals as functional action inputs and a web application to control it.
I have failed to get two different test examples of Google Chrome's Native Messaging extension to work simply because I do not understand half the instructions.
Several PHP examples indicate running XSET from a PHP triggered BASH script is possible but I have zero experience with PHP and limited BASH knowledge.
Using SQLite3 to read chrome's local-storage 'variables' seemed easy enough for me to do but I can't seem to work out how to script SQLite and none of the files in google-chrome's cache are recognized as a valid database.
If I knew any Linux programming languages I'd write one to monitor the top line on the chrome browser window's client area and activate the LEDs according to binary patterns in black and near black pixels.
Can anyone point me to zero-knowledge installations of possible solutions in PHP, SQLite or Native Message Extensions?
Alternatively, where is the best place to hire a programmer for a solution?
I have managed to solve the problem myself using the second idea, PHP.
Install Apache2 and PHP to set up a local host
sudo apt-get update
sudo apt-get install apache2
sudo apt-get install php libapache2-mod-php
Remove /var/www/html/index.html
Create two files in /var/www/html/
index.php
<?php
$var=$_GET['data'];
exec("sh /var/www/html/simple.sh $var", $output);
echo var_dump($output);
?>
simple.sh
#!bin/bash
sudo echo $1 > file.txt
echo $1
Because the username for apache is www-data:
php -r "echo exec('whoami');"
the folder needs ownership change to apache
sudo chown -R www-data:www-data /var/www/html
One last file to create, on the desktop for now, but can go anywhere:
monitor.sh
data=`cat /var/www/html/file.txt`
if [ $data -eq 1 ]
then
xset led named "Caps Lock"
else
xset -led named "Caps Lock"
fi
Edit some settings and permissions:
sudo visudo
Add the following to the end of the file:
www-data ALL=NOPASSWD: ALL
Enable changing of the CapsLock LED:
sudo gedit /usr/share/X11/xkb/compat/ledcaps
replace: !allowExplicit; with: allowExplicit;
The final sequence:
Open a browser and enter the URL:
http://localhost/index.php?data=1
index.php will get the value of data from the URL and execute simple.sh with that value as the first argument.
simple.sh uses echo to write the argument value in $1 to the text file named file.txt.
sh monitor.sh
The value stored in file.txt is dumped into the variable data by the shell command cat.
If the value in the variable data is 1 then CapsLock is turned on, and turned off if the value is anything else.
Saving the data value into file.txt and reading from a different location using monitor.sh is due to xset error in /var/log/apache2/error.log:
xset: unable to open display ""
My best guess is that xset requires a display no matter what, and being launched from a shell file by PHP is without a default display. The documentation of X and xset for -display confused me so much that I used this approach after trying various suggestions. The accidental benefit is that I can host the monitor.sh file on a networked NAS box rather than locking inside /var/www/html/
ps: Forgive me if I have missed something or forgotten some explicit detail as I am very new to these tools in this environment.
I am making a post request with some javascript to a python script in my /var/www/cgi-bin on my web server, and then in this python script I want to save the image file to my html folder, so it can later be retrieved.
Located at /var/www/html, but right now the only way I know how to do this is to set the python script to chmod 777 which I do not want to do.
So how else can I save a file that I grab from my webpage using javascript and then send to server with javascript via POST?
Currently when I do this I get an error saying the python does not have permission to save, as its chmod is 755.
I here is python code, I know it works as the error just says I dont have permission to write the file
fh = open("/var/www/html/logo.png", "wb")
fh.write(photo.decode('base64'))
fh.close()
If you don't want to change the permission of that directory to 777, you can change the owner of the directory to your HTTP server user, then the user of your web app will be able to write file into that directory because they have rwx - 7 permission of the directory.
To do that, via (since you're using Apache as your web server, remember login as `root):
chown -R apache:apache /var/www/cgi-bin/
Remember that then only user apache and root has rwx to that directory, and others has rx.
And this command means:
chown - change the owner of the directory
-R - operate on files and directories recursively
apache:apache - apache user, apache group
/var/www/cgi-bin/ - the directory
Try man chown command to check the manual page of chown and learn more, here's a online version.
If you need change it back, I think the default user of that directory is root. So login as root, and run command:
chown -R root:root /var/www/cgi-bin/
We were solved the problem in chat room.
The error message is directly indicating the role/use the python server is running on doesn't have write access to the folder. You need to assign either the role or the web server user. Make sure to give only write access and not write + execute access.
I have a scalable app in OpenShift with MongoDb2.2 ad NodeJs0.10,
Since i can't use Cartridge rockmongo-1.1 because it cannot be embedded in scalable app,
How can i get my db'documents and do a Backup and Restore with ssh ?
Make sure you use the RHC command line tools.
You have two ways to get to your data:
1) You can ssh into your gear (as a shortcut you can do rhc ssh {app-name}). Then you can do the dump and restore at the console. Remember, you only have write permissions to the ~/app-root/data and /tmp directory so make sure to put your output there. Then you can scp your files back and forth.
2) You can you*rhc port forward* to port forward you MongoDB terminal and commands to you local machine. You will still need the MongoDB username and password we assigned to your instance on creation.