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

Discussion in 'B4J Tutorials' started by Shay, Feb 11, 2015.

  1. Shay

    Shay Well-Known Member Licensed User

    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:

    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:

    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 ==


    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


    == 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/



    # After=docker.service

    # Requires=docker.service




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



    --> 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 ===



    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/
    ellpopeb4a, jamesnz, Jmu5667 and 6 others like this.
  2. Erel

    Erel Administrator Staff Member Licensed User

    Thank you Shay. I moved it to the B4J forum as it is actually about B4J servers.
  3. Shay

    Shay Well-Known Member Licensed 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)
  4. moster67

    moster67 Expert Licensed 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.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice