Blog

How to load mod_wsgi module in Apache

To install mod_wsgi, follow this link

After the installation of a module into “module” directory of Apache’s, we still need to load it into Apache’s configuration file.

Here are the steps

  1. Open Apache’s configuration file. You can find it in {root_directory_of_apache}/conf/ directory, with the name httpd.conf.
  2. Go to that place in the configuration file where other Apache’s modules are loaded.
  3. Add line
    LoadModule wsgi_module modules/mod_wsgi.so

    at the end of that section.

  4. Save the file.
  5. Restart Apache. Look here to how to do it.

If everything is alright, you’ll see the following line in {root_directory_of_apache}/logs/error_log file

Apache/2.4.23 (Unix) mod_wsgi/4.5.7 Python/2.7 configured

It is recommended that before proceeding you get a simple WSGI application running. Follow this link for that.

Note: Add a server name first for an ip in /etc/hosts.
Note: There some changes to be made in the code provided in the configuration link. Within both the directory tags, include the following

AllowOverride none
Require all granted

Install mod_wsgi in Ubuntu

I am following this link
http://modwsgi.readthedocs.io/en/develop/user-guides/quick-installation-guide.html

Here are the steps to install mod_wsgi

  1. Download the source code of the latest version from https://github.com/GrahamDumpleton/mod_wsgi/releases.
  2. Extract it using
    tar xvfz mod_wsgi-{version}.tar.gz
  3. Configure the source code using
    ./configure --with-apxs=/usr/local/apache/bin/apxs --with-python=/usr/local/lib/python2.7.12/bin/python

    Note: I have given that path for apxs and python because I have installed my apache at /usr/local/apache/ and python at /usr/local/lib/python2.7.12. If you have other paths, feed it that.

  4. Execute
    make

    and then

    sudo make install

mod_wsgi is now installed and you can find its .so file at {path_to_apache}/modules/, e.g. /usr/local/apache/modules/.

Installing/Uninstalling MySQL using MySQL APT Repository in Ubuntu

I am following these links:

  1. http://dev.mysql.com/downloads/repo/apt/
  2. http://dev.mysql.com/doc/mysql-apt-repo-quick-guide/en/

For more info, check them out.

Installing MySQL products using apt repository is a very simple and convenient way.

Fresh Installation of MySQL

Note: The following steps assume that no version of MySQL whatsoever have already been installed in the system.

  1. First you need to add MySQL APT repository to your system’s software repository list.
    • Go to http://dev.mysql.com/downloads/repo/apt/.
    • Scroll down and download the release package for your Linux distribution i.e. mysql-apt-config_{version}_all.deb.
    • Go to the directory where you have downloaded it and execute
      sudo dpkg -i mysql-apt-config_{version}_all.deb
    • During the installation of the package, you’ll be asked to choose the versions of the MySQL server and other components. Just choose OK, if you don’t know which version to install.
    • Now do
      sudo apt-get update

    Note: Once the MySQL APT repository is enabled on your system, you will no longer be able to install any MySQL package from your platform’s native software repository until the MySQL APT repository is disabled.

  2. Install MySQL using APT.
    • Execute
      sudo apt-get install mysql-server

    Note: You’ll be asked to supply a password for the root user. If you don’t wanna give any password, just click OK. You can set the root password later using mysql_secure_installation.

  3. Starting and Stopping the MySQL Server
    • To check the status of MySQL server, execute
      sudo service mysql status
    • To stop the MySQL Server, execute
      sudo service mysql stop
    • To start the MySQL Server, execute
      sudo service mysql start

Login into MySQL Server

Use

mysql -u root -p

You will then be asked to enter your password.

Exit from MySQL Server

Use

exit

or

Ctrl+Z

Removing MySQL with APT

To uninstall MySQL server and the related components have been installed using the MySQL APT repository, first remove the MySQL server using the following command

sudo apt-get remove mysql-server

Then, remove any other software that was installed automatically with the MySQL server using

sudo apt-get autoremove

To uninstall other components, use

sudo apt-get remove {package-name}

To see the list of packages installed through MySQL APT repository

dpkg -l | grep mysql | grep ii

To install additional MySQL Products and Components

  1. Update first
    sudo apt-get update
  2. Then,
    sudo apt-get install {package-name}

This is the list of the packages.

How to set an Environment variable in Ubuntu

Read First-

  1. https://www.digitalocean.com/community/tutorials/how-to-read-and-set-environmental-and-shell-variables-on-a-linux-vps

