Delete .DS_Store Files Recursively

If you work with MacOS and you FTP files to a Linux server, you probably have seen this pesky and ubiquitous hidden files named .DS_Store. They seem to be in every folder known to man. The .DS_Store files are hidden MacOS files used to store the attributes of a folder such as position of icons and choice of background images, etc. Although they are not harmful, they probably don’t belong on the web server. Instead of deleting them one by one, there’s a faster way of deleting them recursively. You can invoke this command from the Linux terminal on your webroot folder.

cd /var/www/
find . "-name" ".DS_Store" -exec rm {} \;

The .DS_Store files will be deleted recursively.

CodeIgniter Anchor With Onclick

CodeIgniter comes with a URL helper that assist you with managing URLs. One function worth examining is called anchor, which creates standard HTML links. Instead of the standard HTML <a href=””>anchor</a> tag most people are familiar with, CodeIgniter coders can take advantage of the simpler anchor function.

To create a standard link, all you have to do is code this:

<?=anchor('blog /index', 'Home');?>
 
// Output is
<a href="http://yourdomain.com/blog/index.php">Home</a>

If you want to add a Javascript popup that will ask you “Are you sure?” before proceeding to the link, then all you have to do is add a third option in the anchor function like this:

<?php $onclick = array('onclick'=>"return confirm('Are you sure?')");?>
<?=anchor('blog /index', 'Home', $onclick);?>
 
// Output is
<a href="http://yourdomain.com/blog/index.php" onclick="return confirm('Are you sure?')">Home</a>

This function works great especially if you add it to code that delete records. You like to be able to ask the user first if that’s what they really want to do before proceeding.

Web Directory Structure

If you’re a system administrator or web developer with root privileges, chances are, you probably have complete control of your web server, including root privileges. That’s a good thing. You can setup the server anyway you want. If you’re starting out to build out a new web server, some of the questions that you may have is, what’s the proper or correct way of creating a web directory structure on your web server.

The answer is, there is really no correct way. There’s no magic bullet configuration. You do have complete freedom to setup your server anyway you want. But, if you want to make it easy for yourself, you should probably look for a well-established standard, or some proven way in structuring web directories.

The following is my “suggestion” after my extensive experience with countless web servers over the years. I called it “suggestion” because it’s by no means the holy grail, but the concept has served me well over the years. You may not necessarily agree with my format, or you may have something similar, or something completely different than mine. Nevertheless, my setup is simple and it works.

Most web servers nowadays can host multiple domains. I will make an assumption that you will be running multiple domains on your web server. A typical structure would be something similar to the one below. Each domain has its own subdirectory.

/var/www/domain1.com/
/var/www/domain2.com/
/var/www/domain3.com/

If you have a static website, the file structure would be something like this.

/var/wwww/domain.com/index.html

If you have a dynamic website, you have something similar to this.

/var/www/domain.com/index.php
/var/www/domain.com/wp-content/

By the way, “wp-content” is a WordPress folder where templates and plugins reside. The above structure is serviceable, but if you ever find yourself working with PHP Frameworks such as CodeIgniter, Zend Frameworks, or even Ruby on Rails, there are some additional directories and programs that you would want to hide from the public for security reasons. Here are some directories using the CodeIgniter example.

/var/www/domain.com/index.php
/var/www/domain.com/application/
/var/www/domain.com/system/

To make your application secure, we need to move the “application” and the “system” folders above the web root folder. With the current setup, this is where you begin to have some issues. Where exactly do we put your “application” and “system” folders if multiple domains need them. So, here’s my suggestion. We need to create a “www” folder under each domain. We will make the “www” folder the web root folder. The setup would look something like this.

/var/www/domain1.com/www/
/var/www/domain2.com/www/

Now, that we have the “www” folder created, we can then place the “application” and “system” folders on their own directory above the web root. The setup would look something like this.

/var/www/domain1.com/www/index.php
/var/www/domain1.com/application/
/var/www/domain1.com/system/
/var/www/domain2.com/www/index.php
/var/www/domain2.com/application/
/var/www/domain2.com/system/

So, the setup above is ideal for placing folders above the web root folder if you want a more secure application. At the same time, these folders are still under each domain. So, this is the web structure that I have implemented over the years. If there’s a better way of doing this, I would like to hear about it.

Setup Wireless On Raspberry Pi

One of the first things you should do once you have your Raspberry Pi is setup a wireless network adapter. This will allow you to be cable free. To configure, you will need one of several approved USB wireless adapters. I’m using an Airlink 101 Wireless N 150 Ultra Mini-USB Adapter that I purchased at Amazon for just $14. I chose the Airline 101 because it was affordable, and it works very well with the Raspberry Pi.

10 steps to setup wireless on Raspberry Pi:

  1. Plug in the Airlink 101 adapter.
  2. Power up the the Raspberry Pi.
  3. To see if the wireless device is recognized, type lsusb.
  4. To see if the kernel driver is installed, type lsmod.
  5. Edit the /etc/network/interfaces file.
  6. Edit the /etc/wpa_supplicant/wpa_supplicant.conf file.
  7. Reboot.
  8. Check with ifconfig.
  9. Check with ping.
  10. All done.

Here are the commands, instructions and their respected screen outputs.

$ lsusb
Bus 001 Device 004: ID 0bda:8176 Realtek Semiconductor Corp. RTL8188CUS 802.11n WLAN Adapter
 
$ lsmod
8192cu                485042  0
 
$ sudo nano /etc/network/interfaces
# Add the following lines:
auto wlan0
allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
 
$ sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
# Add the following lines:
network={
ssid="The_SSID"
proto=RSN
key_mgmt=WPA-PSK
pairwise=CCMP TKIP
group=CCMP TKIP
psk="The_WPA_SHARED_KEY_"
}
 
$ sudo reboot
 
$ sudo ifconfig wlan0
 
$ ping yahoo.com

First Page Is Always Selected

I had a little trouble with CodeIgniter pagination today. The pagination function is working fine, but Page 1 is always selected regardless which page I select. The data seems to be correct as I go from one page to another, but the page number doesn’t move at all. Well, after trial and error, the problem turned out to be a configuration issue.

CodeIgniter typically uses the following URI format:

http://domain.com/class/function/id.

The third segment is normally used by the pagination function for navigating from one page to another. By default, CodeIgniter pagination only uses 3 URI segments. If you are using more than 3 segments, then you will need to specify the location of the URI segment in your configuration. In my case, I’m using the fourth segment, I needed to include this setting.

$config [‘uri_segment’] = ‘4’;

If you need help with pagination, please refer to the Pagination class from the CodeIgniter User Guide.