Configuring Apache: step by step instructions

Table of contents:

Configuring Apache: step by step instructions
Configuring Apache: step by step instructions
Anonim

Professional development always focuses on its own tools - this is a guarantee of reliable and efficient fulfillment of obligations. Own hosting and servers for various purposes in a range of popular configurations expand the scope of tasks to be solved, increase the security and confidentiality of developments.

Native HTTP: Apache, PHP, MySQL

The Apache web server has been a solid leader since the last century because it provides a fast, reliable and secure experience. A physical machine and a server running Linux or Windows is the foundation, HTTP is the add-on, although it is essentially a communication protocol. A Windows machine can be used as a server, but the Linux family is preferred.

Apache on Windows is a local variant used on a single machine to duplicate the development of resources hosted on external servers. Installing on Windows Server is acceptable, but not very popular. Setting up Apache on CentOs gives more options and is used to organize servers in the local andglobal networks.

It is believed that Apache servers serve more than 50% of all active web resources, the rest falls on similar products from Microsoft, Sun and others. Actually, the physical server and its operating system can be anything. The HTTP server is placed on a ready-made platform and works in parallel with other applications on it. Apache is considered native to the entire Linux family, but in each case it has its own peculiarities.

Apache setup
Apache setup

Free, simple, reliable Linux systems and their applications. It doesn't matter what you use: Installing and configuring Apache on Ubuntu is not much different from CentOs, Debian or FreeBSD. Often the saturation of a particular operating system with additional software plays a role.

The Linux family is small in terms of the number of "relatives" on the line of one or another core of the system. The differences are more of a social nature - in the sense of developers' attachment to the formulation and implementation of the operating system's capabilities.

In reality, in order to solve a specific task to raise hosting, you need to decide on the necessary functionality, required performance, conceptual priorities and a specific choice of a Linux representative, or stop at Windows Server.

Shift in local development priorities

It is difficult to assess the role of the global network in the development of programming, but it is easy to see a real shift in the center of gravity: it has become customary to execute local applications as a web resource. Just write a program forlocal computer - these are drivers, antiviruses, small projects with simple functionality. Programming language … VBA, although C/C++ or C can be used.

Any information project is a web resource in the company's local network, which can be partially accessed from the global network, for example, to coordinate the actions of employees outside the office, on the road or on a business trip.

MySQL, PHP, Apache: setting up for a local use case - a completely different dynamics of the application, the necessary functionality. Today's companies, regardless of size, number of employees and industry, are seriously considering Internet programming, both local and global.

Local Development Priorities
Local Development Priorities

At the same time, local programming of a web resource can be distributed: company offices can be located anywhere, but this is not the Internet, but a distributed local network of the company.

MySQL, PHP, Apache setup in local form:

  • easy to duplicate across network computers;
  • provides the ability to dynamically change the active component or match it with a sample to evaluate hacking attempts;
  • gives a reason to develop a security system devoid of the risk of being attacked by classical network methods.

If we take into account that MySQL and Apache in the Windows environment are services, and PHP code is plain text processed by a tool (PHP interpreter) called at the right time by an HTTP server, then the level of mutability, mobility and code portability will besignificantly higher than local development tools.

Preparing for Apache installation

Even in the "beginning of the beginning" era, the Unix operating system defined the unspoken principles of loy alty. Since then, everything that was done under Unix-like systems was automatically translated to other platforms. Setting up Apache on Windows is extremely easy, but serious tasks require a good level of experience and a detailed understanding of HTTP server configuration.

First of all, you need to download the latest version of the server (today it is version 2.4.33 dated 2018-17-03) from the official website in zip-archive format. It should be borne in mind initially that server versions are numerous and offered on many third-party resources, so it is important to choose an official implementation hosted on a trusted web resource.

apache centos setup
apache centos setup

Previously, it was popular to install a server through a special installer. It is now common practice to simply expand a zip archive. This is easier and makes it possible to understand the essence of the configuration process, which is very important and subsequently allows you to optimize the server for the desired load and functionality.

Editing the configuration file

