How TO Archives - COBRA softwares
20 Jul

Tutorial: Installing a LAMP Web Server on Amazon Linux

The following procedures help you install the Apache web server with PHP and MySQL support on your Amazon Linux instance (sometimes called a LAMP web server or LAMP stack). You can use this server to host a static website or deploy a dynamic PHP application that reads and writes information to a database.

Prerequisites

This tutorial assumes that you have already launched an instance with a public DNS name that is reachable from the Internet. For more information, see Step 1: Launch an Instance. You must also have configured your security group to allow SSH (port 22),HTTP (port 80), and HTTPS (port 443) connections. For more information about these prerequisites, see Setting Up with Amazon EC2.

Important

If you are trying to set up a LAMP web server on an Ubuntu instance, this tutorial will not work for you. These procedures are intended for use with Amazon Linux. For more information about other distributions, see their specific documentation. For information about LAMP web servers on Ubuntu, see the Ubuntu community documentation ApacheMySQLPHPtopic.

To install and start the LAMP web server on Amazon Linux

  1. Connect to your instance.
  2. To ensure that all of your software packages are up to date, perform a quick software update on your instance. This process may take a few minutes, but it is important to make sure you have the latest security updates and bug fixes.

    Note

    The -y option installs the updates without asking for confirmation. If you would like to examine the updates before installing, you can omit this option.

    [ec2-user ~]$ sudo yum update -y
  3. Now that your instance is current, you can install the Apache web server, MySQL, and PHP software packages. Use the yum install command to install multiple software packages and all related dependencies at the same time.
    [ec2-user ~]$ sudo yum install -y httpd24 php56 mysql55-server php56-mysqlnd
  4. Start the Apache web server.
    [ec2-user ~]$ sudo service httpd start
    Starting httpd:                                            [  OK  ]
  5. Use the chkconfig command to configure the Apache web server to start at each system boot.
    [ec2-user ~]$ sudo chkconfig httpd on

    Tip

    The chkconfig command does not provide any confirmation message when you successfully enable a service. You can verify thathttpd is on by running the following command.

    [ec2-user ~]$ chkconfig --list httpd
    httpd           0:off   1:off   2:on    3:on    4:on    5:on    6:off

    Here, httpd is on in runlevels 2, 3, 4, and 5 (which is what you want to see).

  6. Test your web server. In a web browser, enter the public DNS address (or the public IP address) of your instance; you should see the Apache test page. You can get the public DNS for your instance using the Amazon EC2 console (check the Public DNS column; if this column is hidden, choose Show/Hide and selectPublic DNS).

    Tip

    If you are unable to see the Apache test page, check that the security group you are using contains a rule to allow HTTP (port 80) traffic. For information about adding an HTTP rule to your security group, see Adding Rules to a Security Group.

    Important

    If you are not using Amazon Linux, you may also need to configure the firewall on your instance to allow these connections. For more information about how to configure the firewall, see the documentation for your specific distribution.

    apache_test_page2.4Note

    This test page appears only when there is no content in/var/www/html. When you add content to the document root, your content appears at the public DNS address of your instance instead of this test page.

Apache httpd serves files that are kept in a directory called the Apache document root. The Amazon Linux Apache document root is /var/www/html, which is owned by root by default.

[ec2-user ~]$ ls -l /var/www
total 16
drwxr-xr-x 2 root root 4096 Jul 12 01:00 cgi-bin
drwxr-xr-x 3 root root 4096 Aug  7 00:02 error
drwxr-xr-x 2 root root 4096 Jan  6  2012 html
drwxr-xr-x 3 root root 4096 Aug  7 00:02 icons

To allow ec2-user to manipulate files in this directory, you need to modify the ownership and permissions of the directory. There are many ways to accomplish this task; in this tutorial, you add a www group to your instance, and you give that group ownership of the /var/www directory and add write permissions for the group. Any members of that group will then be able to add, delete, and modify files for the web server.

