If you like DNray Forum, you can support it by - BTC: bc1qppjcl3c2cyjazy6lepmrv3fh6ke9mxs7zpfky0 , TRC20 and more...

 

Apache, NGINX, PHP-FPM — Choosing Right Architecture

Started by berto, Mar 08, 2023, 12:04 AM

Previous topic - Next topic

bertoTopic starter

Hello,

Please excuse my lack of experience, but I am overwhelmed with countless comparisons on what is better, and by better I mean faster!

The task at hand involves building a multilingual website on the Silex Framework, with cloud hosting on Amazon micro instance, ubuntu, php, and mysql. However, I am faced with a connectivity issue and need to determine the optimal solution in terms of speed and resources.

There are various options available including nginx-front and apache-back+mod_php, nginx + php-fpm, naked nginx, naked apache+mod_php, or other alternatives. It is evident that xcache, memcached, and other acceleration methods are necessary; however, my primary concern is identifying the most productive and least resource-dependent package.

If I select an architecture that is voracious for resources, I will have to upgrade to a paid Amazon instance faster, which I do not desire. Moreover, optimizing resource consumption could harm speed, which is also problematic.

Kindly share your personal experiences and recommendations, particularly with setup guide links for beginners.
  •  


AdahTrudy

We observed a significant boost in speed with nginx +php5-fpm compared to apache+mod_php after conducting tests. It's high time to embrace modern technological advancements as opposed to outdated installations of Apache. Here is our recommended strategy:

- Use nginx+php5-fpm
- Utilize apc for local cache and memcached for network operations
- Opt for database Percona XtraDB, or consider switching to MariaDB+XtraDB
- Choose ssd for the axis, deactivate logging, and activate trim
- Backup daily to hdd and weekly over the network.

Following these steps significantly enhanced productivity in our tests.
  •  

Yana

In principle, it's impossible to have an ideal solution.

Personally, I suggest utilizing what the administrator is familiar with managing. Even when situations become challenging and everything is going wrong, being familiar with the system can make a significant difference in outcome. This factor cannot be ignored.

While some engines necessitate the Apache rewrite, there may not always be options available. Nevertheless, given the ability to choose, I would still recommend choosing solutions that incorporate nginx.
  •  

pauldave

Mod_php is the most convenient option that I have come across. Apache+mod_php, to be specific, is very flexible.

However, I have not personally configured apache for five years and instead switched to nginx+php-fcgi because it provides enough speed for my projects and performs well in trivial tasks without slowing down. Additionally, it offers sufficient functionality and flexibility, although mod_php is more flexible.

From past experience hosting sites on this type of instance, I've found that the nginx+php-fpm bundle is superior in terms of memory and speed, rendering starting a project with apache pointless. The database becomes cramped in RAM and periodically encounters freezes when interacting with the disk.

In my experience with t2-micro, incorporating CloudFlare results in a significant decrease in server load due to static caching and thereby reducing the number of requests made to the webserver.
  •  

RanKumar

FPM refers to Server API. php, which has multiple APIs for various versions of its operation. These APIs include CLI SAPI for running console commands, apxs2 SAPI as a module to apache2, CGI SAPI that runs on every request. FPM SAPI is a Fast Process Manager originally developed for PHP by Badoo developers and now supported by the community.

Working with FPM differs from working with Apache primarily in that FPM is solely PHP and not a web server. It is the simplest, easiest, and fastest process manager for PHP that processes requests more quickly due to its lightness and simplicity.

Additionally, FPM is a smart process manager that controls the number of running PHP processes, frequency of restarts to combat memory leaks, and other simple things required for controlling the server. No matter what SAPI is used, whether it's an Apache module, CGI or PHP-FPM, it doesn't take away any PHP features.

Nginx, on the other hand, is an http proxy server developed by Igor Sysoev and is different from Apache due to its asynchronous event architecture. Nginx processes requests much faster than any other server and consumes fewer resources at the same time.

Due to the fact that each nginx workflow processes thousands of user requests, nginx can easily receive a user request, send it to the backend (e.g., php-fpm), and process the remaining user requests while the backend manages the processing.

Nginx works as a pipeline that quickly shifts requests and responses between backend and users, and the asynchronous processing of static files fits perfectly into this scheme. By dividing the work into two parts, giving statics from disk and processing dynamics in PHP-FPM, the workload is significantly reduced.

In comparison, Apache is limited to processing only 35 user requests at the same time, regardless of whether they are static or dynamic requests. Consequently, Apache will queue most of the requests, causing delays.
  •  

Asokanvon

I would recommend using nginx as the web server with php-fpm for processing PHP requests. This setup has proven to be efficient and resource-friendly. Nginx is known for its low memory usage and high concurrency, while php-fpm provides good performance and resource utilization.

For caching, using memcached or Redis would be a good choice. These in-memory key-value stores can significantly improve the speed of your website by caching database queries and reducing the load on your backend systems.

In terms of setup guides, there are many resources available online, but I would suggest starting with the official dоcumentation for each component. For example, you can find detailed installation and configuration guides for nginx, php-fpm, memcached, and Redis on their respective official websites.

It's important to carefully configure and optimize each component to achieve the best performance. Pay attention to tuning parameters such as worker processes, connections, and caching settings to make the most of your resources.

Finally, regarding the multilingual aspect of your website, consider using a content delivery network (CDN) for static assets and caching to further enhance the speed and user experience for visitors from different geographical locations.


Here are some more detailed recommendations based on the options you provided:

1. Web Server: Nginx is a great choice for its efficiency in handling concurrent connections. As for your specific use case, setting up Nginx as a reverse proxy in front of Apache could be an option if you have existing configurations or applications that rely on Apache-specific features. However, if you don't have such requirements, using Nginx with php-fpm directly would be a cleaner and lighter setup.

2. PHP Processing: PHP-FPM (FastCGI Process Manager) is a better choice than mod_php in terms of resource usage and stability. It allows for better control over PHP processes and is more suited for high-performance PHP applications.

3. Caching: Both xcache and memcached are viable options for accelerating your application. XCache is an opcode cacher for PHP, while memcached is a distributed memory caching system. If you have many repeated database queries or expensive computations, using a caching mechanism like memcached can significantly reduce the load on your backend systems.

4. Cloud Hosting: Since you mentioned using an Amazon micro instance, it's important to closely monitor your resources and consider the potential limitations of this type of instance. Upgrading to a higher-tier instance may become necessary if you experience performance issues, but optimizing your application's resource consumption through efficient architecture and caching can help delay the need for an upgrade.

For beginners, I would recommend looking into comprehensive tutorials and guides available on websites like DigitalOcean, Linode, or the official dоcumentation of the technologies you are using. These platforms often provide step-by-step tutorials and guides for setting up web servers, configuring caching, and optimizing performance.

In addition, community forums and Q&A sites like Stack Overflow and Server Fault are great resources for troubleshooting and learning from others' experiences.

Overall, taking a methodical approach to setting up and optimizing your infrastructure, combined with thorough testing and monitoring, will help you find the right balance between speed and resource utilization for your multilingual website.
  •  


If you like DNray forum, you can support it by - BTC: bc1qppjcl3c2cyjazy6lepmrv3fh6ke9mxs7zpfky0 , TRC20 and more...