Server configuration is determined by a set of configuration files located in the conf folder. The main Apache configuration file is

In the vast majority of cases, it is necessary to make changes to the main file, clarify the contents of the files responsible for ssl and virtual hosts. Other settings are usuallyare made during the operation of the server as problems arise or tasks are solved. Basically, further settings are related to optimizing Apache or expanding its capabilities.

To successfully launch the server, it is enough to edit only one line (in order - the 38th) - and the Apache configuration is completed.

apache ubuntu setup
apache ubuntu setup

In previous versions of the server configuration, it was necessary to make numerous changes to the real situation, but now there is a "universal" SRVROOT variable. It is worth specifying its correct value (the path to the server location), and everything will work right away.

Server Deployment Procedure

You need to be careful about the location of the server. Apache itself is interesting, but when it's equipped with PHP and MySQL, it's doubly interesting. It's better when everything related to web development is in one place. You can agree to default paths, but modern programming is not so ideal in its implementation, so you will have to keep your finger on the pulse unambiguously and often. In addition, when choosing a convenient location, all initialization and configuration files, as well as logs on the operation of installed products will be available.

Downloaded official Apache zip-archive should be deployed to the chosen location, placing tool and work separately. In this example, the C:\SCiA folder is the tool (Apache24, PHP, MySQL, …), and the SCiB folder is the work of the websites that are created, maintained, or upgraded.

apache installation and configuration
apache installation and configuration

As a resultAt the first stage of work, only the bin, cgi-bin, conf, error, … subfolders with all their contents get into the C:\SCiA\Apache24 folder.

Edit hosts file

The second step is to properly set up the hosts file - an indication of which IP addresses on a given computer are mapped to which names. If the computer will be developing or maintaining only one site, then you can not change anything.

The base IP - 127.0.0.1 usually always points to localhost. The working hosts file is located at c:\Windows\System32\drivers\etc and looks like this.

apache ssl setup
apache ssl setup

To put the hosts file in the right place, you need to use the command line in administrator mode. You can prepare the correct contents of the file anywhere on your computer's file system, but you can only write it to c:\Windows\System32\drivers\etc with a tool that has administrator rights. The easiest way to do this is through the command line.

Install Apache server

There is nothing easier. It is enough to run the command prompt as an administrator and go to the C:\SCiA\Apache24 folder. Since this is a path on a Windows system, forward slashes are used. In a particular case, the path may be different. But if you can still experiment with the folder name for hosting the holy trinity - Apache, PHP and MySQL - then changing the folder names for each of them is not practical.

php apache setup
php apache setup

In this case, the server archive is deployed in the C:/SCiA/Apache24 folder,therefore, you need to write the command in the bin folder:

httpd.exe -k install

The server will test the configuration file and install itself. Most likely there will be minor errors, but if you edit the configuration file correctly, then all errors will be minor and can be quickly fixed.

Window (1) of the command line - installing the service, window (2) - the list of services in which the server appeared, window (3) - the index.html source file located at С:/SCiB/localhost/www, window (4) - the result of the server.

In this example, a mistake was deliberately made: instead of setting the value of the SRVROOT variable, numerous edits were made "the old fashioned way": everything was manually changed. This is not the best solution. Before applying knowledge, you should familiarize yourself with the current version of the product. As a rule, things change quickly, and knowledge should be applied “with knowledge of the matter and understanding of the current situation.”

The practice of deploying a zip archive

Modern sites are not always written on content management systems. There is a lot of manual labor. The problem of transferring the site to another hosting led to a good solution - a zip archive. Collapsed content in one place, expanded it in another.

Deploying a zip archive
Deploying a zip archive

Having an installer is good practice, but the dynamics of modern information technology does not give time to write beautiful installations. Use installation via zip-archive deployment - modern, practical and convenient. In this option, Apache configuration is limited to changing configuration files.

When installing the server, it is important to specify:

  • where he is;
  • where the web resource is located (localhost);
  • using ssl;
  • virtual hosts.

