Amazon EC2 + Netbeans Configuration
Who would have thought that a business who’s majority income is derived from online retail goods such as a body fat replicas and bullet shaped ice cube trays would be the first successful scalable (Amazon prefers the term “elastic”) cloud hosting solution? Not only were they the first, AWS is also by far the market leader in the industry leading with 31%, followed by Microsoft (9%), IBM (7%) as of 2016 figures.
Scalable cloud hosting is not a trend and is only expected to grow in the coming years. If I were to choose a scalable cloud solution that is sure to innovate and compete, AWS has my vote.
If you are used to shared hosting solutions like me, you must be willing to venture outside the comfort zones of Plesk and cPanel. Configuration over convention is the goal of AWS, so fire up your terminal and get the coffee going. We are about to embark on uncharted waters.
In this tutorial, I will be walking you through the steps that I took to set up my development environment for an AWS EC2 LAMP hosting solution using my favorite IDE Netbeans configured with SFTP for file transferring.
- Install Netbeans – FREE
- Sign up for a FREE Amazon EC2 account
- After signing up, log into your AWS console and click on “Build a web app”.
- Give your app a name, select PHP as the platform, and select the sample application so we can test out the file transferring later. Then click the Create App button.
By creating the app, Amazon AWS builds the application called an “instance” within the EC2 service. Head on down to AWS->Services->EC2 to view all running instances. Amazon serves the application and handles scalability through its Elastic Beanstalk service: AWS->Services->Elastic Beanstalk. Within Elastic Beanstalk, we could click on the instance and upload a project’s source code via the web using a zipped file. This solution works but is not an efficient development environment without and IDE with file transferring capabilities.
- Using the IAM service, we will great a permissions group. Navigate to AWS->Services->IAM. Within the IAM dashboard, select Group->Add Group and select a name for this group. I chose to name my group “Developer” because I’m boring. We don’t need to create special privileges for what we need to accomplish. However, keep in mind that this is where you will assign privileges for users within that group once you get familiar with AWS and the security rules of your app and environment.
- Next, create a user. Select Users->Create New Users. For the brevity of this article, we will only create one user. You will be prompted to save the Public Key and Access key – I encourage you to save it in case you decide to use an API service later.
- In order to securely connect via SSH and SFTP, modify your security groups within the EC2 console to only accept the public IP address from your local PC. Learn how to configure Security Groups for secure SSH access. I recommend trying leaving the unrestricted 000.000.000/0 IP address if you have any trouble with your connection.
- Within the EC2 console, create a new Key Pair. Download and install on your local PC. This acts as the password to connect to our server via SSH and SFTP.
- Fire up the terminal (Mac / Linux) or Putty (Windows) and enter the following command:
1ssh -i /local/folder/yoursshkeyname.pem email@example.com
The public address after the @ symbol can be viewed within the EC2 console for the instance you created earlier. The user name ec2-user may be ubuntu – depending on your Ec2 instance. Be sure you enter the correct location of the .pem file and .pem file name.
After entering the command you will be prompted with question “Are you sure you want to continue connecting?” Enter “yes”. On successful SSH connection, you should see the following response:
- Next, we need make our working directory writable in order to upload files. By default, we can download but not upload (write). The /var/www/html is where you might expect to change the permissions. Instead, EC2 uses symbolic linking from the /var/app/current folder. Enter the below commands to add the user ownership and privileges to the directory:
12sudo chown -R ec2-user /var/app/currentsudo chmod -R 755 /var/app/current
- Switching over to Netbeans, create a new PHP Application from Remote Server.
- Give your project a name and choose the sources folder.
- Enter the project public URL, then click the Manage button and Add a new remote connection.
- Add the name of your connection and select the SFTP option in the dropdown.
- Enter the host name, username, private key location, and the local location of your known hosts file. Leave the password blank. In this case our key file acts as our password.
- Test the connection. Fingers crossed! No whammies… and hope for big money.
- The project’s Run Configuration properties, select the remote connection we previously created and enter /var/app/current in the Upload Directory field.
- Now the moment of truth. From the Source Files folder within our project, download all remote folders and files. BIG MONEY!!! If you got a whammy, no problem. Just re-trace your steps and I’m sure you’ll get it. There are a lot of moving parts here and you will likely have to fail a couple times before everything checks out. If you believe in yourself – you will know how to ride a bike.
The most difficult process for me was getting a solid connection in Netbeans so that I could download and upload files before I realized that the standard /var/www/html directory was symbolically linked from another directory. [face palm] ;(
In the process of finding a solution that worked for me, I had to scour the interwebs for days before I had my entire development environment squared away. I know that there are others out there who feel my pain. If I have helped one person save hours of time by writing this article, I would feel completely vindicated. Please comment below if you feel this has helped you or if you have any questions.