Installing Apache in CentOS 7

Anonim

Installing Apache in CentOS 7

To administering your site on a local server, you need to install a set of additional components that organize a single system that is planned simultaneously and without any errors. One of the main components of such a structure can be considered a web server. Users most often prefer to use Apache because of its simplicity and flexibility of the setup, as well as the possibility of connecting external modules. However, the installation and main configuration - the process is not fast and even difficult for some, so we would like to tell about it in more detail, taking the CENTOS 7 distribution.

Install Apache in CentOS 7

The structure of today's article will be phased, so that even the most novice user understood exactly how the installation and preparation of the web server under consideration is carried out. Immediately clarify that we do not provide manuals for the detailed adjustment of Apache, as it depends on the user's personal preferences and the existing other important components. For this information, we always advise you to turn to official documentation.

Step 1: Preparation and Installation

Let's start immediately from installing components responsible for the correctness of Apache and add all subsidiary services. We offer the repository of the distribution to use the distribution repository for this, since the last stable version of the software is always laid out, and the installation process itself does not take much time.

  1. Run the "Terminal", for example, through the icon in the "Favorites" section.
  2. Go to the terminal for further installation of Apache web server in CentOS 7

  3. If an Apache has already been installed on the computer or you accidentally deleted one of its components, simply use the Sudo Yum Update HTTPD command by activating it by pressing the Enter key.
  4. Command for checking updates of the current version of Apache in CentOS 7

  5. This action is performed on behalf of the superuser, which means you have to confirm it by specifying a password from this account.
  6. Confirmation of Apache updates check in CentOS 7 by entering a superuser password

  7. If updates are installed, you will be notified of this, and if the packet is missing, then another message of the appropriate character will appear.
  8. Information about the current state of the Apache web server in CentOS 7

  9. Now let's talk about the installation of Apache from scratch. As we have already said, we will use official repository to use for this, therefore, you need to enter the Sudo Yum Install command HTTPD.
  10. A command to start the Apache Web Server Installation in CentOS 7 through the Terminal

  11. When notifying the installation of the package, confirm it by selecting the Y version.
  12. APACHE Web Server Installation Confirmation in CentOS 7

  13. Expect the installation completion, while you do not close the current terminal session so as not to interrupt the process.
  14. Waiting for the completion of the download package Apache in CentOS 7

  15. At the end, it is immediately recommended to start a web server that can be done via Sudo SystemCTL Start HTTPD.
  16. The command to start the service of the installed Apache web server in CentOS 7

  17. Check the current status through the Sudo SystemCTL STATUS HTTPD.
  18. A command to check the current APACHE web server status in CentOS 7

  19. Notification "Active: Active (Running)" implies that now Apache is functioning correctly and you can proceed to its further configuration.
  20. Information about the current state of the installed Apache web server in CentOS 7

It was all that you need to know about the basic procedure for installing a web server. As you can see, nothing complicated in it. Next, we want to talk about interaction with the main services and the installation of the main configuration, and you remains to decide whether it is worth exploring the instructions or knowledge of configuration and management already exist.

Step 2: Apache Management

The web server in CENTOS, as in other distributions, functions in the background in the form of service. By default, it is added to the autoload, and we have already told about activation and validation of the state earlier. If you have a desire to manage this tool, it is carried out like this:

  1. Enter the Sudo SystemCTL STOP HTTPD to complete Apache.
  2. A command to stop the APACHE web server service in CentOS 7

  3. This and all subsequent commands will be executed on behalf of the superuser, so you will need to confirm it by entering the appropriate password.
  4. Confirmation of the Apache stop command in CentOS 7 by entering the password

  5. Restart takes place through the Sudo SystemCTL RESTART HTTPD command. This team is relevant in those situations where the server gives failures or is required to restart it due to the features of interaction with the rest of the components.
  6. Team to restart Apache web server in CentOS 7

  7. Use the Sudo SystemCTL RELOAD HTTPD if it is necessary that all changes after setting entered into force, but none of the connections were broken.
  8. A command to restart the Apache web server in CentOS 7 without disconnecting connections

  9. The Sudo SystemCTL DISABLE HTTPD command removes Apache from autoload, and sudo systemctl enable httpd returns a standard state. Additionally, when you enable this option, you will be notified of creating a new symbolic link that is responsible for this parameter.
  10. Commands to add or exception Apache in CentOS 7 from autoload

As you can see, manage the state of service the most standard teams. They will be easy to remember if you are often forced to resort to such measures during network administration, a separate site or any applications.

Step 3: Basic Configuration

