Webbserver

How to disable PHPSESSID from URL

This is a quick howto disable PHPSESSID form appearing in your url an messing upp your google search results. The background to the problem is that googlebot doesnt use cookies and therefore will apache store the PHPSESSID in the url instead. To fix this, create a file called .htaccess and put in in you webroot. (note the dot before the filename)

The file must have the following contents:


#Force PHPSESSID into cookie or not bother
php_value session.use_only_cookies 1
php_value session.use_trans_sid    0

<IfModule mod_rewrite.c>
  RewriteEngine on
  Options All

  #Remove PHPSESSID from existing links to your webpage.
  #This tells google that your page /index.php?foo=bar&PHPSESSID=dasdagas has 
  #moved to /index.php?foo=bar
  RewriteCond %{QUERY_STRING} PHPSESSID=.*$ 
  RewriteRule .* %{REQUEST_URI}? [R=301,L]
</IfModule>

Install and configure LAMP, Ubuntu

Installing PHP on a linux box is far from complicated. There is several guides and HOWTO. If this page is not enough for you. Google: LAMP-server ubuntu.

LAMP is acronym for Linux, Apache, MySQL, PHP. And thats everything you need for developing PHP. Start by type the following in a terminal.

sudo apt-get update
sudo apt-get install apache2 php5 php5-cli libapache2-mod-php5 mysql-server php5-mysql php5-mcrypt


Restart the server.

sudo /etc/init.d/apache2 restart


Go to http://localhost and see if It works!

Apache 2 needs to be configured according to the instuctions found in the Symfony cookbok / Jobeet tutorial.

Virtual hosts

To enable virtual hosts in ubuntu, create /etc/apache2/sites-available/YOURSITE.com with the following content:

<VirtualHost *:80>
	ServerAdmin webmaster@localhost
	ServerName YOURSITE.com
	ServerAlias *.YOURSITE.com

Clean URLs

Som den väldigt observanta har märkt så använder jag från och med igår Clean URls funktionen i Drupal. Med Clean URLs får man bort den fula query-strängen som Drupal lägger till i URLen.
Så här gjorde jag:

Jag antar att du kör alla kommandon som superuser. (sudo su)
Jag kontrollerade först att mod_rewrite var laddad i apache.

apache2ctl -M

Om du ser rewrite_module i listan så är den laddad.

Om du inte ser rewrite_module i listan så måste du ladda den med detta kommando.

a2enmod rewrite

Om du använder virtual hosts så ska du göra en liten ändring i /etc/apache2/sites-available/SIDANS_NAMN
Sätt

AllowOverride None

...till...

AllowOverride All

...på alla ställen i filen.

Spara filen och starta om apache med följande kommando.

/etc/init.d/apache2 force-reload

Apache och mod_rewirte

Länge har jag försökt få fina URLs. Jag har läst på lite om hur man skriver en .htaccess fil för att kunna ändra URLen. Det har fungerat på andra servrar men inte min egen. Jag har faktiskt ingen aning om varför...
mod_rewrite är laddad i apache och tycks fungera. Jag har också gjort lite inställningar i min virtual server. Men inget har hjälpt.

I skolan tipsade vänliga kamrater att slå på all möjlig loggning för att försöka se vad som är felet.
Jag kommer säkert spendera ett 10-tal timmar i helgen åt att läsa loggfiler och försöka lösa gåtan... få se hur mycket jag hinner plugga innan bara =)

Jag kommer posta min lösning här sen.