CentOS: httpd invalid command

Was configuring a CentOS 6 server recently, and I decided to comment out all httpd (i.e. Apache) LoadModule directives. Upon restart, there were several invalid commands, so I took the time to note ’em down as it wasn’t obvious (to me, at least) which commands were provided by which modules.

I liken this to a cheat sheet to http://httpd.apache.org/docs/2.2/ then:

Invalid command 'AddHandler': mod_mime
Invalid command 'Alias': mod_alias
Invalid command 'BrowserMatch': mod_setenvif
Invalid command 'DirectoryIndex': mod_dir
Invalid command 'IndexOptions': mod_autoindex
Invalid command 'LanguagePriority': mod_negotiation
Invalid command 'LogFormat': mod_log_config
Invalid command 'Order': mod_authz_host
Invalid command 'TransferLog': mod_log_config

#apache, #linux, #red-hat

OCIEnvNlsCreate() failed

Wanted to work on an Oracle project from home last weekend, but I received this message:

Warning (2): ocilogon() [function.ocilogon]: OCIEnvNlsCreate() failed. There is something wrong with your system – please check that ORACLE_HOME and LD_LIBRARY_PATH are set and point to the right directories [CORE/cake/libs/model/datasources/dbo/dbo_oracle.php, line 171]

A little bit of system background here. I’m using Linux Mint 8, running oracle-xe oci8 was compiled via pecl, with one notable difference from my previous guide. I did not use instantclient (i.e. instantclient,/usr/lib/oracle/11.1/client/lib), so the phpinfo output for the oci8 section was quite different.

It looked like:

OCI8 Support enabled
Version 1.4.1
Revision $Revision: 293235 $
Active Persistent Connections 0
Active Connections 0
Compile-time ORACLE_HOME /usr/lib/oracle/xe/app/oracle/product/10.2.0/server
Libraries Used -Wl,-rpath,/usr/lib/oracle/xe/app/oracle/product/10.2.0/server/lib -L/usr/lib/oracle/xe/app/oracle/product/10.2.0/server/lib -lclntsh
Temporary Lob support enabled
Collections support enabled

I did some searching. I figured it was something to do with environment variables, as my colleague had helped me to resolve the problem previously. I’d forgotten the fix, so this post will serve as a reminder, if needed.

Now ORACLE_HOME and LD_LIBRARY_PATH were defined via my .bashrc, which consists of just one line:

. /usr/lib/oracle/xe/app/oracle/product/10.2.0/server/bin/oracle_env.sh

Some people suggested using Apache’s SetEnv — which I tried — but the error did not go away. That same colleague suggested this morning I use the envvars file in Ubuntu instead, which helped to resolve my problem, at least:

Adding these two lines solves my problem:

export ORACLE_HOME=/usr/lib/oracle/xe/app/oracle/product/10.2.0/server
export LD_LIBRARY_PATH=/usr/lib/oracle/xe/app/oracle/product/10.2.0/server/lib:

Seriously, my journey with Oracle has always been a rocky one. I wonder why this product is so… inaccessible.

#apache, #oracle, #ubuntu

mod_rewrite primer

I’ve had to write a number of .htaccess files over the past week or so. My uses of mod_rewrite are simple enough, but I thought to post here since there in case anybody just wants to accomplish something quickly. Ask your server administrator to set the “AllowOverride” property to “FileInfo” or “All”, so as to enable .htaccess overrides.

Permanent (301) redirect everything:
RewriteEngine On
RewriteRule ^(.*)$ http://waynekhan.com/v2/ [R=301,L]

Permanent (301) redirect some_page.htm (note to prefix your URL with “^/” and escape fullstops (.) with “\”):

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/some_page\.htm
RewriteRule ^(.*)$ http://waynekhan.com/v2/some/page [R=301,L]

That’s all for now, folks!


PHP4 issue (v4.4.5)

I just spent the last 3 hours trying to figure out how come, after upgrading the PHP version on my web server, two websites were broken.