Few definitions

  1. Environment Variables : are variables that are defined for the current shell and are inherited by any child shells or processes. Environmental variables are used to pass information into processes that are spawned from the shell.
  2. Shell Variables: are variables that are contained exclusively within the shell in which they were set or defined. They are often used to keep track of ephemeral data, like the current working directory.

Creating a Shell Variable

  • Type TRY_VAR=/this/is/test/variable in the shell.
  • Click Enter.

Your Shell variable is set.

To see the value of the variable

  • Type set | grep TRY_VAR or echo $TRY_VAR in the shell.
  • Click Enter.

Note: Defined shell variables exist as long as shell itself. If you close the current shell and try to access it through another shell, these defined variable would show up as empty. Keeping the current shell open and accessing the variable through a new shell tab would still show that defined variable as empty. However, default variables remain as they be. You can look at default shell variables using set command.

Creating environment variables through shell

  • Type export TRY_VAR=/this/is/test/variable in the shell.
  • Click Enter.

Your environment variable is set.

To see the value of the variable

  • Type printenv | grep TRY_VAR or echo $TRY_VAR in the shell.
  • Click Enter.

Note: Defined environment variables also exist as long as shell itself. But there is a difference. Read their definition mentioned above.

Creating environment variables every time on shell startup

  • Open .bashrc in your home directory using gedit ~/.bashrc.
  • Write export TRY_VAR=/this/is/test/variable at the end of the file.
  • Save and close the file.

Your environment variable is set every time on shell startup.

Manually Install Apache HTTP Server in Ubuntu

*(Read blog completely before doing anything)
I am following below-mentioned link. It also specifies the way to automatically install Apache.

https://www.mkyong.com/apache/how-to-install-apache-http-server-in-ubuntu/

Here it goes –

  1. Install Apache HTTP Server from https://httpd.apache.org/download.cgi . I am using version 2.4.23.
  2. Open the terminal, go to the place where you have downloaded  tar.gz file and unzip it using
    tar xvfz httpd-2.4.23.tar.gz
  3. Enter into the extracted directory and run
    > ./configure --prefix=/usr/local/apache
    > make
    > sudo make install

    * I am not using --enable-shared=max option, which was told to follow in mkyong’s link.

  4. Your server is installed and files are located at /usr/local/apache.
  5. Command to start the server
    sudo /usr/local/apache/bin/apachectl -k start
  6. Command to stop the server
    sudo /usr/local/apache/bin/apachectl -k stop

For further info, visit http://httpd.apache.org/docs/2.4/.

Some useful commands

  • To get the view of the Apache Configurations, use

    /usr/local/apache/bin/apachectl -V
  • If you wish to make “prefork” or “worker” MPM server your default MPM server, add

    --with-mpm=prefork

    in the configure command and then follow rest of the step.

  • To know about the default installed modules(which you’ll find in “Optional Features” section in the following command’s result) and other things, use

    ./configure -h

Most common errors while executing the configure command –

  1. “APR” not found
    configure: error: APR not found.  Please read the documentation.

    where APR is Apache Portable Runtime. In this case, you have to do the following-

    • Go to http://apr.apache.org/download.cgi.
    • Download apr-.tar.gz and apr-util-.tar.gz.
    • Extract these compressed files into the directory http-2.4.23/scrlib/ . http-2.4.23 is the extracted directory of Apache HTTP Server.
    • Extracted directories will have names apr-{version} and apr-util-{version}. Change them to apr and apr-util respectively.
    • Now go to http-2.4.23 directory through terminal and  run the previous configure command with --with-included-apr option.
      ./configure --with-included-apr --prefix=/usr/local/apache 
  2. “libpcre” not found
    configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/

    PCRE is Perl-Compatible Regular Expressions. Do the following in this case.

    • Go to http://www.pcre.org/.
    • Then click on sourceforge’s link on that page.
    • Choose pcre.
    • Choose the version and then download the .tar.gz file.
    • Extract the file.
    • Go to the extracted directory through terminal.
    • Now execute the following commands
      > ./configure --prefix=/usr/local/pcre
      > make
      > sudo make install

      /usr/local/pcre is the place where pcre is installed

    • Go to the httpd-2.4.23 directory through terminal and  run the configure command for Apache HTTP server installation with --with-pcre= and also the option to include apr.
      ./configure --with-included-apr --with-pcre=/usr/local/pcre --prefix=/usr/local/apache 

Note – Last two errors wouldn’t show up if you wish to install version 2.2.31, as they provide it along with the package.

Python upgrade in Ubuntu

It’s not a good idea to replace default Python version from your system, because those programs which have dependency on that particular Python version wouldn’t work right after replacing it with newer version.

Instead you can create a latest Python’s virtual environment using virtualenv, for the program which require the higher version of Python.

There is a very nice article related to that. Please refer the below-mentioned mbless.de‘s link.

Important Note: While configuring the latest python, include --enable-shared option too. (Otherwise there will be problems while installing mod_wsgi.)

http://mbless.de/blog/2016/01/09/upgrade-to-python-2711-on-ubuntu-1404-lts.html

You can upgrade to Python 3.x.x, using the same method, but you’ll get an error like

error while loading shared libraries: libpython3.5m.so.1.0: cannot open shared object file: No such file or directory

To get through this, run python interpreter with this command

LD_LIBRARY_PATH=/usr/local/lib/python3.5.2/lib/ /usr/local/lib/python3.5.2/bin/python3

You can save yourself of including this piece of command every time you run python, by

export LD_RUN_PATH=/usr/local/lib/python3.5.2/lib/

and then do configure and make.

For more info, visit

http://stackoverflow.com/questions/37757314/problems-installing-python-3-with-enable-shared

Note:
To install virtualenv, use command sudo pip install virtualenv.

To activate the virtual environment, go to the directory where virtualenv is used, and execute source {virtual_environment_name}/bin/activate.

To deactivate, just execute deactivate

To install pip, refer the following link.

https://ksmanisite.wordpress.com/2016/10/03/install-pip-in-ubuntu/

 

Install pip in Ubuntu

pip is a tool for installing and managing python packages.

  1. Open Terminal through Ctrl+Alt+T
  2. Run sudo apt-get update and sudo apt-get upgrade
  3. Run sudo apt-get install python-pip

-To know the version of pip, execute pip -V.

-To locate the source or binary files for pip, execute whereis pip.

-You can also use which command. It returns the pathnames of the files(or links) which would be executed in the current environment. E.g. which pip.

-We can also use locate command, but it is like a keyword search, as it returns the path of all the files in whose name that keyword is found. E.g. locate pip.

Install Google Chrome in Ubuntu

  1. Download google chrome .deb  file from its official website.
  2. Open the terminal using Ctrl+Alt+T.
  3. Go to the location where you have downloaded the deb file.
  4. Use command sudo dpkg -i google-chrome-stable_current_amd64.deb

Note – Update first using sudo apt-get update and then sudo apt-get upgrade

SSH: A Short Guide!

Note – I am using a Mac system for this short guide.

  • SSH, Secure Shell, is used for establishing a secure connection to the remote system.
  • It incorporates various encryption method to ensure the safety of the sessions, or data to be transmitted.

Very basic command for ssh :

ssh username@hostname

username : The name with which the user has created the account in the remote system.

Note – To know the username of your system, use the UNIX command “whoami”.

 

hostname : It’s the remote system’s IP address or its name.

Note – To know the hostname of your system, use the UNIX command “hostname”.

 

Let’s start off with an example (I have used a dummy username and IP address in the following example)-

ssh abc@123.122.121.120

Before actually connecting to the system, you will be asked the following

The authenticity of host '123.122.121.120 (123.122.121.120)' can't be established.

ECDSA key fingerprint is SHA256:Ub/Y0zpHQZMbD2tzcS75U/IVdA/jh6U/qSZal/LbxUw.

Are you sure you want to continue connecting (yes/no)? 

By this step, host is validated. That means if you are logging into the system for the first time and you are sure this system is authentic, it is assigned an unique key and the information is stored in the following path –

~/.ssh/known_hosts

Why this step is important? Because SSH wants to make sure that you are connecting to the system which you think you are connecting to. If, later at some point of time, the hackers tries to trick you into logging into their spoofed machines to sniff your SSH session, it will throw a warning saying that the DNS spoofing is happening and it will not connect to that system.

Now, say yes to that first time question. It will ask for the remote system’s password, if there is any. Now, you have terminal access to your remote system.

 

If you are using a Mac system, you have to first enable remote sessions in Mac’s security settings. For that, do the following

Command+Space_Bar-->Type "Security Preference"-->Go to "Sharing"-->Check "Remote Login" option

Do the same with the remote system, if it is also Mac.

 

To end the remote sessions, use UNIX command “exit”.