Free-Software

Apache: PHP not working in UserDir

Submitted by Renan on Thu, 29/07/2010 - 18:30

Here is a tip to PHP developers that uses the Debian family of distros: how enable the execution of PHP scripts in the public_html folder. Apparently, this feature is disabled by default in the Debian based distros. Before start, I'm assuming that you already have both Apache and PHP installed, configured and running.

The interest in using Apache's mod_userdir is to increase the system security at the same time making easy the file handling. All the files inside the public_html folder present in your home dir will be accessible through Apache.

As root, run the following commands. First, we enable the userdir mod:

# a2enmod userdir

The script will enable the module and will tell you do restart Apache. At next, create the public_html folder using your normal user, inside your Home, and define its permissions:

  1. $ mkdir public_html
  2. $ chmod 711 public_html

Now, as root, define the Home's folders permissions(this is a critical detail):

# chmod 711 /home /home/[your_login]

The next step is enable the execution of PHP scripts inside public_html. To do that, as root, open the file /etc/apache2/mods-enabled/php5.conf and find the following lines:

  1. <IfModule mod_userdir.c>
  2.   <Directory /home/*/public_html>
  3.     php_admin_value engine Off
  4.   </Directory>
  5. </IfModule>

Comment them by putting a # in the beginning of each one. Save and close. Now restart the Apache server by running the following command as root:

# /etc/init.d/apache2 restart

The end! You can now run your PHP apps inside your public_html folder without being worried about doing weird tricks to read/write the default /var/www. :)

Reload partition table without rebooting a Linux system

Submitted by Renan on Tue, 20/07/2010 - 22:17

After buying a new 500Gb hard-drive for my laptop(the 120Gb old one is without room :) ) I took to partitionate it and install my operating systems. As usual, first I've installed Windows(although I did not use frequently, it's impossible don't have it) and then Sidux(Sidux, Debian Sid based, stable, rolling-release, I recommend).

After all installed, I've forgoted creating some partitions for the Gentoo installation(learning purposes :) ) and my "file backup" partition(to share files between my systems). After creating the first ext4 partition using the KDE Partition Manager ( btw, KDE > Gnome ;) ), it could not format or do other operation in this fresh partition.

Searching arround for some time, I notice that the system are not listing the partition id at /dev. There have all the other partitions(/dev/sda1, /dev/sda2, /dev/sda5, etc) but not the new one(/dev/sda8, for example). After rebooting, it showed up. Then I conclude that the Linux Kernel, at booting, read the partition table and create all the resources in /dev -- a process that does not occour(at least, automatically) in runtime.

But, if cannot be done automatically, it can be done manually! :)

I've found 3 methods that force the Kernel reload the partition table and repopulate its ids in /dev.

Partprobe

This program has the objective to tell the Kernel reload the partition table of a device(Hard-disks, flash-drives, etc) in runtime. To use, install it in your distribution using the package management tools provided(in my case, it's Debian's apt-get):

# apt-get install partprobe

After, execute partprobe as root telling what device you want to reload the partition table:

# partprobe /dev/sdX (Where X is your device letter)

Done! Your system should have recognized the new partitions you have created! Now, just return to KPM and do the stuff(format/label/etc) your freshly created partition!

Hdparm

If partprobe did not work, its possible to do the same procedure using Hdparm: a general hard-disk utilitary. Just execute the following command as root:

#  hdparm -z /dev/sdX (Where X is your device letter)

Via Kernel interface

This method does not use any previous programs because it comunicates directly with the kernel interface. Because of that, there is no error recovering if something wrong happens while reloading your partition table. You are warned. I'm not responsible for any data loss or kryptonite damage you might suffer. :)

As root user, send the following signal to the kernel interface:

# echo 1 > /sys/block/sdX/device/rescan (Where X is your device letter)

Then, check the dmesg reported messages to confirm that the kernel done the reloading of the device's partition table.

After this, your partition(s) should be recognized and enabled in /dev, making it possible to format, label and mount them!

If you work with Linux servers, you know how painfull is to reboot a system. Using this tip you can work with partitions and avoid the downtime that one simple restart could do. ;)

Syndicate content
"If debugging is the process of removing bugs, then programming must be the process of putting them in." Drupal theme by Kiwi Themes.