Wednesday, May 8, 2013

A Patchy Apache


The name "Apache," like most other open-source names is often difficult to trace. For a while, most believed the name was a reference to the Native American tribe--which is admittedly what I believed until running across this quote from an Apache creator:

The name literally came out of the blue. I wish I could say that it was something fantastic, but it was out of the blue. I put it on a page and then a few months later when this project started, I pointed people to this page and said: "Hey, what do you think of that idea?" ... Someone said they liked the name and that it was a really good pun. And I was like, "A pun? What do you mean?" He said, "Well, we're building a server out of a bunch of software patches, right? So it's a patchy Web server." I went, "Oh, all right." ... When I thought of the name, no. It just sort of connoted: "Take no prisoners. Be kind of aggressive and kick some ass."
—Brian Behlendorf
That, my dear friends, is how you name a project. You just come up with something that sounds cool and hope you don't step on any toes.

That being said, the Apache web server is decently easy to set up, and is your first step to creating your LAMP server (after, of course, installing linux). A decently detailed guide to follow can be found on the Arch Wiki. In most cases, your first step is to create a new userspace for the Apache server, though this is not recommended for simple testing, it is a good idea if you intend to keep the server's files distinct from any other files on your computer. This can be done by using the useradd command:


# useradd -m -g [initial_group] -G [additional_groups] -s /bin/bash [username]


-m creates a home directory like any other user

-g sets inital groups

-G sets additional groups

-s sets the initial login shell (typically /bin/bash)

Again, for these purposes, you can use your standard user. Once you have chosen the user you wish to use, make sure Apache is installed and start the daemon. In Arch this can be done with:


# systemctl start httpd


In Ubuntu:


# service httpd start


To verify the daemon started, check http://localhost/. If you don't see an error, you are fine. If you like you can add the following contents to /srv/http/index.html:

<html>
<title>Welcome</title>
<body>
<h2>Hello World!</h2>
</body>
</html>

Now when you check http://localhost/, you should see:


Which is kinda cool. Now, let's move on. If you wish to view user directories, visit http://localhost/~user/. If, for example, your Apache user was "leios," type in "~leios" instead of "~user" into the URL. If you can see simple directories, you are on the right path. If not, edit the following line in  /etc/httpd/conf/extra/httpd-userdir.conf to include your username:

<Directory "/home/user/public_html">

Then restart the httpd daemon:

# systemctl restart httpd

In Ubuntu:

# service httpd restart


We now need to make a public_html directory for future formatting:

$ mkdir ~/public_html

Next we have to make all of your executable files executable for everyone visiting your site (which shouldn't be anyone on your localhost). Assuming you are logged in as your Apache user, type in:

$ chmod o+x ~
$ chmod o+x ~/public_html

Alternatively, you could create a group that shares your Apache user's home directory and add the user "http" to it. Once done, give all visitors read and execute permissions like so:

$ chmod g+xr-w /home/yourusername
$ chmod -R g+xr-w /home/yourusername/public_html

And there you have it, everything should be working fine. It might not look pretty, but within the next few days, we will work on that. In typical linux fashion, there is a giant file to modify to make sure all of your settings are customized to your liking. In this case, the file is: /etc/httpd/conf/httpd.conf. Feel free to check it out. It will definitely help you understand what is going on if you take the time to read it through. Whenever editing files like these, it is wise to create a back-up, so that if you screw up, you still have a stable version to go back to. Once you have finished editing everything, be sure to restart the httpd daemon.

We will return to the Apache server later when working on servers that are not doubling as home workspaces. For now, we have configured Apache for testing of sites on http://localhost/, which is enough for today.

Thanks for reading,
-Leios

No comments:

Post a Comment