To set file permissions

  1. Add the www group to your instance.
    [ec2-user ~]$ sudo groupadd www
  2. Add your user (in this case, ec2-user) to the www group.
    [ec2-user ~]$ sudo usermod -a -G www ec2-user

    Important

    You need to log out and log back in to pick up the new group. You can use the exit command, or close the terminal window.

  3. Log out and then log back in again, and verify your membership in the wwwgroup.
    1. Log out.
      [ec2-user ~]$ exit
    2. Reconnect to your instance, and then run the following command to verify your membership in the www group.
      [ec2-user ~]$ groups
      ec2-user wheel www
  4. Change the group ownership of /var/www and its contents to the www group.
    [ec2-user ~]$ sudo chown -R root:www /var/www
  5. Change the directory permissions of /var/www and its subdirectories to add group write permissions and to set the group ID on future subdirectories.
    [ec2-user ~]$ sudo chmod 2775 /var/www
    [ec2-user ~]$ find /var/www -type d -exec sudo chmod 2775 {} \;
  6. Recursively change the file permissions of /var/www and its subdirectories to add group write permissions.
    [ec2-user ~]$ find /var/www -type f -exec sudo chmod 0664 {} \;

Now ec2-user (and any future members of the www group) can add, delete, and edit files in the Apache document root. Now you are ready to add content, such as a static website or a PHP application.

(Optional) Secure your web server

A web server running the HTTP protocol provides no transport security for the data that it sends or receives. When you connect to an HTTP server using a web browser, the URLs that you enter, the content of web pages that you receive, and the contents (including passwords) of any HTML forms that you submit are all visible to eavesdroppers anywhere along the network pathway. The best practice for securing your web server is to install support for HTTPS (HTTP Secure), which protects your data with SSL/TLS encryption.

For information about enabling HTTPS on your server, see Tutorial: Configure Apache Web Server on Amazon Linux to use SSL/TLS.

To test your LAMP web server

If your server is installed and running, and your file permissions are set correctly, yourec2-user account should be able to create a simple PHP file in the /var/www/htmldirectory that will be available from the Internet.

  1. Create a simple PHP file in the Apache document root.
    [ec2-user ~]$ echo "<?php phpinfo(); ?>" > /var/www/html/phpinfo.php

    Tip

    If you get a “Permission denied” error when trying to run this command, try logging out and logging back in again to pick up the proper group permissions that you configured in To set file permissions.

  2. In a web browser, enter the URL of the file you just created. This URL is the public DNS address of your instance followed by a forward slash and the file name. For example:
    http://my.public.dns.amazonaws.com/phpinfo.php

    You should see the PHP information page:

    phpinfo5.6.6Note

    If you do not see this page, verify that the/var/www/html/phpinfo.php file was created properly in the previous step. You can also verify that all of the required packages were installed with the following command (the package versions in the second column do not need to match this example output):

    [ec2-user ~]$ sudo yum list installed httpd24 php56 mysql55-server php56-mysqlnd
    Loaded plugins: priorities, update-motd, upgrade-helper
    959 packages excluded due to repository priority protections
    Installed Packages
    httpd24.x86_64                          2.4.16-1.62.amzn1                    @amzn-main
    mysql55-server.x86_64                   5.5.45-1.9.amzn1                     @amzn-main
    php56.x86_64                            5.6.13-1.118.amzn1                   @amzn-main
    php56-mysqlnd.x86_64                    5.6.13-1.118.amzn1                   @amzn-main

    If any of the required packages are not listed in your output, install them with the sudo yum install package command.

  3. Delete the phpinfo.php file. Although this can be useful information to you, it should not be broadcast to the Internet for security reasons.
    [ec2-user ~]$ rm /var/www/html/phpinfo.php

To secure the MySQL server

