• Skip to main content

Uly.me

cloud engineer

  • Home
  • About
  • Search

Archives for January 2013

Delete .DS_Store Files Recursively

January 31, 2013

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 {} \;

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

The .DS_Store files will be deleted recursively.

Filed Under: Mac Tagged With: .ds_store, delete, mac os, recursively

CodeIgniter Anchor With Onclick

January 31, 2013

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>

<?=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>

<?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.

Filed Under: PHP Tagged With: anchor, codeigniter, javascript, url helper

Web Directory Structure

January 16, 2013

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.

Filed Under: CSS, HTML, PHP Tagged With: codeigniter, structure, web directory, web folders

  • Go to page 1
  • Go to page 2
  • Go to Next Page »
  • Home
  • About
  • Search

Copyright © 2023