Setting up Apache on a Solaris 10 System
First you need to create an httpd.conf configuration file.
There is an example configuration file, httpd.conf-example in
/etc/apache2. You can use it as a starting point.
# cd /etc/apache2
# cp httpd.conf-example httpd.conf
Apache will run with the username of webservd
and the group of webservd when using the default configuration
provided when Solaris 10 was installed, which means you will
find the following two lines in the httpd.conf file.
User webservd
Group webservd
With the default setup, you should also have the following
entries in /etc/passwd and /etc/group.
# grep webservd /etc/passwd
webservd:x:80:80:WebServer Reserved UID:/:
# grep webservd /etc/group
webservd::80:
You should find the following line within httpd.conf and modify
the email address to be the email address which you would like
to use to receive email related to problems with the web server.
ServerAdmin you@yourhost.com
Next find the following line.
ServerName 127.0.0.1
ServerName is the name that the server uses to identify
itself. It should be set to a valid DNS name for your
host, e.g. www1.example.com, or, if no DNS name is
available, then the IP address for the system. Note: this
does not preclude having multiple domain names handled
by one server through virtual hosts. This name should
be the primary name for the system if you will have
multiple websites hosted on the system with unique
domain names. You can also include a port number
after the name, e.g. www1.example.com:80.
Next find the following line.
DocumentRoot "/var/apache2/htdocs"
This specifies the directory out of which you will
serve your documents. If instead, you would like
to place your website under /home/www, you would
change the line accordingly. Don't put a slash
at the end of the directory name.
With the default configuration, if someone visits
your website, the IP address of her system will
be stored in Apache's log files. If you want the
Fully Qualified Domain Name (FQDN) stored as well,
change the following line from "Off" to "On". E.g.,
if you would like www.apache.org as well as
204.62.129.132, you would change the value to
"On".
HostnameLookups Off
Changing the value to "On" means it is more
apparent from the log files where your visitors
are coming from, but adds additional bandwidth
usage, because every time someone visits the
website, the server must perform an IP address
to name lookup. If you are likey to get only
a few hundred or less hits on the websites on
the server per day, then the name lookups
will be adding little traffic, but if you
expect hundreds of thousands of hits a day,
it might be preferable to leave HostnameLookups off.
If someone tries to access a webpage on the
server, but it doesn't exist or there is
some other problem accessing the webpage,
errors will be logged in the log file
specified below by default. You can have
the error log somewhere else on the system
by changing the ErrorLog value.
ErrorLog /var/apache2/logs/error_log
A web server can tell browser clients the
language that is used for webpages on the
server when one is not listed specifically
on webpages residing on the server. With
the default configuration, the DefaultLanguage
value is commented out, i.e. there is a "#" at
the beginning of the line.
#DefaultLanguage
If you know all of the pages on your
web server will be in one language,
you can change this line. E.g., to
indicate that all pages on the server
are in English, I could change the
DefaultLanguage line
to the one below.
DefaultLanguage en
When you start Apache, it records its process
identification number, aka Pid, in a
specified location. The location is
controlled by the value of PidFile.
Make sure the directory exists. If
you use the default value of /var/run/apache2/httpd.pid,
you will need to create the /var/run/apache2 directory.
PidFile /var/run/apache2/httpd.pid
I use /var/run/httpd.pid
, instead, since
the /var/run directory already exists and is used to store
other pid files and I don't see a need to have a separate
directory under it just for Apache's httpd.pid file,
so I have the following line in httpd.conf.
PidFile /var/run/httpd.pid
You will also need to remove the "#" from the beginning
of the following line, so that it is no longer
commented out.
#LockFile /var/apache2/logs/accept.lock
Otherwise, Apache may not start and you may see
lines like the following in error_log
[Tue Feb 07 17:57:40 2006] [emerg] (2)No such file or directory: Couldn't create accept lock
If you want to have multiple websites
residing on your web server with each
pointing to a different set of documents,
then you need to set the VirtualHost
configuration parameters. E.g., you
might wish to have www.example.com
and www.someother.com accessible on
the same web server. To have
such virtual hosts, first remove
the comment from the line below.
#NameVirtualHost *:80
Then copy the "VirtualHost example" section below
that line and make whatever chanes you desire.
You don't need to specify a unique ErrorLog and CustomLog,
but I would normally recommend having separate log files
for each website hosted on the server, rather than having
all log entries go into an access and error log shared
by all sites hosted on the server. An example VirtualHost
section is shown below.
<VirtualHost example.com>
ServerName example.com
ServerAlias www.example.com example.com
ServerAdmin webmaster@example.com
DocumentRoot /home/jsmith/www
ErrorLog /home/jsmith/www/logs/example-error_log
CustomLog /home/jsmith/www/logs/example-access_log common
</VirtualHost>
You can have aliases for a particular website by specifying
names after ServerAlias
. E.g.
in the example above, someone could put either
http://www.example.com or http://example.com in
his browser and be taken to the same website.
Be sure the directores where the log files will
be stored have been created before you start
the Apache web server. And the DocumentRoot
directory should exist also.
Once you have finished editing the /etc/apache2/httpd.conf
file, you can start the Apache web server with the command
below. Be sure you are logged in as root before issuing the
command.
# /usr/apache2/bin/apachectl start
If you made a mistake in the httpd.conf file or want
to modify the file for another reason, you can edit
it and then restart Apache with the following command.
# /usr/apache2/bin/apachectl restart
Note: if you use the apachectl
command to start Apache,
it won't restart automatically when you reboot the system, unless you
have enabled it as a service or have a script on the system that starts
Apache which gets executed at system startup. To enable Apache to run
as a service and have it restart when the system reboots, use the command
svcadm enable apache
(See
Using the svc and svcadm Commands
).
Where do you look if Apache won't start?
Look in the default error_log file. For instance,
if you left the value of ErrorLog for the
primary site in /var/apache2/logs, check the
error_log file there.
For instance, when I first tried starting Apache
it wasn't starting. I looked in the error_log
file and saw the following.
[Tue Feb 07 17:38:15 2006] [error] httpd: could not log pid to file /var/run/apache2/httpd.pid
I realized the /var/run/apache2 directory didn't exist and
changed the PidFile value in httpd.conf to be /var/run/httpd.pid,
instead. When I then tried starting Apache again, as before I didn't
get any error message on the terminal indicating it had failed to
start, but it wasn't running. I looked in the error_log again.
This time I didn't see any additional entries for the above error
message, but did see the one below.
[Tue Feb 07 17:57:40 2006] [emerg] (2)No such file or directory: Couldn't create accept lock
So I looked through httpd.conf for any references to "lock". I found
#LockFile /var/apache2/logs/accept.lock
. I removed the "#" at the
beginning of the line and attempted to restart Apache. It then
started successfully.
Some additional problems you might encounter
Perhaps you get Apache running successfully, but then
attempt to access a website on the server and get the
following error message.
Forbidden
You don't have permission to access /
on this server.
Additionally, a 403 Forbidden
error was encountered while trying to use an ErrorDocument to handle the request.
Apache/2.0.52 (Unix) DAV/2 Server at example.com Port 80
Check the permissions on the directory that contains the root
of the website. Suppose that the website is housed under /home/jsmith/www.
If you see permissions like the following, then
the permissions are the cause of the problem.
# ls -ld /home/jsmith/www
drwxr-xr-- 4 jsmith staff 512 Feb 7 18:24 /home/jsmith/www
In this case you would need to change the permissions on the
www directory from 754 to 755 so that everyone has execute
permission for the directory. And not only do you have to
change it for the www directory, but for the directory above it
as well, i.e. the user's home directory.
# chmod 755 /home/jsmith
# chmod 755 /home/jsmith/www
[/os/unix/solaris]
permanent link