So sánh wordpress trên apache với nginx năm 2024
To run a WordPress website, you need to host it on a web server. This is what enables web browsers to request your site’s data. However, there are several web server options, which can make choosing one a daunting task. Show While there are many web servers to choose from, Apache and NGINX are the most popular options. But which of the two is the best web server? These two web servers handle over 50% of all web traffic. While they share many qualities, there are differences you need to know about that can help you choose the right one for your site. In this article, we’ll discuss the differences between NGINX and Apache. We’ll then look at how you can install WordPress on both types of servers. Let’s get started! Comparing Performance: NGINX vs ApacheAs we mentioned earlier, NGINX and Apache are the most prominent web server options. They can handle diverse workloads and work with other software to form LAMP and LEMU stacks. However, in order to accurately compare these web servers, you’ll need to understand how they differ. ApacheApache is the older of the two servers, and was first released and developed by the Apache Software Foundation in 1995 by Robert McCool. Since 1996 Apache has been the top web server, and it is used by approximately 38.7% of websites. Currently, the Apache Foundation continues to release versions for Apache. The Apache module provides a range of benefits, including:
The Apache server is a user-friendly web server with lots of customization features. The software is also compatible with Unix and Windows servers. NGINXNGINX was released in 2004 by Igor Sysoev, found of NGINX Inc., to solve the C10K problem. This is the challenge web servers face when handling 10,000 or more concurrent connection requests. To solve this, NGINX was developed as an asynchronous, non-blocking, and event-based architecture. This is one of the primary differences between NGINX and Apache. It is also one of the reasons why approximately 32.1% of websites use NGINX. There are many other benefits that NGINX provides, such as:
NGINX and NGINX Plus are often seen as better options for high-traffic websites because of its load balancing capabilities to handle heavier loads. It’s also ideal for maintaining top performance on sites with a lot of static web content. Differences Between Apache vs NGINXWhile NGINX and Apache HTTP Server are similar, there are many differences between the two. The biggest distinction is the way these web servers handle multiple client requests. Apache uses a forked solution, while NGINX uses a non-blocking event loop. Apache provides Multi-Processing Modules (MPMs) that dictate how request handling works. The forked approach makes swapping out connection handling architecture easier. The modules used in this approach are additions to the core functionality of Apache. Each Multi-Processing Module starts a different process for handling server requests. One example is mpm-worker – a module that creates processes handling multiple threads. Each thread is a single connection to the server. Adding this module allows scaling of the server and enables the management of large amounts of traffic. NGINX is different and spawns only worker processes for simultaneous request handling. These processes are non-blocking events that continuously check for and process multiple requests. This continuous checking creates a loop. All events in the loop are asynchronous and are removed from the loop when the connection closes. What’s the Best WordPress Web Server Software?Both Apache and NGINX work well with WordPress hosting. However, NGINX might be the better option if you want improved performance. Let’s take a look at how to install WordPress on both types of servers, so you’ll be ready to get started with either one. How to Install WordPress on ApacheTo install WordPress on Apache, you will need to set up a LAMP (Linux, Apache, MySQL, and PHP) stack. This is generally done on an Ubuntu server. Step 1: Create a Sudo User on Your ServerTo create a user, log into your server as the root user. Then use the add user command below to create a new account:
The server will prompt you to set and confirm a password. Next, fill in the details for the user. Then you can provide sudo access to that user. This access allows the user to execute commands that are normally completed by the root user. To add the user to a sudo group, enter the following command:
Then, you’ll want to log into the server as the sudo user for the rest of the installation process. Step 2: Install Apache Web ServerTo install Apache, you will need to use the Ubuntu package manager apt. This is the default on Ubuntu servers. Entering the following sudo command starts the installation after you enter your password:
You’ll then see the packages that will be installed, and how much disk space is required. Press Y and then Enter to start the installation. Step 3: Install MySQL Database ServerNext, you’ll need to install the database management system MySQL. The following command in the package manager will start the installation:
The packages and disk space required will be displayed again. To start the installation, press Y and set the root password. Step 4: Install PHPPHP is the part of your LAMP stack that processes code to dynamic content. To install it, you should enter the following command:
PHP should then install without any problems. You’ll need to restart the server to complete the stack installation. To do so, enter the following command:
Your LAMP stack is now installed and configured. Step 5: Set Up Virtual HostsVirtual hosts encapsulate configuration details, and are a recommended step. The encapsulation lets you host more than one website on a server. Apache servers default to /var/www/html directories that are unwieldy for multiple websites. To create a virtual host, you’ll need to set up a directory structure in /var/www for the new website’s domain. Use the following command to create this structure:
Change new_domain to the domain of your website. Then create an index.html file with sample content using the nano command:
To ensure that Apache serves your content, you’ll also need to create a host file. The following command creates the configuration file:
Then add the following configuration block:
The next command enables the file, while the second disables the default site on the server:
0 Your virtual host should now be configured and working. This newly-created directory should be used for installing WordPress. Step 6: Install WordPressAfter configuring your LAMP stack, you can install WordPress. Download the latest version of WordPress and install it with the :
1 Next, for WordPress and . Then use the WordPress web browser interface to complete the . This includes creating a site title and setting a password. How to Install WordPress on NGINXTo install WordPress on NGINX, you need a server running one of the distributions that NGINX Unit supports. If you are using Linux, you will be creating a LEMU (Linux, NGINX, MySQL, and NGINX Unit) stack. Step 1: Install MySQLBefore starting, create a server user with sudo access. Log into your server as the root user, and use the following command to create a new account:
You’ll need to enter and confirm a password before filling the details for the user. Then you can provide sudo access to that user. This access enables the user to execute commands that are normally completed by the root user. To add the user to a sudo group, enter the following command:
Log into the server as the sudo user, and use the to install MySQL:
4 Enter a new root password. The MySQL configuration tool can then run. This is a configuration wizard that walks you through the installation process. Step 2: Create a MySQL DatabaseOnce MySQL is ready, you can . You’ll also need to create a new user with management permission. To do this, log into the MySQL root account and enter the following commands:
5 The Flush Privileges command makes sure that MySQL recognizes the changes you have made. You should change the default username and password to match your preferences. Step 3: Install WordPressBefore installing WordPress, you should create a temporary file location using the following command:
6 This command also downloads and unpacks WordPress. Step 4: Configure WordPressNext, create a copy of the WordPress configuration file and rename it using the following commands:
7 You can update the SALT keys in the file to improve security. Using nano opens the wp-config.php file, and enables you to search for the SALT keys:
8 Replace the keys with newly-generated ones, and then save and exit the file. Step 5: Install PHPWhile you can use NGINX Unit, you should still install PHP. You can use the following command to do so:
9 This is necessary because WordPress relies on several extensions that are not included in NGINX Unit. Step 6: Install NGINX UnitFinally, you will need to install the precompiled NGINX Unit for your server’s operating system. Use the following command to install the module for PHP:
0 These commands also verify that NGINX Unit and PHP are working properly. Next, you need to install and configure NGINX Open Source. You can install a pre-built package from the mainline branch. These include the latest features and patches. After this configuration, WordPress will be ready to use. Keep Learning With WP EngineApache and NGINX are the most popular web server software options. But in the battle between NGINX vs Apache, which one comes out on top? While they are similar in many ways, the NGINX server does provide better performance for high-traffic websites. However, Apache has a larger community with more documentation. Of course, you’ll need several things to develop an outstanding website. These include the right tools, the best resources, and top-notch web hosting! For more SEO and web-related resources like WordPress optimization and understanding HTTP 400 Errors, check out our Resource Center to improve your site. |