The default installation of the MySQL server has several features that are great for testing and development, but they should be disabled or removed for production servers. The mysql_secure_installation command walks you through the process of setting a root password and removing the insecure features from your installation. Even if you are not planning on using the MySQL server, performing this procedure is a good idea.

  1. Start the MySQL server.
    [ec2-user ~]$ sudo service mysqld start
    Initializing MySQL database:  Installing MySQL system tables...
    OK
    Filling help tables...
    OK
    
    To start mysqld at boot time you have to copy
    support-files/mysql.server to the right place for your system
    
    PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
    ...
    
    Starting mysqld:                                           [  OK  ]
    
  2. Run mysql_secure_installation.
    [ec2-user ~]$ sudo mysql_secure_installation
    1. When prompted, enter a password for the root account.
      1. Enter the current root password. By default, the root account does not have a password set, so press Enter.
      2. Type Y to set a password, and enter a secure password twice. For more information about creating a secure password, seehttp://www.pctools.com/guides/password/. Make sure to store this password in a safe place.

        Note

        Setting a root password for MySQL is only the most basic measure for securing your database. When you build or install a database-driven application, you typically create a database service user for that application and avoid using the root account for anything but database administration.

    2. Type Y to remove the anonymous user accounts.
    3. Type Y to disable remote root login.
    4. Type Y to remove the test database.
    5. Type Y to reload the privilege tables and save your changes.
  3. (Optional) Stop the MySQL server if you do not plan to use it right away. You can restart the server when you need it again.
    [ec2-user ~]$ sudo service mysqld stop
    Stopping mysqld:                                           [  OK  ]
  4. (Optional) If you want the MySQL server to start at every boot, enter the following command.
    [ec2-user ~]$ sudo chkconfig mysqld on

You should now have a fully functional LAMP web server. If you add content to the Apache document root at /var/www/html, you should be able to view that content at the public DNS address for your instance.

(Optional) Install phpMyAdmin

phpMyAdmin is a web-based database management tool that you can use to view and edit the MySQL databases on your EC2 instance. Follow the steps below to install and configure phpMyAdmin on your Amazon Linux instance.

Important

We do not recommend using phpMyAdmin to access a LAMP server unless you have enabled SSL/TLS in Apache; otherwise, your database administrator password and other data will be transmitted insecurely across the Internet. For information about configuring a secure web server on an EC2 instance, see Tutorial: Configure Apache Web Server on Amazon Linux to use SSL/TLS.

  1. Enable the Extra Packages for Enterprise Linux (EPEL) repository from the Fedora project on your instance.
    [ec2-user ~]$ sudo yum-config-manager --enable epel
  2. Install the phpMyAdmin package.
    [ec2-user ~]$ sudo yum install -y phpMyAdmin

    Note

    Answer y to import the GPG key for the EPEL repository when prompted.

  3. Configure your phpMyAdmin installation to allow access from your local machine. By default, phpMyAdmin only allows access from the server that it is running on, which is not very useful because Amazon Linux does not include a web browser.
    1. Find your local IP address by visiting a service such as whatismyip.com.
    2. Edit the /etc/httpd/conf.d/phpMyAdmin.conf file and replace the server IP address (127.0.0.1) with your local IP address with the following command, replacing your_ip_address with the local IP address that you identified in the previous step.
      [ec2-user ~]$ sudo sed -i -e 's/127.0.0.1/your_ip_address/g' /etc/httpd/conf.d/phpMyAdmin.conf
  4. Restart the Apache web server to pick up the new configuration.
    [ec2-user ~]$ sudo service httpd restart
    Stopping httpd:                                            [  OK  ]
    Starting httpd:                                            [  OK  ]
  5. In a web browser, enter the URL of your phpMyAdmin installation. This URL is the public DNS address of your instance followed by a forward slash andphpmyadmin. For example:
    http://my.public.dns.amazonaws.com/phpmyadmin

    You should see the phpMyAdmin login page:

    phpmyadmin_loginNote

    If you get a 403 Forbidden error, verify that you have set the correct IP address in the /etc/httpd/conf.d/phpMyAdmin.conffile. You can see what IP address the Apache server is actually getting your requests from by viewing the Apache access log with the following command:

    [ec2-user ~]$ sudo tail -n 1 /var/log/httpd/access_log | awk '{ print $1 }'
    205.251.233.48

    Repeat Step 3.b, replacing the incorrect address that you previously entered with the address returned here; for example:

    [ec2-user ~]$ sudo sed -i -e 's/previous_ip_address/205.251.233.48/g' /etc/httpd/conf.d/phpMyAdmin.conf

    After you’ve replaced the IP address, restart the httpd service withStep 4.

  6. Log into your phpMyAdmin installation with the root user name and the MySQL root password you created earlier. For more information about usingphpMyAdmin, see the phpMyAdmin User Guide.