The last position is relevant when it is supposed to develop or maintain several resources at once on the server. For a real developer, this is a must-have: even if it provides the work of one site, it will not be superfluous to have a fallback.

Gentlemen's sets

Easy to deploy a zip archive is obvious, Apache (installation and configuration) is only two or three clicks away. However, the result when installers were popular was equivalent. The developer simply spent more time developing the next version of his product. Installing the server, server language, and database is essentially just a set of files, starting services, a hosts file, and default paths in the operating system variable path.

The advent of Denver and similar gentlemen's development kits was a revolutionary step in the line of simplicity and convenience, but make no mistake. Revolution and programming are absolutely incompatible things. The first is a child of a conflict and its stormy resolution, the second is a serious matter that requires absolute calmness, punctuality, accuracy, consistency, attentiveness, safety, reliability.

Configuring the Apache server is a serious procedure that needs to be taken very carefully and everything must be done so that tomorrow you can change and clarify something.

In most cases, web developmentresources are quite long processes in which the requirements for services (Apache, PHP, MySQL, …) change quickly, but there is always time to understand the next task and its optimal solution. But this is not a reason to go on about gentleman's sets. Time passes, but the gentleman does not change, this is a much more compelling argument than the Denver declaration - it's simple, fast and affordable.

Multiple sites - one server

Setting up Apache 2.4 for a single host is an unjustified luxury. Despite its compact design, this server bears a huge weight of responsibility for more than half of the active web resources of the Internet. In addition, not all resources have a representative part and are visible on the web.

The server can be used as a database, as an information transfer point, as a filter, as a parser, as a working mechanism in a more global information process. As a result, setting up Apache virtual hosts is almost always a must.

One server can support as many web resources as you want, for this you need to uncomment the line 501 in the httpd.conf file:

Include conf/extra/httpd-vhosts.conf

and describe all the necessary hosts in the file

extra\httpd-vhosts.conf

You may need to clarify which ports and IP the server is listening on, but this is a separate issue, for the first time you can limit yourself to what is.

apache 2.4 setup
apache 2.4 setup

It should be noted that in the example, for the convenience of describing real virtual web resources (and there are many of them), a variable is introduced(DOCROOT) with the path to the shared folder of all web resources available through the installed server.

Apache SSL configuration is available in a similar way. In the httpd.conf file, you just need to leave "as is" lines from 524 to 531, which are responsible for the operation of SSL.

Apache simplicity and complexity

The days when setting up a server was a real challenge are long gone. Today, setting up Apache is a very simple procedure that does not require special skills from the developer.

Three easy steps:

  • expand archive;
  • change configuration file;
  • install the server.

As a result, Apache is fully functional. If you do not take into account the subtleties of the process of running the server at maximum load or do local development on a Windows computer, no additional knowledge is required.

Difficulties can arise on Linux systems. Significantly different understanding of the file system, user and group rights, as well as the organization of the process of interaction with other applications require the developer to be more competent and understand how Linux computers work.

Configuring Apache on any Linux system opens up much more possibilities for the developer and provides access to the local network and the Internet. By tradition, a Windows computer is a local workstation, and the server is internal there. A Linux computer is a file server, a web server, and a local network node or point in Internet space.

Professional environmentdeveloper

Apache is a fundamental building block of the Internet space that can be easily and easily configured, used and will become the backbone of a company's network infrastructure.

This logic assumes that there is at least one server on the network running CentOS, Ubuntu, FreeBSD, Windows workstations. It is optimal to have two Linux servers (main and auxiliary), Apache setup for a local computer in a Windows environment. In the event of a virus attack or an unforeseen situation, the auxiliary server will replace the main one, and the main one will be repaired and restored. You can replace the local installation of Apache on a workstation (under Windows) from the archive.

This trivial solution can be refined and supplemented in real practice. The size of a company's information flows can determine the desired configuration and the required number of servers. Actually, Apache is designed to work under load, but nothing prevents you from distributing the responsibilities of one server over several. A solution that takes into account the characteristics of a particular company is always more promising than adapting a third-party option.

Recommended: