Posts tagged ‘Apache’

How to make Apache handle. asp and .aspx links in FreeBSD or Linux? (Updated)

Ok, so what do you do when a site that was based on asp.net is converted to a Linux box and your product shipped with links to sites such as http://our.home.page/index.asp and many other .asp or aspx sites?

Should you use mono?
Yes, probably

See my mono post on Asp.Net here:

Asp.Net web services on FreeBSD and Apache using Mono

Should you migrate your code to php or ruby or another open source language?
Sure, maybe

If you choose not to go with mono at this point because it might be easy to re-write your code in php or ruby or any other open source language, especially if you are doing nothing more than echoing html code after performing simple calculations.

I haven’t tested it yet, but you may get a lot of the asp code automatically converted using this tool: asp2php

What about the fact that unchangeable links to my pages end with .asp or .aspx entensions?
It doesn’t matter what the file extension is, you can have that file extension handled by any scripting language. For example, to configure Apache to have php handle .asp or aspx file, you can follow the steps below.

If you have an index.asp file that should automatically be served by default, it is probably not in the list of files to serve by default, which is probably just index.htm and index.php. You can either rename index.asp to index.php or modify the httpd.conf to include the index.asp file. These steps assume you are changing the httpd.conf.

  1. Change to the apache configuration directory: /usr/local/etc/apache22/
  2. Edit the httpd.conf with ee.
    ee httpd.conf
  3. Search for “DirectoryIndex” to find the section where the directory index is configured.
  4. Add index.asp as the first item as shown:
    DirectoryIndex index.asp index.php index.html
  5. Change to the “Includes” directory which by default is here: /usr/local/etc/apache22/Includes
  6. Create a file that is named ending in .conf (For example, to show what the file does in the name, I used asp-as-php5.conf):
    # Handle .asp and .aspx with php
    AddType application/x-httpd-php .asp
    AddType application/x-httpd-php .aspx
  7. Restart apache. Now your .asp and .aspx files will be handled by php.

Copyright ® Rhyous.com – Linking to this page is allowed without permission and as many as ten lines of this page can be used along with this link. Any other use of this page is allowed only by permission of Rhyous.com.

How to install dotProject 2.1.2 on FreeBSD 7.2 with Apache 2.2, PHP5, and MySQL 5.1 Server?

How to install dotProject 2.1.2 on FreeBSD 7.2 with Apache 2.2, PHP5, and MySQL 5.1 Server?

The basic overview.

  1. Install FreeBSD.
    How do I install FreeBSD?
  2. Update FreeBSD and download the ports tree.
    What are the first commands I run after installing FreeBSD
  3. Then install Apache + SSL.
    Installing an Apache + SSL on FreeBSD using the ports tree
  4. Then install MySQL.
    How to install MySQL on FreeBSD 7.2 or on Red Hat 5.4?
  5. Configure MySQL to be Unicode.
    How to create a UTF-8 Unicode Database on MySQL and make UTF-8 Unicode the default?Note:
  6. Secure MySQL. I don’t have a post on this, but you can follow these MySQL pages.
    Securing the Initial MySQL Accounts
    General Security Guidelines

    Note: If you know what you are doing, you can go with any database that dotProject supports, such as Postgresql.

  7. Install PHP5and PHP5-Extensions and make sure to include the MySQL extensions and the LDAP extension.
  8. How to install PHP5 and PHP5 Extensions on FreeBSD?

  9. Then install DotProject

I have previous documents about installing each of the steps above installing dotProject. Once you have gone though the above documents, you will be ready for this document. This document will only cover dotProject.

Installing dotProject 2.1.2 from Ports

  1. Install dotProject from ports using one of the following commands (I use the first one when doing virtual hosts and the second one when just using sub directories of the web root).
    #
    #
    cd /usr/ports/www/dotproject
    make install

    Note: If you Apache directory is /usr/local/www/apache22/data you may want to use this make command:

    #
    #
    cd /usr/ports/www/dotproject
    make DOTPROJECTDIR=/usr/local/www/apache22/data/dotproject install

  2. Create a database in MySQL for dotProject. Name it whatever you want. For this example, I am going to name the database dotProjDB. If you have read the articles about MySQL that I referenced above, you should know how to log into to MySQL, but just in case you forgot, I will show you again.There are lots of ways to create a database in MySQL, and I am going to give you one example using the shell and the MySQL client.
    # mysql -u root -p

    Enter your password and you should be taken to a mysql prompt.

    mysql> create database dotprojdb

    Yes it is that simple. And at the same time no it is not that simple. There is a lot more to know such as where to put the database files and how fast of drives you need, whether you need faster read speed or faster write speed or both, but this will suffice for now.

  3. Create a mysql user account for this database. We don’t want to user the root account.
    See this page in the MySQL documentation for more information on this: Adding User Accounts

    mysql> CREATE USER ‘dpuser’@’localhost’ IDENTIFIED BY ‘P@sswd!’;
    Query OK, 0 rows affected (0.01 sec)
    mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP ON dotprojdb.* TO ‘dpuser’@’localhost’;
    Query OK, 0 rows affected (0.01 sec)

  4. Now open a web browser to your server’s site: http://yourserver/dotprojectYou will see the following page.

    No need to do anything on this page because it should redirect you after 5 second to a dotProject configuration web page.

    Now some of the items in red need to be taken care of. Not all of them, just some of them.

    The first group of items are “Requirements” and anything not with a pretty green check mark under the “Requirements” section needs to be fixed.

    However, under the “Database Connectors” section, there are lots of red Xs. We don’t need to fix these. We just need one database, so as long as the database you want to use (in this example it’s MySQL) has a pretty green check mark, you don’t need to do add more “Database Connectors”.

  5. Fix the first error: Session Save Path writable? X Fatal: session.save_path is not setTo do this, follow these steps:
    1. Change to the directory that contains the php.ini file. On FreeBSD that directory is here: /usr/local/etc
      # cd /usr/local/etc

    2. Now by default the PHP5 port on FreeBSD doesn’t install a php.ini file, but instead provides two example php.ini files: php.ini-recommended and php.ini-dist. So copy one of them to php.ini.
      # cp php.ini-recommended php.ini

    3. Edit the php.ini file and remove the comment from this line:
      ;session.save_path = “/tmp”

      I use ee which is the command to open Easy Editor. But you can use vi or whatever.

    4. Save the file and exit.
  6. The other issue is this one: Session AutoStart = ON? X Failed Try setting to ON if you are experiencing a WhiteScreenOfDeathOk. So this issue is fixed is in that same php.ini file. So repeat the steps only this time we don’t remove a comment, we change a setting from 0 to 1. Find the following line and change it from 0 to 1, as shown.
    session.auto_start = 1
  7. Restart apache. This is required and must be done before these settings will take effect.
    # /usr/local/etc/rc.d/apache22 restart

  8. Now you are ready to click the “Start Installation” button. So go ahead and click it. The following page should appear.
  9. Enter the details as shown in the page. Hopefully you have your own database user and password to use.
  10. Should you click the “User persistent connection?” option? Well, read this. http://www.php.net/manual/en/features.persistent-connections.phpI am not going to check it.
  11. Click “Install db and write config”. It should succeed and you should see this new page.
  12. Now go back to the dotproject home page: http://yourserver/dotprojectLogin with the default user name and password and you are ready to go.

    UPDATE:
    Check out my new update to this:
    How to configure dotProject 2.1.2 to authenticate using Active Directory’s LDAP?


Copyright ® Rhyous.com – Linking to this article is allowed without permission and as many as ten lines of this article can be used along with this link. Any other use of this article is allowed only by permission of Rhyous.com.

How to install Bugzilla on a FreeBSD 7.2 with Apache + SSL and MySQL?

How to install Bugzilla 3.4.2 on FreeBSD 7.2.

The basic overivew.

  1. Install FreeBSD.
    How do I install FreeBSD?

  2. Update FreeBSD and download the ports tree.
    What are the first commands I run after installing FreeBSD

  3. Then install Apache + SSL.
    Installing an Apache + SSL on FreeBSD using the ports tree

  4. Then install MySQL.
    How to install MySQL on FreeBSD 7.2 or on Red Hat 5.4?

  5. Configure MySQL to be Unicode.
    How to create a UTF-8 Unicode Database on MySQL and make UTF-8 Unicode the default?

  6. Then install Bugzilla

I have previous documents about installing each of the steps above installing Bugzilla. This document will over cover bugzilla.

Installing Bugzilla From Ports

You can install easily from Ports. Make sure your ports tree is up to date:

$

su

Password:

ServerName#
ServerName#
ServerName#
portsnap fetch
portsnap extract
portsnap udpate

Then just do this to install Bugzilla 3.4.2 on FreeBSD 7.2.

ServerName#
ServerName#
cd /usr/ports/devel/bugzilla
make BUGZILLADIR=/usr/local/www/apache22/data/bugzilla install

Note: Make sure you choose the correct install directory for the BUGZILLADIR parameter. By default Apache 2.2 is only serving up files in /usr/local/www/apache22/data/ so by install bugzilla there, you will be able to access bugzilla with this url: http://www.YourWebSite.com/bugzilla

You will be asked to select your compile options throughout. If you don’t want to be promtped, and you want to accept the defaults, use this command.

ServerName# make BATCH=yes install

