B4J Tutorial (B4X) Creating LAMP server with b4x on Amazon EC2

LAMP: Linux Apache MySQL PHP

In this tutorial I will explain how to bring complete working server, on Amazon EC2 (you get 1 year free)

I am using this server for sending notification for iphone (using b4j code), hosting all my php code for IOS/Android + hosting MySQL server / Apache, as well it should solve all the encryption issue, since it uses real (1 ip) certificate (Ecryption with ssl was not tested by me yet)

You will need to register as new EC2 user and create new instance
For more information follow this link:
http://aws.amazon.com/free/

I also recommend creating “Elastic IP” meaning public IP that will not change
And move your domain name to AWS + configure “hosted zone” + DNS record set (A record for your http://domain.something)
Please note DNS stuff is not free – see pricing inside Amazon site

DNS part is not mandatory for now (you can always use http://ip, but if you are not using elastic ip, it can change)


After your account is ready, choose from the free instances the Red-HAT 7 image and install it

In order to login you need to create putty private certificate – you can follow this link:
https://linuxacademy.com/blog/linux/connect-to-amazon-ec2-using-putty-private-key-on-windows/


Please note I will try to give full information but if you encounter any issue try to read first in the resources at the end of this doc.


login as “ec2-user”

Run the following command

sudo su - (to get root privileges)


== installing Apache ==

yum install httpd

service httpd start

systemctl enable httpd

(Check that web server is now working)


== Installing MySQL server

yum install wget

yum install mariadb-server mariadb

systemctl start mariadb.service

systemctl enable mariadb.service

/usr/bin/mysql_secure_installation (put some password – remember it since it is your DB root password)

mysql -u root -p

show databases;


== Installing PHP ==

yum install php php-mysql php-gd php-pear

systemctl restart httpd.service


== Install phpMyAdmin ==

yum clean all

wget http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

rpm -i remi-release-7.rpm

wget http://rpms.famillecollet.com/RPM-GPG-KEY-remi

rpm --import RPM-GPG-KEY-remi

yum install phpmyadmin --enablerepo=remi


vi /etc/httpd/conf.d/phpMyAdmin.conf

add YOUR local IP (www.whatismyipaddress.com) ip in 4 places (require ip, allow ip) – see more information below

if you don’t do it, you will get error that you have no permission to login


== Login to phpMyAdmin ==

http://<IP>/phpmyadmin/

username: root

password: the one you put above


#hide default tables on phpMyAdmin:

vi /etc/phpMyAdmin/config.inc.php

# add below db configuration, restart httpd service, logout myphpadmin

$cfg['Servers'][$i]['hide_db']='^(information_schema|performance_schema|mysql|phpmyadmin|test|webauth)$';


== Enable SSL ==

yum install mod_ssl

mkdir /etc/httpd/ssl

openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/httpd/ssl/apache.key -out /etc/httpd/ssl/apache.crt

vi /etc/httpd/conf.d/ssl.conf

# General setup for the virtual host, inherited from global configuration

DocumentRoot "/var/www/html"

ServerName yourDomainName:443

SSLCertificateFile /etc/httpd/ssl/apache.crt

SSLCertificateKeyFile /etc/httpd/ssl/apache.key

apachectl restart


== install java ===

yum install java-1.7.0-openjdk


== Changing local time to Israel ==

mv localtime localtime.old

ln -sf /usr/share/zoneinfo/Israel localtime


== Update server clock ==

date -s "13/02/2015 20:42"


== Create service for Push Server ==

# Put Jar file under /home/ec2-user directory (or whenever you want)


--> create new file PushService.service under /etc/systemd/system/


[Unit]

Description=PushService

# After=docker.service

# Requires=docker.service


[Service]

TimeoutStartSec=0

ExecStartPre=

ExecStart=/bin/java -jar /home/ec2-user/PushServer.jar


[Install]

WantedBy=multi-user.target


--> save


systemctl enable /etc/systemd/system/PushService.service

systemctl start PushService.service

systemctl status PushService.service -l #This will show you status


# b4x server

change the port to port 81, restart apache



== Some tips ===
- Don't forget to open port 80, 443, 81 on your EC2 security group


=== Resources ===

http://www.cyberciti.biz/faq/howto-install-linux-apache-mariadb-php-lamp-stack-on-centos7-rhel7/

http://www.tecmint.com/install-lamp-in-centos-7/

REMI: http://blog.famillecollet.com/pages/Config-en

Hide myphpadmin default tables: http://stackoverflow.com/questions/14563328/phpmyadmin-default-databases


HTTPS: https://www.digitalocean.com/commun...ate-an-ssl-certificate-on-apache-for-centos-7


Service: https://coreos.com/docs/launching-containers/launching/getting-started-with-systemd/
 

Shay

Well-Known Member
Licensed User
Longtime User
Just tested https via EC2 server
it is working great
don't forget to use: (on client side, for example on "HttpUtils2Service" on b4i)
hc.InitializeAcceptAll("hc")
 

moster67

Expert
Licensed User
Longtime User
Thank you Shay.
Did you modify the code in B4x pushserver to save the data in a mySQL database instead of SQLite? Just wondering since you set up MySQL (Mariadb) in your tutorial.
 
Top