Archive for September, 2010
Ubuntu subdomains on Apache2
by RedCoupe on Sep.21, 2010, under Web design / development
From a standard Apache2 install I created a folder in /var/www/ called ‘testsite’ (without the quotes).
Go to the following folder:
/etc/apache2/sites-available
…and create a file called something suitable, for this purposes of this blog post I’ll just call my file testsite, It’s contents should be:
<VirtualHost *:80>
DocumentRoot /var/www/testsite/
ServerName testsite.localhost
ServerAlias testsite.myubuntubox
<Directory /var/www/testsite/>
Options Indexes FollowSymLinks MultiViews +Includes
AllowOverride None
Order allow,deny
allow from all
</Directory>
</VirtualHost>
Then run the following command:
sudo a2ensite testsite
Edit your /etc/hosts file and add the following lines:
127.0.0.1 testsite.localhost 127.0.0.1 testsite.myubuntubox 192.168.0.6 testsite.myubuntubox
Obviously the ip address 192.168.0.6 may be different depending on your network setup.
Restart Apache:
sudo /etc/init.d/apache2 reload
I also had to edit my c:\windows\system32\drivers\etc\hosts file on my other PC to make sure that when I visit http://testsite.myubuntubox/ it resolves correctly, so I now have the following:
127.0.0.1 localhost 192.168.0.6 myubuntubox 192.168.0.6 testsite.myubuntubox
That’s it, all working, now I can develop multiple websites locally using subdomains. Personally I would rather do it this way than putting websites into folders, seems to work better with Dreamweaver.
Change date/time format from MySQL
by RedCoupe on Sep.17, 2010, under Web design / development
Format was: 2010-09-17 12:09:01
But wanted to display like: 17-09-2010 12:09:01
<?php echo date('d-m-Y H:m:s', strtotime($row_Recordset1['datetimeval'])); ?>
Related links:
PHP replace crlf in a textarea with br
by RedCoupe on Sep.09, 2010, under Web design / development
I had a textarea value which was obtained from a MySQL database and it contained many instances of crlf or \n. To display correctly on a web page I wanted to convert those to <br /> so I used the following code:
<?php echo nl2br($myrecorsetvalue); ?>
Obviously you would need to replace the $myrecorsetvalue with whatever recordset variable you are using.
Random rows in MySQL
by RedCoupe on Sep.08, 2010, under Web design / development
A competition has been running on a website and all the entries were stored in a MySQL table.
Had to get a random record to pick a winner once the closing date had passed.
Here’s the SQL I used:
SELECT * FROM t_tablename ORDER BY RAND() LIMIT 1
If I had wanted to pick out 5 random winners, then change the LIMIT value to LIMIT 5.
Problem connecting to MySQL on Ubuntu
by RedCoupe on Sep.08, 2010, under Web design / development
Had a problem connecting to my MySQL server which is on a Linux server (Ubuntu) and used the following advice to get round this, so I thought I would share this with you in case anybody has the same problem:
Edit the following file: /etc/mysql/my.cnf
Find the following line:
bind-address = 127.0.0.1
and change it to the actual ip address of the Ubuntu box and save
Then restart MySQL: sudo /etc/init.d/mysql restart
Job done!