Now that you have Bugzilla 3.4.2 on your FreeBSD 7.2 server, you are not finished. We now need to connect to connect it to a database, which I am assuming is MySQL but could just as easily be Postgresql.

Resetting the file ownership recursively on the bugzilla folder

Make sure that the bugzilla folder and all subfolders are owned by www:www.

ServerName# chown -R www:www /usr/local/www/apache22/data/bugzilla

Creating a MySQL Database

  1. Log into mysql. I use the command line and type in mysql -p, enter my password when prompted.
  2. Create a database for Bugzilla.
  3. Create a user that can access Bugzilla.
  4. I use the followiing SQL commands for these steps:

    CREATE DATABASE BugDB
    
    GRANT SELECT, INSERT, UPDATE, DELETE, INDEX, ALTER, CREATE, LOCK TABLES,
               CREATE TEMPORARY TABLES, DROP, REFERENCES
               ON BugDB.* TO BugDBUser@localhost
               IDENTIFIED BY 'P@sswd!';
    FLUSH PRIVILEGES;
    

Run Install Check Script

  1. In a command prompt go to /usr/local/www/data/bugzilla
    ServerName# cd /usr/local/www/data/bugzilla
  2. Run the setup checking script.
    ServerName# ./checksetup.pl
  3. Now you are ready to open and edit the localconfig file.
    ServerName# ee localconfig
  4. Change the following values:

    $webservergroup = ‘www’
    $db_name = ‘BugDB’
    $db_user = ‘BugDBUser’
    $db_pass = ‘P@sswd!’

    Then close and save the localconfig file.

  5. Run ./checksetup.pl again.
  6. Note: If you have installled everything including MySQL using the defaults, you will see this warning:

    WARNING: You need to set the max_allowed_packet parameter in your MySQL configuration to at least 3276750. Currently it is set to 1048576. You can set this parameter in the [mysqld] section of your MySQL configuration file.

    Resolve this using the MySQL configuration file called my.cnf. I discussed the my.cnf earlier in this article, so you should already be familiar with it.
    How to create a UTF-8 Unicode Database on MySQL and make UTF-8 Unicode the default?

    Find the max_allowed_packet settings and change it to 4M.

    max_allowed_packet = 4M

    Restart MySQL.

    ServerName# /usr/local/etc/rc.d/mysql-server restart
  7. Run checksetup.pl again.

    I got this error:

    Creating ./lib/.htaccess…
    No such file or directory at Bugzilla/Install/Filesystem.pm line 445, line 275.

    I had to manually create the /usr/local/www/apache22/data/bugzilla/lib directory then this error disappeared when I ran checksetup.pl again.

  8. Now create an Apache configuration file for bugzilla and put it in /usr/local/etc/apache22/Includes. I name it bugzilla.conf.

    bugzilla.conf

    <Directory "/usr/local/www/apache22/data/bugzilla">
      Options +ExecCGI
      AllowOverride Limit
      DirectoryIndex index.cgi
      AddHandler cgi-script .cgi
    </Directory>
    

    Restart Apache

    ServerName# /usr/local/etc/rc.d/apache22 restart
  9. You should now be able to connect to your server: http://YourServer/bugzilla


    Copyright ® Rhyous.com – Linking to this article is allowed without permission and as many as ten lines of this article can be used along with this link. Any other use of this article is allowed only by permission of Rhyous.com.

Installing an Apache + SSL on FreeBSD using the ports tree

Installing Apache + SSL is very easy on FreeBSD.

