Installing apache from the source require the —devel package to be installed on your server. You can find the latest available version of Apache, you can download it here. In order to see all configuration option available for Apache, you can use.
The —enable-so option, can load required modules to apache at run time via the DSO mechanism rather than requiring a recompilation. Once the installation completes, you can browse the web servers default page with your favorite browser. If firewall is enabled on your server, you must have to make exception for port 80 on your OS firewall. You can use the following command to open port You can see the default Apache2 Welcome screen by browsing your server IP address.
You do not need separate server machine and apache software for each website. This can achieved using the concept of Virtual Host or VHost. Any domain that you want to host on your web server will have a separate entry in apache configuration file. In order to configure name based virtual hosting, you have to set the IP address on which you are going to receive the Apache requests for all the desired websites. You can do this by NameVirutalHost directive within the apache configuration i.
You can add as many virtual hosts, as per your requirement. You can check your web configuration files with:. In order to setup IP based virtual hosting, you need more than one IP address configured on your server.
So, the number of vhost apache will depend onnumber of IP address configured on your server. If your server has 10 IP addresses, you can create 10 IP based virtual hosts. In the above diagram two websites example1. It allows Apache to interpret.
Php files. You can also check it with:. FastCGI i. It starts sufficient number of instances of CGI to handle concurrent web requests. It also uses suexec to support different users with their own instances of PHP and improves web security. Apache can also handle ruby files through FastCGI. If you like to enable or disable these modules, you have to edit the apache configuration file and comment or uncomment these modules, if the web server is already compiled with these modules.
Apache displays its version and the name of the operating system in errors as shown in below screenshot. This package includes tools that will be useful to benchmark Apache, manage basic and digest authentication to web pages, and resolve IP addresses to host names in the logs, among other things. However, before you proceed please keep in mind that installing packages require administrative privileges, so you will need to run the following commands either as root in CentOS or using sudo in Ubuntu.
With that in mind, let us proceed with the installation. Typically, that is the case in Ubuntu but not in CentOS. Otherwise, if it is stopped as we forced it to using sudo service apache2 stop which is also shown in the image you will need to run sudo service apache2 start to restart it.
By now, you can safely ignore the AH error message as it refers to an aspect of the web server configuration that we will cover in the next tutorial of the Apache series. Figure 1. In Ubuntu, the installation process by default will configure it to start after a reboot whereas in CentOS, you will need to start it by hand: systemctl start httpd and enable it for future reboots: systemctl enable httpd This ensures that Apache will be started by systemd each time the machine boots. In Ubuntu, you can also get more information about Apache web traffic statistics, server load and uptime, percentage of CPU usage, number of requests currently being processed, to name a few examples using apachectl status In CentOS this command is aliased to systemctl status httpd so you will not get more details than those shown in Fig.
Although we will discuss this further in later articles, you need to know that Apache not only is used as a standalone server that is, to store a single website or application , but also to run several sites also known as virtual hosts at the same time. For the time being, it is sufficient to indicate the place where the web server stores pages and see how it returns them upon a request performed by a client - all in the context of a standalone server.
Then try to access the web server by IP as explained earlier. To replace this default test page by one of ours, create a simple html file and save it as index. You have already taken your first step towards mastering Apache. In addition, we showed you how to replace the default test page with a custom one. In the next articles of this series, we will discuss in greater depth the capabilities of Apache. Stay tuned. If you took the time to read the introduction, you will have noticed that it is the number one server powering websites and Internet-facing computers - and there are plenty of good reasons for that.
In this guide we will discuss one of those reasons: its easiness of configuration and seamless integration with server-side scripting languages such as PHP in the context of a standalone web server. In this type of setup, Apache is used to serve a single domain or application, as opposed to running several sites off a single system also known as virtual hosting, the topic of our next tutorial. Note: The configuration syntax and directives of Apache have changed a bit from version 2. In addition, some well- known directives in version 2.
If you followed the steps in the previous tutorial, you should have installed the latest version of the web server 2. As you can see in Fig. Thus, it is to be expected that the main configuration file be named differently httpd. Regardless of the distribution, the main configuration file contains the configuration directives that give the server its instructions. You will use this file to configure system-wide settings for the web server, and additional files to set up virtual hosts but again, we will expand more on that last topic in the next guide.
It is important to note that you should understand and familiarize yourself with the directives in the configuration file before making changes that can potentially affect the operation of the web server. Although we will discuss modules in later guides of this series, it is important to have this definition in mind before we dive into the configuration directives.
You will see the reason in a minute. All of them and many, many more! This tool can come in handy if at a given time you cannot access the Internet to check the same resource online. The default is listening on port 80 of all network interfaces, although it is more secure to specify a single IP address.
It is usually good practice to create a dedicated user and group for running Apache, as it is the case with most system services. Problems with the server will localhost be sent to this address. ServerName The hostname and port that the server ServerName www. Although all requests are taken made to this directory, you can create symbolic links to point to other locations. Possible values include: debug, info, notice, warn, error, crit, alert, emerg When a particular level is specified, messages from higher levels indicated by the numbered list above will be logged as well.
Wildcards and other regular that apply only to expressions are allowed. If an absolute path is not used, it is relative to the ServerRoot directory. To view the values of a certain directive quickly from the command line instead of opening the configuration file, you can use grep as follows. If you click on the Directives link at the top of the page see Fig. Choose any directive we will use Include as example and click on the link to be redirected to the detailed description.
Pay attention to the highlighted area in Fig. In the case of Include, the description indicates that it can only be used in the system-wide server configuration, inside a virtual host definition, and within Directory tags. If you attempt to use it in a different place or inside the wrong set of tags such as inside IfModule or Files , the web server will complain about it by refusing to restart correctly. These settings allow to grant access to resources after a user has entered valid credentials.
Although there are other authentication mechanisms, we will only cover basic authentication in this guide which consists of username and password for brevity. Please be aware that this method sends the password from the server to the client unen- crypted, so it should not be used with sensitive data in a later tutorial we will introduce more secure options. You can refer to the Authentication and Authorization page of the documentation for further details.
If you want to add other users to the same file, use htpasswd as explained earlier, only omitting the -c switch since the file now exists no need to create a different one. You will recall that we created a simple page named index. This directory, as you have learned in this guide, is of special importance as it is the default DocumentRoot. We need to serve a file named restricted. Other files present inside DocumentRoot must be accessible to all users without authentication.
Of course, this approach assumes this file exists in that directory already. MaxConnectionsPerChild : Like the Unix directive, this controls how many connections a single child process will serve before exiting. However, unlike on Unix, a replacement process is not instantly available. Use the default MaxConnectionsPerChild 0 , unless instructed to change the behavior to overcome a memory leak in third party modules or in-process applications.
ThreadsPerChild : This directive is new. It tells the server how many threads it should use. This is the maximum number of connections the server can handle at once, so be sure to set this number high enough for your site if you get a lot of hits. The recommended default is ThreadsPerChild , but this must be adjusted to reflect the greatest anticipated number of simultaneous connections to accept.
The directives that accept filenames as arguments must use Windows filenames instead of Unix ones. However, because Apache may interpret backslashes as an "escape character" sequence, you should consistently use forward slashes in path names, not backslashes. While filenames are generally case-insensitive on Windows, URLs are still treated internally as case-sensitive before they are mapped to the filesystem.
If you wish to assure that only lowercase is used in URLs, you can use something like:. When running, Apache needs write access only to the logs directory and any configured cache directory tree. Due to the issue of case insensitive and short 8. This means that each directory which Apache evaluates, from the drive root up to the directory leaf, must have read, list and traverse directory permissions. If Apache2. Apache for Windows contains the ability to load modules at runtime, without recompiling the server.
To activate these or other modules, the LoadModule directive must be used. For example, to activate the status module, use the following in addition to the status-activating directives in access. Information on creating loadable modules is also available. More information is available. When running CGI scripts, the method Apache uses to find the interpreter for the script is configurable using the ScriptInterpreterSource directive. Since it is often difficult to manage files with names like.
This mechanism acts as a backup for those situations where Apache is not yet prepared to use the error. Apache comes with a utility called the Apache Service Monitor.
With it you can see and manage the state of all installed Apache services on any machine on your network. To be able to manage an Apache service with the monitor, you have to first install the service either automatically via the installation or manually. You can install Apache as a Windows NT service as follows from the command prompt at the Apache bin subdirectory:.
If you need to specify the name of the service you want to install, use the following command. You have to do this if you have several different service installations of Apache on your computer. If you specify a name during the install, you have to also specify it during any other -k operation.
If you need to have specifically named configuration files for different services, you must use this:. If you use the first command without any special parameters except -k install , the service will be called Apache2. Before starting Apache as a service by any means, you should test the service's configuration file by using:.
You can control an Apache service by its command line switches, too. To start an installed Apache service you'll use this:. You can also restart a running service and force it to reread its configuration file by using:. By default, all Apache services are registered to run as the system user the LocalSystem account. It has, however, wide privileges locally. It is recommended that users create a separate account for running Apache service s. If you have to access network resources via Apache, this is required.
If you allow the account to log in as a user and as a service, then you can log on with that account and test that the account has the privileges to execute the scripts, read the web pages, and that you can start Apache in a console window.
0コメント