Finding Apache Configuration File httpd.conf Location

Finding the location on typical Linux/Unix servers is not very difficult. To do so, go into terminal/SSH and run the command:

ps -ef | grep httpd

Your output may differ slightly based on your operating system, but it should look something like:

    0    48     1   0  7:22AM ??         0:00.44 /usr/sbin/httpd -D FOREGROUND -D WEBSHARING_ON
   70   165    48   0  7:22AM ??         0:00.01 /usr/sbin/httpd -D FOREGROUND -D WEBSHARING_ON
  501  1247  1219   0  7:50AM ttys001    0:00.00 grep httpd

On certain operating systems, it may not return anything. In that case, try command:

ps -ef | grep apache2

If you don’t receive any results from both commands, you may not be running Apache/httpd.¬†Nonetheless, you want to pay close attention to /usr/sbin/httpd. That is the location to your binary file. Run the following command to obtain the location to your configuration file:

/usr/sbin/httpd -V | grep SERVER_CONFIG_FILE

You’ll see something like the following, which will designate the location for your httpd.conf file.

 -D SERVER_CONFIG_FILE="/private/etc/apache2/httpd.conf"

Loading IPTables Rules on Boot with CentOS/RHEL

Reloading iptables rules on boot for CentOS and RHEL is simpler than for most other Linux Distributions. RHEL and its clone CentOS write its “permanent” iptables rules to the¬†¬†/etc/sysconfig/iptables file. Writing iptables rules is out of the scope of this article, so I won’t go over that today.

After you have applied your respective iptables rules, you may wish to check on your iptables rules before you save them. Use the following command to list all the current rules:

iptables -L

Use this command to save the iptables rules (the following command is the actual command to save the rules so they are applied on boot)

/sbin/service iptables save

The following command would allow you to double check that your rules have been saved. It is similar to iptables -L, but also different. The previous command shows all the rules that are currently in effect, but many of those rules will not be applied after your system has been restarted. The following command will show all the rules that are currently in effect and have been written to disk, meaning they will apply even after a reboot.

cat /etc/sysconfig/iptables

PHP – Import CSV to MySQL

The following code snippet can be used to import CSV into MySQL using PHP.

<?php
$delimiter = ',';

$db = new mysqli('localhost', 'username', 'password', 'database');

if (($handle = fopen("import.csv", "r")) !== FALSE) {
	while (($data = fgetcsv($handle, 1000, $delimiter)) !== FALSE) {
		foreach($data as $i => $content) {
			$data[$i] = $db->real_escape_string($content);
		}
		$db->query("INSERT INTO mytable VALUES('" . implode("','", $data) . "');");
	}
	fclose($handle);
}

?>

A few things to keep in mind:

  • Make sure you change the MySQL login information to your own login information
  • Make sure you change the table name, in this case, mytable, to your own table name.
  • For your CSV (comma separated values) file, the delimiter may not necessarily be a comma. Change the $delimiter variable to the one-character delimiter separating the different fields.
  • This does NOT automatically create a table. You have to manually do that.
  • Every row would be inserted, so you should manually remove the first row if it is just the column names.