Lesson: After running emerge –update, pay close attention to the the changes in configuration files proposed by etc-update. I didn’t, and caused myself a lot of avoidable grief. During one of my system-wide updates, I trashed Apache’s config files. Being the slightly retarded geek wannabe that I am, I had a heck of a time tracking down the information I needed to get my LAMP server running the way I wanted it to.
After much Clustying, file editing, head-banging, hair-pulling and cussing, I found out that it was pretty much working in the first place. All it needed was a couple of minor tweaks.
I first noticed something was wrong when I fired up the test website I have lurking in my /home/lizardbrain/public_html directory. The pages all loaded, but instead of being interpreted, the PHP script was rendered as text. It didn’t take me long to find that I needed to add some stuff to /etc/conf.d/apache2 (file paths are the ones on my Gentoo box; your distro may stash the files in other places). The first thing I did was add “-D PHP5” to the APACHE2_OPTS line in /etc/conf.d/apache2. It still didn’t work — I kept getting “Not Found” error messages. Actually, I had fixed about half the problem and didn’t know it, so I continued to clusty and tweak the config files. Most of what I did was unnecessary, but at least didn’t break anything. What finally gave me the clue that I was on the wrong track was when I restored /etc/apache2/httpd.conf to its original condition and copied a .php file from my public_html directory to the server’s home directory: it worked. All I needed to do from that point was get Apache to serve pages to my test site.
For those of you who got here by querying the search term “apache2 Invalid command ‘UserDir’,” /etc/apache2/httpd.conf does not allow the setting of “UserDir public_html.” What I had to do was add another option, “-D USERDIR,” to /etc/conf.d/apache2. Then I had to edit /etc/apache2/httpd.conf to add UserDir instructions.
Here’s what it boiled down to:
In /etc/conf.d/apache2, add
-D PHP5 -D USERDIR
to the APACHE2_OPTS line. Make sure you add these options within the existing quotation marks.
In /etc/apache2/httpd.conf, add
This gave me basic functionality. Since there is no public access to this computer, I didn’t bother to add anything else to /etc/apache2/httpd.conf to restrict access. For those who need more security, I got this from the Gentoo Forums:
# Control access to UserDir directories. The following is an example
# for a site where these directories are restricted to read-only.
# <Directory /home/*/public_html*gt;
# AllowOverride FileInfo AuthConfig Limit Indexes
# Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
# <Limit GET POST OPTIONS PROPFIND>
# Order allow,deny
# Allow from all
# <LimitExcept GET POST OPTIONS PROPFIND>
# Order deny,allow
# Deny from all
# Enable this additional section if you would like to make use of a
# suexec-enabled cgi-bin directory on a per-user basis.
# Options ExecCGI
# SetHandler cgi-script
Now, when I point my browser to http://mygentoobox/~lizardbrain/, my test site appears, and php scripts are rendered correctly. As usual, the Gentoo Forums were my best friend, once I figured out the correct search terms.