Showing posts with label apache. Show all posts
Showing posts with label apache. Show all posts

Sunday, February 12, 2012

Installing Rails 3.1.1, ruby 1.9.3, apache2, Passenger and Mysql on Ubuntu 11.10

To install Rails 3.1 on  fresh Ubuntu 11.10 I followed the following steps.


Note:
Currently I am running Ubuntu on a Virtual Machine (VMware Player )


Step 1: Install  libYAML from source
cd /usr/src
sudo wget http://pyyaml.org/download/libyaml/yaml-0.1.4.tar.gz
sudo tar xvzf yaml-0.1.4.tar.gz
cd yaml-0.1.4
sudo ./configure --prefix=/usr/local
sudo make 
sudo make install


Step 2: Install  required libraries
 sudo apt-get install libxml2-dev libxslt-dev libzlib1g zlib1g-dev build-essential openssl libssl-dev libmysqlclient16-dev


Step:3 Install ruby  from source file
cd /usr/src
sudo wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p0.tar.gz
sudo tar xvzf ruby-1.9.3-p0.tar.gz
cd ruby-1.9.3-p0
sudo ./configure --prefix=/usr/local --enable-shared --disable-install-doc --with-opt-dir=/usr/local/lib
sudo make
sudo make install


Step:4 Test proper ruby is installed
sudo ruby -v
The above command should display some thing as follows
ruby 1.9.3p0 (2011-10-30 revision 33570) [i686-linux]


Step 5: Install ruby gem
cd /usr/src 
sudo wget http://rubyforge.org/frs/download.php/75475/rubygems-1.8.11.tgz
sudo tar xvzf rubygems-1.8.11.tgz
cd rubygems-1.8.11
sudo ruby setup.rb


Step 6: Install Mysql server and Mysql client
sudo apt-get install mysql-server-5.1 mysql-client-5.1

Step 7: Install rails
sudo gem install rails


Step 8: Install apache2
sudo apt-get install apache2


Step 9: Install passenger
cd /usr/src 
sudo wget http://rubyforge.org/frs/download.php/75337/passenger-3.0.9.tar.gz
sudo tar xvzf  passenger-3.0.9.tar.gz
cd passenger-3.0.9
sudo ./bin/passenger-install-apache2-module  
Follow the instruction provided by the installer and restart the apache


Step 10: Install Node.js 
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs-dev


Step 11: Install readline library 
sudo apt-get install libreadline6-dev
cd /usr/src/ruby-1.9.3-p0/ext/readline
sudo ruby extconf.rb
sudo make
sudo make install


Step 12: Testing rails application
 a. create a new rails project. My project directory is /var/projects
     cd /var/projects
   sudo rails new demo --database=mysql
 b. create mysql database
     sudo mysql -u root -p 
     It prompts mysql password and provide the one which you provide at the time of
      installing Mysql server
     mysql> create database demo_developement;
  mysql> exit


c. Install  vim editor (optional) if  you are fond of vim
    sudo apt-get install vim vim-rails


 d. Update database.yml file
     cd /var/projects/demo
      Open database.yml and update 'password' attribute by using following command
      sudo vim config/database.yml


 e. Update apache configuration file and  update the virtual host entry shown below and restart
    sudo vim /etc/apache2/sites-enabled/000-default


  <VirtualHost *:80>
      ServerName localhost
      DocumentRoot /var/projects/demo/public
      RailsEnv development
      <Directory /var/projects/demo/public>
         AllowOverride all
         Options -MultiViews
      </Directory>
   </VirtualHost>
  sudo /etc/init.d/apache2 restart
f. Create log files
  sudo touch /var/projects/demo/log/development.log

Note:
1. You may get permission denied error something like
    "Permission denied - /var/projects/demo/tmp/cache/assets/CF0"
    To resolve this just give read and write permission for this folder. You can use the following command for   
     development environment
    sudo chmod 777 /var/projects/demo/tmp/cache/assets

2. To view apache log files you can use the following command
  sudo tail -f /var/log/apache2/error.log -n 100
     where "-n 100" denotes last 100 lines of error.log file

3. For installing Rails using RVM follow this blog


Reference:

Sunday, February 5, 2012

Multiple virtual hosts with Apache (on windows)

Creating multiple virtual hosts using apache is so common, you may find making it so easy and straight forward on Linux or even Mac, but believe me it is not the case with Windows !​


   Here is the deal, the idea behind how to make this is to give another IP for your new host, and make apache listen on that IP, let's do it:

Step 1: add your new host in the hosts file under "C:\Windows\System32\drivers\etc​" and assign new IP to it:
  1. 127.0.0.1       localhost  
  2. 127.0.0.2       mysite.com  
Step 2: make your apache server listens on the new IP by modifying httpd.conf file in the "apache\conf" folder, put the following in the Listen section:
  1. Listen 80  
  2. Listen 127.0.0.2:80  