In particular, these two were done using my colleague’s new framework — which is pretty good — but they just wouldn’t work.

Apache2 would prompt to download the .php file, and when I saved it, it was blank. Great. In the 2nd website, the page would be blank instead.

Now, I’m not really very cool about upgrading PHP, in fact I’d much rather get my sysadmin to do it, but tonight called for urgency. Yeah. So it was up to me.

So i used almost the same ./configure parameters except I wanted the imap_* functions:

# ./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql \
--with-curl --disable-debug --enable-ftp --enable-inline-optimization \
--enable-magic-quotes --enable-mbstring --enable-mm=shared \
--enable-safe-mode --enable-track-vars --enable-trans-sid \
--enable-wddx=shared --enable-xml --with-dom --with-gettext \
--with-regex=system --with-xml --with-zlib-dir=/usr/lib \
--with-zlib-dir --with-ttf --with-freetype-dir=/usr/local/include/freetype2 \
# make
# make install

All went fine of course. I tried with different options, with-apxs2, with-mysql and with-imap. Didn’t work as well. Then I sought Google:

“php script downloaded instead of rendered”

Nothing much actually. Maybe it was the search keywords. There was a post on the WordPress forum about Apache, okie so I decided to upgrade Apache as well. Risky, but it was late, so what the heck. Pissed off already. After compiling the new Apache 2.0.x version, I recompiled PHP. Nope, didn’t work.

So I figured I’d to trace the PHP script, comment/uncomment until I came to this one line:

session_register("foo", "bar");

Ahhah! Later I went into the Apache2 logs and lo and behold, there was a segfault error message which I had blithely not thought to read. Yeah. This bug is resolved in CVS, but I’m really pissed now, so I reverted to v4.4.4, and it worked like a charm.


#apache, #linux, #php

PHP5 on Fedora Core 6 (64-bit)

# gunzip -dc php-5.2.1.tar.gz | tar -xof -
# cd php-5.2.1
# ./configure --with-apxs2=/usr/local/apache2/bin/apxs \
--with-mysql \
checking for MySQL support... yes
checking for specified location of the MySQL UNIX socket... no
checking for MySQL UNIX socket location... no
configure: error: Cannot find MySQL header files under yes.
Note that the MySQL client library is not bundled anymore!
localhost# mysql -v
zsh: command not found: mysql

Great! MySQL is not installed! Gotta head over to the MySQL website for more progress. Look for Linux (non RPM downloads), for platform Linux (AMD64 / Intel EM64T).

Now… Linux is really powerful, way more than Windows ever could be IMO but to even have a decent LAMP — that’s Linux, Apache, MySQL and Perl/PHP — for development purposes only going, the learning curve is so steep.

In contrast, I could just get XAMPP and have a development server on Windows running really quickly.

* update *

Yessss… the install for the AMD64 binary went through like a dream! I didn’t even know it was a binary at first:

# gunzip -dc mysql-standard-5.0.27-linux-x86_64-glibc23.tar.gz | tar -xof -
# ./configure
NOTE: This is a MySQL binary distribution. It's ready to run, you don't need to configure it!
Starting the mysqld server.  You can test that it is up and running
with the command:
./bin/mysqladmin version
localhost# Starting mysqld daemon with databases from /root/mysql-standard-5.0.27-linux-x86_64-glibc23/data
STOPPING server from pid file /root/mysql-standard-5.0.27-linux-x86_64-glibc23/data/wayne.sg.pid
070217 16:19:26  mysqld ended

OK, some problems, it started, then stopped on its own. Fine. I looked for INSTALL-BINARY, and lo and behold:

# groupadd mysql
# useradd -g mysql mysql
# cd /usr/local
# mv /root/mysql-standard-5.0.27-linux-x86_64-glibc23/ /usr/local/
# cd /usr/local/
# ln -s mysql-standard-5.0.27-linux-x86_64-glibc23 mysql
# cd mysql
# scripts/mysql_install_db --user=mysql
# chown -R root  .
# chown -R mysql data
# chgrp -R mysql .
# bin/mysqld_safe --user=mysql &
# ps -aef | grep mysql
root     18474  7962  0 16:14 pts/1    00:00:00 /bin/sh bin/mysqld_safe --user=mysql
mysql    18492 18474  0 16:14 pts/1    00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql --pid-file=/usr/local/mysql/data/wayne.sg.pid --skip-external-locking
root     19031  7962  0 16:23 pts/1    00:00:00 grep mysql

Yes… it worked!

Now back to PHP:

# cd /root/php-5.2.1/
# ../configure --with-apxs2=/usr/local/apache2/bin/apxs \
--with-mysql \
--with-libdir=lib64 \
--with-mysql=/usr/local/mysql \
checking for MySQL support... yes
checking for specified location of the MySQL UNIX socket... /usr/local/mysql/data/wayne.sg.pid
checking for MySQL UNIX socket location... /usr/local/mysql/data/wayne.sg.pid
configure: error: Cannot find libmysqlclient under /usr/local/mysql.
Note that the MySQL client library is not bundled anymore!

Hmmm. I installed MySQL server, now I need the client.

# rpm -ivh MySQL-client-standard-5.0.27-0.rhel4.x86_64.rpm
error: Failed dependencies:
perl(DBI) is needed by MySQL-client-standard-5.0.27-0.rhel4.x86_64

Noooooooooooooooooooooooooooooooooooo. Luckily I am familiar with installing CPAN modules. But I wonder why Perl DBI is required?!? Nevermind. Will figure that out again. I guess.

# gunzip -dc DBI-1.53.tar.gz | tar -xof -
# cd DBI-1.53
# perl Makefile.PL
# make
# make test
# make install

Same goes for DBD-mysql, since I am be doing Perl development in future.

# gunzip -dc DBD-mysql-4.001.tar.gz | tar -xof -
# cd DBD-mysql-4.001
# perl Makefile.PL
# make
# make test
# make install
# rpm -ivh MySQL-client-standard-5.0.27-0.rhel4.x86_64.rpm
error: Failed dependencies:
perl(DBI) is needed by MySQL-client-standard-5.0.27-0.rhel4.x86_64

Argh. What’s wrong? Here’s what’s wrong. This is the 3rd time I have encountered issues with 64-bit. So much for bleeding edge. The advice was to skip the dependency checking:

# rpm -ivh --nodeps MySQL-client-standard-5.0.27-0.rhel4.x86_64.rpm

*update2 *

I STILL can’t get php to compile with MySQL support, the error is something like “can’t find libmysqlclient”. Shall skip the –with-mysql options until I can figure out what’s wrong. Google-ing resulted in alot of links but no help so far.

#apache, #mysql, #php, #red-hat

Apache2 on Fedora Core 6 (64-bit)

This blog post is a lifesaver.

CPU: AMD Opteron 144 (UP)
OS: FC-6-x86_64 (in VMWare Player)

Download this, save as /home/wayne-devel/patch.txt. Then run commands (as root):

# gunzip -dc httpd-2.2.4.tar.gz | tar -xof -
# cd httpd-2.2.4/srclib/apr-util/build/
# patch apu-conf.m4 /home/wayne-devel/patch.txt
# rm configure
# cd ../../../
# rm configure
#. /buildconf
# ./configure --enable-mime-magic --enable-expires \
--enable-headers --enable-ssl --enable-http --enable-info \
--enable-dir --enable-rewrite --enable-so --enable-isapi \
# make
# make install

Steps 3-4 solves this bug, that strangely hasn’t made itself into the stable version of Apache proper. Ugh. Total time: 5 hours. There goes the beauty sleep, then.

Will try installing PHP/MySQL when the sysadmin mood strikes again. Soon I hope.

#apache, #red-hat