The basic configuration refers to the virtual host configuration, which is useful for the settings and placement of different domains on one server. One standard virtual host is quite enough if you only deal with one site, however, when registering other domains, you will have to resort to the creation of additional parameters. Now for example, we will take a standard virtual host, and you change its address if required.

  1. Let's start with the creation of a catalog where all the daughter of the virtual host will be stored. This is done through the sudo mkdir -p /var/www/example.com/html command.
  2. Creating a folder for storing a new virtual host Apache in CentOS 7

  3. An additional folder is needed, where event logs will be automatically saved. To add it to enter Sudo mkdir -p /var/www/example.com/log.
  4. Creating a folder for storing new virtual hosts APACHE events in CentOS 7

  5. Set the standard rights to the directory through the Sudo Chown -r $ USER: $ user /var/www/example.com/html.
  6. Installing the standard access level for the created Apache folders in CentOS 7

  7. Additional Install and privileges for each user inserting Sudo Chmod -R 755 / VAR / WWW.
  8. The second command for setting the standard access level for the created Apache folders in CentOS 7

  9. We will proceed to create a sample of the main page that will be displayed when checking the workability of the host. Create a new text file through a convenient editor, for example, using Nano, you should enter Sudo Nano /Var/www/example.com/html/index.html.
  10. Starting a text editor for the contents of the Virtual Host Apache in CentOS 7

  11. When you open a text editor, a notification will be notified that this is a new file. Do not worry, because it should be. We specifically create it, exposing the appropriate configuration.
  12. Information on the creation of a new APACHE virtual host page file in CentOS 7

  13. Insert the code below, replacing the standard greeting on arbitrary text. If you want, you can completely redo the structure by creating a suitable page.

    Welcome to Example.com!

    SUCCESS! The Example.com Virtual Host Is Working!

  14. Creating an Apache virtual host page in CentOS 7

  15. Save the changes by clicking on Ctrl + O, and then leave the text editor via Ctrl + X.
  16. Exit from the text editor after creating a Virtual Host Apache Page File in CentOS 7

  17. These were only preliminary settings. Now proceed to the virtual host: you first need to specify folders for its storage. To do this, enter Sudo MKDIR / ETC / HTTPD / SITES-AVAILABLE / ETC / HTTPD / SITES-ENABLED.
  18. Creating a folder for storing APACHE sites in CentOS 7

  19. After that, specify the web server that now he needs to interact with other components. This task is carried out through editing the main configuration file. Run it through a text editor by specifying sudo nano /etc/httpd/conf/httpd.conf.
  20. Transition to global tinctures to specify a new virtual host in Apache in CentOS 7

  21. Run at the bottom of the list and insert the IncludeOptional SiteS-Enabled / * string. CONF.
  22. Changing the Global Configuration File Apache in CentOS 7

  23. Before leaving the text editor, do not forget to save all changes.
  24. Saving changes after global changes to the Apache configuration file in CentOS 7

  25. To create the virtual host, you will need another configuration file. Create it through sudo nano /etc/httpd/sites-available/example.com.conf.
  26. Launching a text editor to create a new Virtual Host Apache in CentOS 7

  27. Insert the content here further, replacing the required rows to yours.

    ServerName www.example.com

    Serveralias example.com.

    Documentroot /var/www/example.com/html.

    Errorlog /var/www/example.com/log/error.log.

    Customlog /var/www/example.com/log/requests.log Combined.

  28. Entering standard contents for the new APACHE virtual host in CentOS 7

  29. It remains only to activate the file by creating a symbolic link through Sudo LN -S /etc/httpd/sites-available/example.com.conf /etc/httpd/sites-enabled/example.com.conf.
  30. Creating a new symbolic link to ensure the performance of the APACHE virtual host in CentOS 7

Step 4: Access Control Setup

If it comes to setting up global parameters, it is necessary to provide access control, indicating a number of users who will be able to make changes to the previously considered directories. This procedure is performed using the standard Selinux tool responsible for managing access levels.

  1. Set the global security parameter through the Sudo Setsebool -p httpd_unified 1. It will provide all types of processes as one.
  2. Creating global access rules APACHE virtual host files in CentOS 7

  3. Next it is recommended to check the current SELinux parameters that were provided automatically. To do this, write sudo ls -dz /var/www/example.com/log/.
  4. Start checking the current APACHE virtual host access status in CentOS 7

  5. As a result, you will see the contents of DRWXR-XR-X. root root unconfined_u: Object_r: httpd_sys_content_t: s0 /var/www/example.com/log/. It means that now Apache can only read those files that were created in the installed folder, respectively, will have to change the configuration.
  6. Study access to access to the APACHE virtual host in CentOS 7

  7. This task is performed via Sudo Semanage FContext -a -t httpd_log_t "/var/www/example.com/log(/*)?".
  8. Changing the contextual access rules to the APACHE virtual host in CentOS 7

  9. Save the changes and make it so that they are activated after rebooting the server by entering Sudo Restorecon -R -V /Var/www/example.com/log.
  10. Updating access to the APACHE virtual host settings in CentOS 7

  11. Now check the changes in Sudo LS -DZ /VAR/www/example.com/log/ again.
  12. Output information After updating Apache virtual host data in CentOS 7

  13. As you can see, as a result, the conclusion has the form DRWXR-XR-X. root root unconfined_u: object_r: httpd_log_t: s0 /var/www/example.com/log, therefore, everything is done correctly.
  14. View access to the virtual host after it update Apache in CentOS 7

  15. It remains only to test all the changes. To do this, enter the Sudo SystemCTL Restart HTTPD and click on ENTER.
  16. Restarting Apache Services in CentOS 7 after making all changes

  17. Confirm the action by specifying the superuser password.
  18. Action confirmation password to restart Apache Services in CentOS 7

  19. Create a request for the directory by entering LS -LZ /VAR/www/example.com/log. If the content that has appeared has -RW-R - R--. 1 root root error.log -rw-r - R--. 1 root root 0 requests.log, it means that all previous settings have been completed correctly.
  20. Checking the status of Apache access levels in CentOS 7 after rebooting services

You have been familiar with the installation procedure and the overall configuration of the Apache web server in CentOS 7. As you can see, the installation itself will not take much time, and all the difficulties are connected only with the configuration. If the presented manual for changing parameters and the APACHE management, you turned out to be not enough, we advise you to explore the official documentation by using reference below.

Go to the official website of the Apache documentation

Read more