Share this
18 Jul

How to build privacy based search extension for Opera in a few minutes

This article presents a way to create a privacy based search extension for the Opera Web browser in 10 minutes. Like Mozilla Firefox and Google Chrome, it is a freeware Web browser developed by Opera Software. It is available for Microsoft Windows, OSX and Linux operating systems and also for mobile devices running on Android, iOS, Windows Phone, Symbian, Maemo, Bada, BlackBerry and Java ME compatible mobile devices.
The Opera Web browser has some great features, which are listed below.

Usability and accessibility: Opera provides keyboard shortcuts to control various aspects of the browser. As an example, page zooming allows text and media content such as Adobe Flash Player, scalable vector graphics and images to be increased and decreased in size to help users with vision impairment to see them better. Also, Opera has the Turbo mode which, when enabled, compresses Web pages by up to 70-80 per cent, based on content, before sending them to the user. This is done to make Web pages load faster for users with slower Internet connections. This technique is specially used in Opera Mini for mobile devices.

Standard support: Opera is based on the V8 and Blink layout engine, so Web standards support of Opera is similar to Google Chrome. Also, Opera was one of the first browsers to support CSS (Cascading Style Sheets).

Native ad blocker: This blocks ads with a built-in ad blocker when enabled. Currently, this feature is only available on the Opera Beta 37 version and above.

Privacy and security: One of the key security features of Opera is the option to delete private data, such as cookies, browsing history and cache with a click of a button. Another great security feature is that Opera displays a security badge in the address bar, which specifies important security details about websites you visit, such as security certificates. It checks whether the visited website is blacklisted for phishing or malware and displays a warning message if it’s on the blacklist.
On April 20, 2016, Opera became the first major browser maker to integrate an unlimited and free VPN (Virtual Private Network). Now, if you use Opera browser, you don’t have to download the VPN extension/add-on or pay for any VPN subscription to secure your online browsing activity on public Wi-Fi.
With a free, unlimited, native VPN that doesn’t require any subscription fee, Opera wants to make VPNs available to everyone, and provide privacy and security.

What are Opera extensions?
Opera extensions are code packages that you can add to your Opera Web browser to extend its functionality. The Opera extension API provides functions to explore different features of the Web browser by giving you a variety of options for the extension functionality. If you have already developed extensions for Google Chrome, then you will encounter some similar steps and procedures while developing extensions for Opera. Since Opera is based on Chromium, a majority of core internal functionalities are similar to the Google Chrome Web browser, which means it is possible to run some of the Chrome extensions on Opera.
Now, let us create a privacy based search extension for the Opera Web browser.

Why do we require privacy on search?
When we perform a search on search engines and click on our search results, our search terms or key words are sent to the website we clicked on (via an HTTP referrer header). This concept of sharing personal information is called ‘search leakage’. In simple words, when we search for something private, we are sharing that private search information with our search engine as well as with the websites that we clicked on for that search. Also, when we visit any website after that, our computer automatically sends important information about the websites we visited along with our IP address and user agent, to that clicked website. So, basically, when we perform a search, other websites know our search terms and they also know that we searched for them.
Some search engines save our history, along with the date and time of the search, as well as some important computer information such as our user agent, IP address or our account information (name and login information, if we are logged in).
This availability of information about us does raise some privacy concerns. Thankfully, there are some search engines that avoid these privacy and security problems. The three most popular ones are listed here.

DuckDuckGo: This is one of the most popular Internet search engines, with its main motto being to protect searchers’ privacy and to avoid the creation of personalised search results for users. DuckDuckGo puts privacy first and does not log user information such as IP addresses, etc. It also provides full protection from search leakage.

Encrypted Google: This uses SSL (Secured Socket Layer), which encrypts the connection between your computer and Google. This basically prevents and protects it from others, like Internet service providers and public Wi-Fi hotspots, from seeing your search results page and other vital information.

Ixquick: This lets you search privately using your favourite search engines. It gathers results from all major search engines. It adds an extra security layer between you and your search engines, which means search engines will see search requests coming from Ixquick and not the end user. This makes the user’s search requests practically anonymous to the main search engine. Ixquick does not log search terms, IP addresses or any other personal information about users.
So now, let us develop an extension, which will allow a user to search any highlighted text or word, on the DuckDuckGo, Encrypted Google and Ixquick search engines.

Developing an extension
We are now going to develop a user-friendly and useful privacy based search extension. Let us call it the ‘Privacy Search’ extension, which will allow the user to search any highlighted word on one of these privacy based search engines—duckduckgo.com, encrypted.google.com and ixquick.com. Users will highlight the word they wish to search in the Web browser, then will right-click the highlighted word and select the ‘Privacy Search’ option from the context menu. Following this, three sub-menu options will be displayed: ‘Search on DuckDuckGo for..’, ‘Search on Encrypted Google for..’ and ‘Search on Ixquick for..’ Users will select and click on any one of these sub-menu options, depending on which search engine they want to use. After doing this, users will be redirected to the highlighted word’s search results page, opened in a new tab.
We are going to use the following Web technologies:

  • JSON to create a manifest file
  • JavaScript for the logic

Setting up the development environment
Let us set up a file structure for our extension, and create a new folder with any name on the computer. In our case,C:\privacysearch is the extension’s folder. Now, inside that new folder, create a folder called ‘images’. In the root directory of our extension folder, create an empty text file using Notepad and save it with the .json extension calledmanifest.json and also create an empty JavaScript file called background.js.
You should end up with the following directory structure:

  • images\
  • manifest.json
  • background.js

Description
The directory containing icons or images is called images, which we will be using in our extension.
manifest.json is a metadata file in JSON format that contains basic properties like the extension’s name, description, version number, etc.
background.js is a JavaScript file containing the search logic for the extension.

Adding icons or images to our extension
In this step, we are going to add an icon to our option in the context menu. Visithttp://www.flaticon.com/search/magnifier and download any one icon, preferably in .png format, and of size 16×16 pixels. Copy it to the images folder located in our extension’s folder and rename that image to ‘search.png’.

Creating the manifest file
Open the manifest.json file with your favourite code editor or Notepad and copy the following JSON code:

{
“manifest_version”: 2,
“name”: “Privacy Search”,
“description”: “This addon searches highlighted text, on selected top three privacy search websites.”,
“version”: “1.0”,
“background”: {“scripts”: [“background.js”]},
“icons”: { “16”: “images/search.png”},
“permissions”: [“contextMenus”, “tabs”]
}

The code is written in JSON format (Key: Value pair). It consists of all basic information about the extension such as its name, description, version, images, icons used, permissions required and so on.

Parameter description

  • ‘manifest_version’ specifies the version of the manifest; the value must be 2.
  • ‘name’ specifies the name of the extension.
  • ‘description’ specifies a short description of the extension.
  • ‘version’ specifies the version of the extension.
  • ‘background’ specifies that script ‘background.js’ loads as soon as the user starts the Opera browser.
  • ‘icons’ specifies the location of the icons or images, which we are going to use in our extension.
  • ‘permission’ specifies which Opera extension APIs are to be used. We are using contextMenus and tabs.

Adding JavaScript
Now, open the background.js file in your favourite code editor or Notepad and copy the following JavaScript code:

var parent = chrome.contextMenus.create({
title: “Privacy Search on..”,
contexts: [“selection”]
});
chrome.contextMenus.create({
title: “Search on DuckDuckGo for: \”%s\””,
parentId: parent,
contexts: [“selection”],
onclick: searchTextDuckDuckGo
});
chrome.contextMenus.create({
title: “Search on Encrypted Google for: \”%s\””,
parentId: parent,
contexts: [“selection”],
onclick: searchTextGoogle
});
chrome.contextMenus.create({
title: “Search on Ixquick for: \”%s\””,
parentId: parent,
contexts: [“selection”],
onclick: searchTextIxquick
});
function searchTextDuckDuckGo(info){
var myQuery = encodeURI(“https://duckduckgo.com/?q=”+info.selectionText);
chrome.tabs.create({url: myQuery});
}
function searchTextGoogle(info){
var myQuery = encodeURI(“https://encrypted.google.com/#q=”+info.selectionText);
chrome.tabs.create({url: myQuery});
}
function searchTextIxquick(info){
var myQuery = encodeURI(“https://ixquick.com/do/search?q=”+info.selectionText);
chrome.tabs.create({url: myQuery});
}

The first four functions are for creating a UI for our extension. Since we are providing options in the context menu, we will use contextMenus.create() function to create a customised context menu. This function has some key:value parameters such as title and contexts; the most important one is the event – which specifies what must be done when certain browser based events occur, i.e., calling some function. In our case, we are creating a parent menu called ‘Privacy Search on..’ using the first function, and sub-menu options called ‘Search on DuckDuckGo for:’, ‘Search on Encrypted Google for:’ and ‘Search on Ixquick for:’ using the next three functions.

When users click or select one of these sub-menu options, a specified function is called. For example, when users click the ‘Search on DuckDuckGo for:’ option, the searchTextDuckDuckGo() function is called. The ‘searchTextDuckDuckGo’ function gets the value of the element ‘info.selectionText’; it is appended with the URL of the DuckDuckGo search engine and is stored in a variable named myQuery, which then loads in a new tab with the search results.

That’s it with the coding part; now let us load and test the extension.

Loading and installing the extension
In the Opera Web browser, extensions are packaged as .nex files. You can do this by going through the following steps.

Type ‘opera:extensions’ in the address bar of an Opera browser and press Enter or the Ctrl+Shift+e keys.

Click the ‘Developer Mode’ option located on the top right to enable it. By doing this, you get the ability to inspect various parts of the extension using the browser’s developer tools. Besides, you can make changes to your extension’s code and also preview the effects by using the reload button.

You will get two options, ‘Load unpacked extension’ and ‘Pack Extension’, as shown in Figure 1.
With the ‘Load unpacked extension’ option, you can navigate to the directory where your extension files are, and select that extension folder. This loads the extension.
With the ‘Pack extension’ option, you can select your extension folder and package it in a .nex file.

After creating the .nex file, just drag and drop it in the Opera browser to install it.

Running the extension in the Opera Web browser
After installing/loading the extension, you can test it by highlighting some text and then selecting the ‘Privacy Search on..’ option and any one of the sub-menu options, from the right click context menu. For example, we tested the extension by highlighting the word ‘JavaScript’ on http://opensourceforu.efytimes.com/ and then selected the ‘Search on DuckDuckGo for:’ sub-menu option from the ‘Privacy Search on..’ option in the right click context menu, as shown in Figure 2. This opened the DuckDuckGo search results for ‘JavaScript’ in a new tab in the Opera browser, as shown in Figure 3.

Figure-2-6Figure-3-5Figure-1-9

Share this

© 2015-2020 COBRA Softwares Pvt Ltd. All rights reserved.