Note: Tested on FreeBSD 9

  1. First install FreeBSD. Instructions for installing FreeBSD is contained in this article.
    How I install FreeBSD?
    How I install FreeBSD 9?
  2. Second update FreeBSD and install the ports tree. Instructions for this are in this article.
    What are the first commands I run after installing FreeBSD?
  3. Install the latest version of Apache, which is Apache 2.2 as of writing this.
    #
    #
    cd /usr/ports/www/apache22
    make BATCH=yes install

    This will download the Apache 2.2 source and compile and install it. A few other dependencies will be installed as well.

    Apache will not start automatically which is fine because we are not ready to start it yet.

  4. Configure Apache to automatically start when the FreeBSD system boots up. This is done using the /etc/rc.conf file.
    #
    #
    echo # Apache 2.2 >> /etc/rc.conf
    echo 'apache22_enable="YES"' >> /etc/rc.conf
  5. In order for Apache to use SSL, you must create a certificate. Now you may or may not know how to create one. I have made it easy for you by doing everything in a shell script. I have used SHA-256, because in this day an age, you need higher security than MD5 or SHA1.

    makesha256key.sh

    #!/bin/sh
    mkdir -p /root/mycert
    cd /root/mycert
    
    mkdir -p /usr/local/etc/apache22/ssl.key
    mkdir -p /usr/local/etc/apache22/ssl.crt
    chmod 0400 /usr/local/etc/apache22/ssl.key
    chmod 0400 /usr/local/etc/apache22/ssl.crt
    
    openssl genrsa -des3 -out $1.key 1024
    openssl req -new -x509 -nodes -sha256 -days 365 -key $1.key -out $1.crt
    
    cp $1.key $1.key.orig
    openssl rsa -in $1.key.orig -out $1.key
    
    cp $1.key /usr/local/etc/apache22/ssl.key/
    cp $1.crt /usr/local/etc/apache22/ssl.crt/
    chmod 0400 /usr/local/etc/apache22/ssl.key/$1.key
    chmod 0400 /usr/local/etc/apache22/ssl.crt/$1.crt
    

    This is NOT a fully functional shell script that shows you the command line options and everything. It is really just a list of commands to make this easier for you. Copy this to a shell script and run it. It takes one parameter, the cert name and you should call it like this:

    ./makesha256key.sh certname

    IMPORTANT: The commands in the script will prompt you for a Certificate password, and your Certification information. The only thing you need to make certain of is that when prompted for the “Common Name” you use the URL. For example, if your web site is www.rhyous.com, then www.rhyous.com is your Common Name.

    Or you can run the commands from the shell script manually one at a time if you want (replacing $1 with your desired certificate name).

    Note: In this script, the certificate will be a self-signed certificate, but you can get a signed certificate free here: http://cert.startcom.org

  6. Now configure Apache to read the httpd-ssl.conf file when it starts.

    Open the /usr/local/etc/apache22/httpd.conf using the easy editor or ee.

    # ee /usr/local/etc/apache22/httpd.conf

    Near the end of the file, remove the comment symbol, the # sign, from the following line:

    Include etc/apache22/extra/httpd-ssl.conf

    Note: While you are in this file you may want to remove the comment from the line for enabling Virtual Hosts too if you are going to have multiple URLs hosted at this page.

  7. Configure the httpd-ssl.conf.
    # ee /usr/local/etc/apache22/extra/httpd-ssl.conf

    I only change the two lines to point to the correct certificate. Here is an sample httpd-ssl.conf without the comments.

    Listen 443
    AddType application/x-x509-ca-cert .crt
    AddType application/x-pkcs7-crl    .crl
    SSLPassPhraseDialog  builtin
    SSLSessionCache        "shmcb:/var/run/ssl_scache(512000)"
    SSLSessionCacheTimeout  300
    SSLMutex  "file:/var/run/ssl_mutex"
    <VirtualHost _default_:443>
      DocumentRoot "/usr/local/www/apache22/data"
      ServerName www.example.com:443
      ServerAdmin you@example.com
      ErrorLog "/var/log/httpd-error.log"
      TransferLog "/var/log/httpd-access.log"
    
      SSLEngine on
    
      SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
    
      SSLCertificateFile "/usr/local/etc/apache22/ssl.crt/server.crt"
    
      SSLCertificateKeyFile "/usr/local/etc/apache22/ssl.key/server.key"
    
      <FilesMatch "\.(cgi|shtml|phtml|php)$">
        SSLOptions +StdEnvVars
      </FilesMatch>
      <Directory "/usr/local/www/apache22/cgi-bin">
        SSLOptions +StdEnvVars
      </Directory>
    
      BrowserMatch ".*MSIE.*" \
             nokeepalive ssl-unclean-shutdown \
             downgrade-1.0 force-response-1.0
    
      CustomLog "/var/log/httpd-ssl_request.log" \
              "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
    
    </VirtualHost>
    

  8. Now start or restart Apache.
    # /usr/local/etc/rc.d/apache22 start

Now just open a browser (on another system of course) and connect to your new FreeBSD installed web server. You can connect using name, fqdn, or IP and see which work.

  • http://servername
  • http://www.YourDomain.com
  • http://192.168.0.100

You can also try to connect with SSL.

  • https://servername
  • https://www.YourDomain.com
  • https://192.168.0.100

Common Errors

  1. Performing sanity check on apache22 configuration:
    httpd: apr_sockaddr_info_get() failed for F9
    httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
    Syntax OK
    Starting apache22.
    httpd: apr_sockaddr_info_get() failed for F9
    httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
    /usr/local/etc/rc.d/apache22: WARNING: failed to start apache22
    

    If you get this error, you need to update your /etc/hosts file and make sure the system’s hostname there.

    ::1                     localhost YourServerNameHere
    127.0.0.1               localhost YourServerNameHere
    

Install other software

It is now very common to install a database server and a scripting language, such as MySQL and PHP. I have separate documents for each install:

How to install MySQL FreeBSD?

How to install PHP5 and PHP5 Extensions on FreeBSD?