no way to compare when less than two revisions
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Vorhergehende Überarbeitung Nächste Überarbeitung | |||
— | content:apache_phpfpm [2020/04/03 14:41] – Apache Install Daniel | ||
---|---|---|---|
Zeile 1: | Zeile 1: | ||
+ | ====== Howto setup a LAMP-Server in 2018 ====== | ||
+ | |||
+ | This documentation is about how to set up a LAMP- Server (Linux, Apache, MySql, PhP) in the current, most stable way. The Reason for me writing this is, that default Installations of common Distruibutions are often based on an old way in Server- Configuration, | ||
+ | |||
+ | ===== Choosing Installation-Media & Install Basic System ===== | ||
+ | |||
+ | First, starting from Windows, you should make shure to have enough harddisk- space free. Then get a installation-medium of the Linux your choice. I will stick to OpenSuSE as to get from [[https:// | ||
+ | |||
+ | - Download the DVD-Image | ||
+ | - Make the Installation- Media | ||
+ | - Install the System with standard Desktop- Packages (KDE) | ||
+ | - Boot into new Linux and Set Up Desktop as you like | ||
+ | |||
+ | ===== Basic System- Scaling thoughts ===== | ||
+ | |||
+ | The most important thing to consider when making performant LAMP is to **not overextend memory-usage** | ||
+ | |||
+ | The remaining Memory should be Split around this Values: | ||
+ | |||
+ | * 1/2 to Mysql | ||
+ | * 1/4 to PhP | ||
+ | * 1/4 to Apache | ||
+ | |||
+ | Those values are only for initial setup. After watching your System some time, you can adjust them to your needs. Mostly, when the system is growing, the Database will need even much more Memory than the Webserver, but that depens on your needs. | ||
+ | |||
+ | This is a very tight setup - having no more space for other Applications. So maybe if possible, spend some more GB and leave them free or dedicated to other things (e.g. In- Memory-DB like redis for special jobs). | ||
+ | |||
+ | Again in short: **Don' | ||
+ | |||
+ | ==== How to tell that your System is set up right ==== | ||
+ | |||
+ | As the System is still usable also with a bad configuration, | ||
+ | |||
+ | Open a terminal and type in " | ||
+ | |||
+ | If those values are both high, you can go and set swappiness to 0, which means that the system will tray to stay in memory as long as it will be possible. | ||
+ | |||
+ | Use " | ||
+ | |||
+ | ===== Install MySql ===== | ||
+ | |||
+ | In OpenSuSE MariaDB is available and working out of the Box (maybe change the Admin- Password at first Start). MySQL is tuneable in / | ||
+ | |||
+ | You should check the Parameters align with the memory of your machine (see above): Settings for 4 GB Memory (at all), are: | ||
+ | |||
+ | * innodb_buffer_pool_size = 768M | ||
+ | * innodb_log_file_size = 96M | ||
+ | * #Hint: innodb_log_file_size * 2/ | ||
+ | * max_connections = 24 | ||
+ | * join_buffer_size = 12M | ||
+ | * sort_buffer_size = 1M | ||
+ | * readn_rnd_buffer_size = 1M | ||
+ | |||
+ | Memory-Usage will be: innodb_buffer_pool_size + ( join_buffer_size + sort_buffer_size + readn_rnd_buffer_size ) * max_connections. If your System has more memory, use some tuning script (like MySQLTuner-perl) to see what makes most sense to put the memory to. | ||
+ | |||
+ | Start Mysql with " | ||
+ | |||
+ | ===== Install Apache ===== | ||
+ | |||
+ | In SuSE 15.X the apache-prefork is installed by default as MPM, which means having one single Apache- Programm in memory. This is not very well scaleable (not multithreaded) and not very stable, as one hangig Request can stop the Server. | ||
+ | |||
+ | In modern setups, apache-event (which is the successor of the apache-worker MPM) is used. This is the most stable and best multithreaded webserver commonly used. If you experience problems with it, you can switch back to apache-worker, | ||
+ | |||
+ | To switch to that MPM: | ||
+ | |||
+ | * Open the Software Store | ||
+ | * Install apache-event | ||
+ | * Remove apache-prefork | ||
+ | * Commit the Changes | ||
+ | * in / | ||
+ | < | ||
+ | |||
+ | #This Config is for event or worker MPMs. | ||
+ | # | ||
+ | ServerLimit 31 | ||
+ | # http:// | ||
+ | StartServers | ||
+ | #This should be set to threadsperchild * serverlimit | ||
+ | MaxRequestWorkers | ||
+ | # http:// | ||
+ | MinSpareThreads | ||
+ | MaxSpareThreads | ||
+ | # number of worker threads created by each child process | ||
+ | # http:// | ||
+ | ThreadsPerChild | ||
+ | # maximum number of requests a server process serves | ||
+ | # http:// | ||
+ | MaxRequestsPerChild | ||
+ | #unsued Parameters, while not needed or obsolete | ||
+ | # | ||
+ | # | ||
+ | |||
+ | </ | ||
+ | |||
+ | I would suggest to remove any mpm-specific configurations and use only those settings. You can leave the other settings as defined by initial setup. | ||
+ | |||
+ | ===== Install PhP-FPM ===== | ||
+ | |||
+ | If installed, remove mod_php! The Module for apache is known to make it slow and instable - here we will set up PhP-Fpm, which is much more stable and much faster. | ||
+ | |||
+ | PhP-FPM is a Server for running the PhP-Instances in a controlled way. It will manage the maximum amount of running instances and take care of errors like hanging scripts. | ||
+ | |||
+ | * First, install php-fpm and all dependent packages. | ||
+ | * Than go to / | ||
+ | * in php-fpm.d directory you need to set up at least one pool: This is one Instance for Apache to speak to | ||
+ | * i do recommend setting " | ||
+ | |||
+ | The " | ||
+ | |||
+ | * pm = dynamic | ||
+ | * pm.max_children = 120 | ||
+ | * pm.start_servers = 12 | ||
+ | * pm.min_spare_servers = 6 | ||
+ | * pm.max_spare_servers = 18 | ||
+ | |||
+ | ==== PHP Configuration ==== | ||
+ | |||
+ | I do not recommend using php.ini in / | ||
+ | |||
+ | After that, start php-fpm-server with " | ||
+ | |||
+ | ===== Install Apache ===== | ||
+ | |||
+ | Todo: Apache/ | ||
+ | |||