Step 3: and finally, open "apache\conf\extra\httpd-vhosts.conf" and add your new virtual hosts like this:
  1. <virtualhost mysite.com:80>
  2. DocumentRoot "absolute_location_to_mysite_public_folder"
  3. ServerName Boston.com
  4. ServerAlias boston.com
  5. <directory "absolute_location_to_mysite_public_folder">
  6. AllowOverride All
  7. Options Indexes FollowSymLinks
  8. Order allow,deny
  9. Allow from all
  10. </directory>
  11. </virtualhost>

  12. <virtualhost localhost:80>
  13. DocumentRoot "apache_htdocs_folder"
  14. ServerName localhost
  15. ServerAlias localhost
  16. <directory "apache_htdocs_folder">
  17. AllowOverride All
  18. Options Indexes FollowSymLinks
  19. Order allow,deny
  20. Allow from all
  21. </directory>
  22. </virtualhost>








Finally, you can use the two hosts in your browser:
  • localhost
  • mysite.com

Apache manual installation on windows


Manual Installation

Manual installation offers several benefits:
  • backing up, reinstalling, or moving the web server can be achieved in seconds (see 8 Tips for Surviving PC Failure)
  • you have more control over how and when Apache starts
  • you can install Apache anywhere, such as a portable USB drive (useful for client demonstrations).
Step 1: configure IIS, Skype and other software (optional)
If you have a Professional or Server version of Windows, you may already have IIS installed. If you would prefer Apache, either remove IIS as a Windows component or disable its services.
Apache listens for requests on TCP/IP port 80. The default installation of Skype also listens on this port and will cause conflicts. To switch it off, start Skype and choose Tools > Options > Advanced > Connection. Ensure you untick “Use port 80 and 443 as alternatives for incoming connections”.
Step 2: download the files
We are going to use the unofficial Windows binary from Apache Lounge. This version has performance and stability improvements over the official Apache distribution, although I am yet to notice a significant difference. However, it is provided as a manually installable ZIP file from www.apachelounge.com/download/
You should also download and install the Windows C++ runtime from Microsoft.com. You may have this installed already, but there is no harm installing it again.
As always, remember to virus scan all downloads.
Step 2: extract the files
We will install Apache in C:\Apache2, so extract the ZIP file to the root of the C: drive.
Apache can be installed anywhere on your system, but you will need to change the configuration file paths accordingly…
Step 3: configure Apache
Apache is configured with the text file \conf\httpd.conf contained in the Apache folder. Open it with your favourite text editor.
Note that all file path settings use a ‘/’ forward-slash rather than the Windows backslash. If you installed Apache anywhere other than C:\Apache2, now is a good time to search and replace all references to “c:/Apache2″.
There are several lines you should change for your production environment:
Line 46, listen to all requests on port 80:
  1. Listen *:80  
Line 116, enable mod-rewrite by removing the # (optional, but useful):
  1. LoadModule rewrite_module modules/mod_rewrite.so  
Line 172, specify the server domain name:
  1. ServerName localhost:80  
Line 224, allow .htaccess overrides:
  1. AllowOverride All  
Step 4: change the web page root (optional)
By default, Apache return files found in its htdocs folder. I would recommend using a folder on an another drive or partition to make backups and re-installation easier. For the purposes of this example, we will create a folder called D:\WebPages and change httpd.conf accordingly:
Line 179, set the root:
  1. DocumentRoot "D:/WebPages"  
and line 204:
  1. <Directory "D:/WebPages">  
Step 5: test your installation
Your Apache configuration can now be tested. Open a command box (Start > Run > cmd) and enter:
  1. cd \Apache2\bin  
  2. httpd -t  
Correct any httpd.conf configuration errors and retest until none appear.
Step 6: install Apache as a Windows service
The easiest way to start Apache is to add it as a Windows service. From a command prompt, enter:
  1. cd \Apache2\bin  
  2. httpd -k install  
Open the Control Panel, Administrative Tools, then Services and double-click Apache2.2. Set the Startup type to “Automatic” to ensure Apache starts every time you boot your PC.
Alternatively, set the Startup type to “Manual” and launch Apache whenever you choose using the command “net start Apache2.2″.
Step 7: test the web server
Create a file named index.html in Apache’s web page root (either htdocs or D:\WebPages) and add a little HTML code:
  1. <html>  
  2. <head><title>testing Apache</title></head>  
  3. <body><p>Apache is working!</p></body>  
  4. </html>  
Ensure Apache has started successfully, open a web browser and enter the address http://localhost/. If all goes well, your test page should appear.

In general, most problems will be caused by an incorrect setting in the httpd.conf configuration file. Refer to the Apache documentation if you require further information.

Rererence:
http://www.sitepoint.com/how-to-install-apache-on-windows/​