Hi everyone!! I am NOT Topher Grace, nor do I want to be. I am just Topher Scribbles and just for kicks, I really want to out-rank Topher Grace's IMDB website. If you want to help, just link to me. Thanks and enjoy some boring fun!!

Error installing GD from php5-extensions using FreeBSD Ports

I’ve run into another problem installing Apache-PHP-MySQL FreeBSD server. While installing php5-extensions, I received an error when it tried to install GD. Here’s the error:

===> Patching for php5-gd-5.2.3
===> Applying FreeBSD patches for php5-gd-5.2.3
===> php5-gd-5.2.3 depends on executable in : phpize - found
===> php5-gd-5.2.3 depends on file: /usr/local/bin/autoconf259 - found
===> php5-gd-5.2.3 depends on file: /usr/local/libdata/xorg/libraries - not found
===> Verifying install for /usr/local/libdata/xorg/libraries in /usr/ports/x11/xorg-libraries
/usr/X11R6 exists, but it is not a symlink. Installation cannot proceed.
This looks like an incompletely removed old version of X. In the current version, /usr/X11R6 must be a symlink if it exists at all.Please read /usr/ports/UPDATING (entry of 20070519) for the procedure to upgrade X.org related ports.
*** Error code 1
Stop in /usr/ports/x11/xorg-libraries.
*** Error code 1

Stop in /usr/ports/graphics/php5-gd.
*** Error code 1

Stop in /usr/ports/lang/php5-extensions.
*** Error code 1

Stop in /usr/ports/lang/php5-extensions.

To fix, all I did was add WITHOUT_X11=yes to my make install line. You can also do a XORG_UPGRADE=yes. Either way works, but the latter will install some x11 items.

Done!!

Search Engine Friendly URL’s Using Mod_Rewrite

Want to make http://domain.com/awesomepage.php?page=4&user_id=badass&action=go look like http://domain.com/awesome/page/4/user/baddass/go ?? To do this, you will need to use mod_rewrite in .htaccess or edit your Virtual Host in httpd.conf.

Here is the code:


Options +FollowSymlinks
RewriteEngine On
RewriteRule ^/awesome/page/([0-9]+)/user/(.+)/(.+)$ /awesomepage.php?page=$1&user_id=$2&action=$3 [NC]

Yes, you will need to create more than one entry per page, but if you plan it out correctly, you will need just one.
That’s all there is to it.

Done!!

What’s My IP Address

Since I have a dynamic IP address at home, I always have to look it up whenever I access anything that is IP restricted at work.

All I do is run a simple code:

echo $_SERVER[REMOTE_ADDR]

Or you can check out my other page, http://topherdotcom.com/scribble/what-is-my-ip-address/ to see your own IP address.

Done!!

Can’t Install mysql50-server Through the Ports?

I’ve been trying to install mysql50-server via ports, but have been getting a checksum error, like this:

=> MD5 Checksum mismatch for mysql-5.0.41.tar.gz.
=> SHA256 Checksum mismatch for mysql-5.0.41.tar.gz.
===> Giving up on fetching files: mysql-5.0.41.tar.gz mysql-5.0.41.tar.gz
Make sure the Makefile and distinfo file (/usr/ports/databases/mysql50-server/distinfo)
are up to date. If you are absolutely sure you want to override this
check, type "make NO_CHECKSUM=yes [other args]".
*** Error code 1

Stop in /usr/ports/databases/mysql50-server.
*** Error code 1

Stop in /usr/ports/databases/mysql50-server.

For an easy fix, all I did was fetch the mysql tar from freebsd.org and place in /usr/ports/distfiles/, intalled again through the ports, and voila!!

Here’s an easy one liner fixer (for the lazy people, like me). Just copy and paste at prompt.

cd /usr/ports/distfiles/ && fetch ftp://ftp.freebsd.org/pub/FreeBSD/ports/distfiles/mysql-5.0.41.tar.gz && cd /usr/ports/databases/mysql50-server/ && make install clean

NOTE: This is all one line.

Done!!

Redirect to a specific page using mod_rewrite

Here’s a quick and easy way to redirect a domain name to a specific page using mod_rewrite.

<Directory /path/to/document/root>
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^.*$ http://domain.com/page.html [R=301,L]
</Directory>

This uses a 301 Permanent Redirect to the redirected page.

Done!!

Download a Text File Using PHP

Do you need to download a text file instead of having your browser read the file?

All you need to do is use the code below, and name it download.php (or whatever you want).

<?
$file = 'filename.txt';
header('Content-type: text/plain');
header('Content-Length: '.filesize($file));
header('Content-Disposition: attachment; filename='.$file);
readfile($file);
?>

NOTE: Make sure you copy as is and do NOT leave any whitespace since you are sending headers.

All you need to do is replace filename.txt with the name of the filename you wish to have downloaded.

Now create another file, index.html perhaps, and just link to that php file, and you are all set. If you named the script download.php, you will just need:

<a xhref="download.php" mce_href="download.php" >Download Text File</a>

Done!!

Removing ^M from a text file

Do you see ^M at the end of every line? Or ^M at random places where a new line should be?

This seems to happen when a DOS or Windows machine edits a text file. It is the Control Character for Carriage Return. To remove this, you will need to edit the file in Vi. Not sure how to do this in other text editors, but this will definitely work in Vi.

If you want to just remove the ^M characters, run this command in Vi:

s:%/^M//g

NOTE: Do not type Shift-6, Shift-m. That will not work. You will need to hold down ctrl while pressing V then M.If you want to replace each ^M character with a new line, run this command in Vi:

s:%/^M/^M/g

Again, hit ctrl-V-M to issue the second ^M in the replacement field.

Done!!

FreeBSD Samba

So you want to mount a network drive with Samba?

First thing you do is install Samba via ports on both systems. (Be sure to update your ports with cvsup, that will be in a future article)

# cd /usr/ports/net/samba3
# make install clean

Next, on the server machine, in order to make Samba run, you will need to add it to /etc/rc.conf. Just add this line:

samba_enable="YES"

On the client machine, you don’t have to start Samba. In fact, for added security, I remove the samba.sh startup script like so:

# rm /usr/local/etc/rc.d/samba.sh

Now we add the user on the server machine. You will be adding an actual Unix user, but without a login and home directory.

# adduser SambaUser

Username : SambaUser
Password : *****
Full Name : Samba User
Uid : 1004
Class :
Groups : SambaUser
Home : /dev/null
Shell : /usr/sbin/nologin
Locked : no

Add a Samba password:

smbpasswd -a SambaUser

Now we edit the Samba service in smb.conf located at /usr/local/etc/smb.conf with…

[SambaUserdir]
comment = SambaUser's Network Drive
path = /path/to/directory
valid users = SambaUser
public = no
writeable = yes
printable = no

Be sure to create the directory (/path/to/directory) and make that writable to the SambaUser.

To test your server, you should be able to do this:

# smbclient -L 127.0.0.1 -U SambaUser

If no errors, then you are good to go. If you get an error, please refer to Samba’s site, or you can google the error message.

We can start Samba now with this:

# /usr/local/etc/rc.d/samba.sh start

Now we mount the drive. Create the directory in the client machine where you would like the mounted network drive at, and then mount it. (NOTE: Below is all one line)

mount_smbfs -I 192.168.0.2 //SambaUser@ServerName/SambaUserdir /path/to/mount

That’s pretty much it!!

Done!!

Reinstalling PHP

So you want to reinstall PHP??

This is how you would reinstall php, for whatever reason, and keep the same config options.
First of all, you need to find out what ./configure options you used to install PHP in the first place. Go to the source folder, usually /usr/local/php-(version number). Open up config.status in your favorite editor and copy the ./configure line, which is probably at or around line 7.

Change directory into the PHP source folder. Run a clean, distclean, patch (if needed), configure (with the same options as in the config.status file), make, install, and finally restart apache.

# make clean
# make distclean
# ./configure (paste from config.status file)
# make && make install
# apachectl restart

Done!!

Fresh Install From Scratch

OK..Roll up your sleeves. It’s time to get dirty (not as dirty as installing KDE via ports though). So here we go.

I’m just going to talk about post-installation. Yeah, yeah, I’ll get to the install later. Anyway, the first thing I install is cvsup. You can install this via ports:

# cd /usr/ports/net/cvsup-without-gui && make install clean

I installed cvsup-without-gui because, well, I never actually used just cvsup.

After it installs, it will create a ports-supfile file at

/usr/share/examples/cvsup/ports-supfile

or

/usr/src/share/examples/cvsup/ports-supfile.

Just copy it to your root folder. Then, just change

*default host=CHANGETHIS.FreeBSD.org

to a cvsup server near you. To find a cvsup server near you, just go to

After that, run cvsup:

# /usr/local/bin/cvsup /root/ports-supfile

Oh yeah, if you are behind a firewall, make sure to open port 5999.

Done!!