Diese Version wurde durch eine neuere bestätigte Version ersetzt.DiffDiese Version (2020/04/03 14:41) ist ein Entwurf.
Überprüfungen: 0/1

Dies ist eine alte Version des Dokuments!


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, which is not the way it could be done today, leading to instability and complex configuration.

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 OpenSuSE (use Leap 15.0 currently as stable Distro. Tumbleweed may be instable). Follow the instructions to

  1. Download the DVD-Image
  2. Make the Installation- Media
  3. Install the System with standard Desktop- Packages (KDE)
  4. Boot into new Linux and Set Up Desktop as you like

The most important thing to consider when making performant LAMP is to not overextend memory-usage of your System. That means, that the amount of memory used by all Applications, should normally never exeed the system-memory space. If the settings are too high for your setup, the system will start to swap o lot of data, not working fast enough any more. As basic thumb-based Values, you need: 1 GByte Memory for Linux- Base- System 1 GByte Memory if you plan to have the graphical Desktop running (you can run that server in Textmode, which will not consume Memory) 1 GByte free (this will be used by System for filecache)

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't use more Memory as your system can deliver, or you will have no fun with it!

As the System is still usable also with a bad configuration, here is how to check if the Memory is set up right:

Open a terminal and type in „top“ as command. In the 4th line you should see „KiB Mem…“ . The important Values in that line are: XXX free ⇒ if this Value is to low (<90000 is very low), the System has no space left to start new Tasks. This Value should always be higher. 256000 or more is a good Value. XXX buff/cache ⇒ this is the value, that the system has allocated for filebuffering. A low value indicates that it may not performe well. The Value should be around 1024000 or more for best performance.

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 „systemctl vm.swappiness = 0“ and set it in /etc/sysctl.conf by adding line „vm.swappiness=0“.

In OpenSuSE MariaDB is available and working out of the Box (maybe change the Admin- Password at first Start). MySQL is tuneable in /etc/my.cnf:

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/innodb_buffer_pool_size should be equal 25%)
  • 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 „rcmysqld start“ at the command line as root, it should work now.

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, which is basically the same.

To switch to that MPM:

  • Open the Software Store
  • Install apache-event
  • Remove apache-prefork
  • Commit the Changes
  • in /etc/apache2/server-tuning.conf the module will be configured. Event and Worker is nearby the same. I use the following parameters for the event/worker module:
#This Config is for event or worker MPMs.
#ServerLimit is the maximum number of apache-servers running beside the one controlling server. So 31 will make max. 32 Processes in total.
ServerLimit 31
# http://httpd.apache.org/docs/2.4/mod/mpm_common.html#startservers
StartServers        2
#This should be set to threadsperchild * serverlimit
MaxRequestWorkers  496
# http://httpd.apache.org/docs/2.4/mod/mpm_common.html#minsparethreads
MinSpareThreads     32
MaxSpareThreads     64
# number of worker threads created by each child process
# http://httpd.apache.org/docs/2.4/mod/mpm_common.html#threadsperchild
ThreadsPerChild     16
# maximum number of requests a server process serves
# http://httpd.apache.org/docs/2.4/mod/mpm_common.html#maxrequestsperchild
MaxRequestsPerChild  5000
#unsued Parameters, while not needed or obsolete
#MaxClients         512
#ThreadLimit         16

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.

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 /etc/php7/fpm and briefly check if php-fpm.conf is ok for you
  • 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 „listen“ to socket-file and not to ip. eg: listen = /var/run/php-fpm.sock

The „pm“-setting controls how much memory will be used at the end. Start with:

  • pm = dynamic
  • pm.max_children = 120
  • pm.start_servers = 12
  • pm.min_spare_servers = 6
  • pm.max_spare_servers = 18

I do not recommend using php.ini in /etc/php7/fpm, but to put it in /etc/php7/conf.d With that Setup, the whole php-configuration will be the same for cli- and web(f)cgi- php execution. Check to move all php.ini files to conf.d. After that, go through the ini-files in conf.d an see if they fit your needs. Especially each Parameter should only be defined once.

After that, start php-fpm-server with „rcphp-fpm start“ at the command-line.

Todo: Apache/Mpm-Event, setup mod_proxy_fcgi to work with it

Diese Website verwendet Cookies. Durch die Nutzung der Website stimmen Sie dem Speichern von Cookies auf Ihrem Computer zu. Außerdem bestätigen Sie, dass Sie unsere Datenschutzbestimmungen gelesen und verstanden haben. Wenn Sie nicht einverstanden sind, verlassen Sie die Website.Weitere Information
  • content/apache_phpfpm.1585924867.txt.gz
  • Zuletzt geändert: 2020/04/03 14:41
  • von Daniel