Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

Beide Seiten der vorigen Revision Vorhergehende Überarbeitung
Nächste Überarbeitung
Vorhergehende Überarbeitung
Nächste ÜberarbeitungBeide Seiten der Revision
content:apache_phpfpm [2020/04/05 19:32] – [Howto setup a LAMP-Server in 2018] Danielcontent:apache_phpfpm [2021/07/19 10:58] – Überschrift Daniel
Zeile 1: Zeile 1:
-====== Howto setup a LAMP-Server in 2018-2020 ======+====== Apache PHP- FPM- Serverguide ====== 
 + 
 +===== Howto setup a LAMP-Server in 2018-2020 =====
  
 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. 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.
  
 +To get the Differences, this is how my Distro (OpenSuSE) delivers the Packages by default and which disadvanteages it has:
 +
 +  * Apache-Prefork. That way, Apache is one Application with many threads - which is slower, consumes more memory and doesn't scale good
 +  * PHP-Module integrated in the Apche- Server which is not released as stable and may crash the whole Apache- Server on Errors
 +      * Using Network Connection to connect to
 +  * MariaDB
 +
 +And here is what this guide will set up:
 +
 +  * Apache- Event. That way, Apache is one small Apache- Manager- Application which will spawn as many Apache- Servers as needed to handle the incoming connections dynamically. This is stable, as one Error may only crash the one Instance, which will be respawned by the Apache- Manager dynamically
 +      * Connection to php is done by Proxy- Handling in Apache
 +  * PHP-FPM will also Spawn PHP-Instances dynamically for each script beeing run
 +      * Using Socket Connections to connect to
 +  * MariaDB
  
-===== Choosing Installation-Media & Install Basic System =====+==== Choosing Installation-Media & Install Basic System ====
  
-First, starting from Windows, you should make shure to have enough harddisk- space free. Then get installation-medium of the Linux your choice. I will stick to OpenSuSE as to get from [[https://software.opensuse.org/distributions|OpenSuSE]] (use Leap 15.currently as stable Distro. Tumbleweed may be instable). Follow the instructions to+First, starting from Windows, you should make sure to have enough harddisk- space free (i recommend at least 60 GB). Then get the installation-medium of the Linux your choice. I will stick to OpenSuSE as to get from [[https://software.opensuse.org/distributions|OpenSuSE]] (use Leap 15.currently as stable Distro. Tumbleweed may be instable). Follow the instructions to
  
-  - Download the DVD-Image+  - Download the DVD-Image from the Webpage as described there
   - Make the Installation- Media   - Make the Installation- Media
   - Install the System with standard Desktop- Packages (KDE)   - Install the System with standard Desktop- Packages (KDE)
   - Boot into new Linux and Set Up Desktop as you like   - Boot into new Linux and Set Up Desktop as you like
  
-===== Basic System- Scaling thoughts =====+==== Basic System- Scaling thoughts ====
  
 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 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)
Zeile 39: Zeile 55:
 Use "systemctl vm.swappiness = 0" and set it in /etc/sysctl.conf by adding line "vm.swappiness=0". Use "systemctl vm.swappiness = 0" and set it in /etc/sysctl.conf by adding line "vm.swappiness=0".
  
-===== Install MySql =====+==== Install MAriaDB (MySql====
  
 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: 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:
Zeile 54: Zeile 70:
  
 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. 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.
 +
 +For a local setup, you should use Sockets and disable networking. To do this, set
 +<code>
 +
 +socket = /run/mysql/mysql.sock
 +
 +</code>
 +
 +You should than deactivate TCP/IP with "skip-networking" and comment out the bind-address.
  
 Start Mysql with "rcmysqld start" at the command line as root, it should work now. Start Mysql with "rcmysqld start" at the command line as root, it should work now.
  
-===== Install Apache =====+After that had worked you should secure your Database by giving a password as it was explained by the step above when starting it. If not shure just run " <font inherit/monospace;;inherit;;#000000background-color:#ffffff;>/usr/bin/mysql_secure_installation</font> ". 
 + 
 +==== 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 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.
Zeile 70: Zeile 97:
   * Commit the Changes   * 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:   * 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:
-<code> 
  
 +<code>
 #This Config is for event or worker MPMs. #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 is the maximum number of apache-servers running beside the one controlling server. So 31 will make max. 32 Processes in total.
Zeile 96: Zeile 123:
 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. 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 =====+==== Install PhP-FPM ====
  
 If installed, remove mod_php (see beneath)! 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. [[https://en.opensuse.org/SDB:Apache_FastCGI_and_PHP-FPM_configuration|Here]] you can find a good Documentation for changing to php-fpm, but we will extend them a bit. If installed, remove mod_php (see beneath)! 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. [[https://en.opensuse.org/SDB:Apache_FastCGI_and_PHP-FPM_configuration|Here]] you can find a good Documentation for changing to php-fpm, but we will extend them a bit.
Zeile 125: Zeile 152:
  
 </code> </code>
 +
   * Than go to /etc/php7/fpm and briefly check if php-fpm.conf is ok for you   * Than go to /etc/php7/fpm and briefly check if php-fpm.conf is ok for you
   * Explanation: In php-fpm.d directory you need to set up at least one pool. This is one Instance for Apache to speak to.   * Explanation: In php-fpm.d directory you need to set up at least one pool. This is one Instance for Apache to speak to.
Zeile 143: Zeile 171:
  
 <code> <code>
-listen = /var/run/php-fpm.sock+listen = /run/php-fpm/php-fpm.sock
 listen.owner = wwwrun listen.owner = wwwrun
 listen.group = www listen.group = www
Zeile 156: Zeile 184:
  
 </code> </code>
- 
  
 ==== PHP Configuration ==== ==== PHP Configuration ====
Zeile 172: Zeile 199:
 and check, if the socket-file has been created. and check, if the socket-file has been created.
  
-=== About PHP- Modules ===+==== About PHP- Modules ====
  
-many modules for PHP are offered in the Distrubution. I **would not recommend using those** - as all php-modules need to be compiled against your php. If you update PHP and your modules are the same, they may brake your PHP!+many modules for PHP are offered in the Distrubution. I **would not recommend using those**  - as all php-modules need to be compiled against your php. If you update PHP and your modules are the same, they may brake your PHP!
  
 Better use pearl / pecl and install modules with it! Here, i have found no other way, than to search for php-pear and php-pecl in the distribution and use them. Better use pearl / pecl and install modules with it! Here, i have found no other way, than to search for php-pear and php-pecl in the distribution and use them.
Zeile 182: Zeile 209:
 Which can be found in the Repo: [[https://build.opensuse.org/project/show/devel:languages:php|https://build.opensuse.org/project/show/devel:languages:php]] Which can be found in the Repo: [[https://build.opensuse.org/project/show/devel:languages:php|https://build.opensuse.org/project/show/devel:languages:php]]
  
-After that, modules can be installed by e.g. "pecl install imagick". They also need to be loaded in php.conf. I would make an new config named /etc/php7/conf.d/pear_pecl.conf and include they modules there. E.g. "extension=imagick.so"+After that, modules can be installed by e.g. "pecl install imagick". They also need to be loaded in php.conf. I would make an new config named /etc/php7/conf.d/pear_pecl.ini and include they modules there. E.g. "extension=imagick.so"
  
 Restart php-fpm for the changes and check the log of php-fpm (usually in /var/log/php-fpm.log) for errors when loading modules. Restart php-fpm for the changes and check the log of php-fpm (usually in /var/log/php-fpm.log) for errors when loading modules.
  
- +==== Tell Apache to use php-fpm ====
-===== Tell Apache to use php-fpm =====+
  
 For making Apache use php-fpm as php-server, you use the module "proxy_fcgi", which should be included in the apache MPM- Package. For making Apache use php-fpm as php-server, you use the module "proxy_fcgi", which should be included in the apache MPM- Package.
Zeile 194: Zeile 220:
  
   * To enable this and all its dependencies, use   * To enable this and all its dependencies, use
 +<code>
  
-<code> 
 sudo a2enmod setenvif rewrite proxy proxy_fcgi sudo a2enmod setenvif rewrite proxy proxy_fcgi
  
Zeile 227: Zeile 253:
  
 </code> </code>
-===== Start and check Apache ===== 
  
-Now you can start and enable apache2+==== Start and check Apache ====
  
 +Now you can start and enable apache2
 <code> <code>
 +
 sudo systemctl start apache2 sudo systemctl start apache2
-sudo systemctl enable php-fpm+sudo systemctl enable apache2
  
 </code> </code>
Zeile 239: Zeile 266:
 check if the modules have beend loaded: check if the modules have beend loaded:
  
 +<code>
 apache2ctl -M apache2ctl -M
 +
 +</code>
  
 This should include proxy_fcgi_module now. This should include proxy_fcgi_module now.
Zeile 261: Zeile 291:
 This should give you the complete Info of your php-configuration. If something fails, check if the above services are started an/or the logfiles. This should give you the complete Info of your php-configuration. If something fails, check if the above services are started an/or the logfiles.
  
-You are done. Now its up to you to fill Apache with content. Have fun!+In Production, you should not run a plain http-server, but switch to SSL. Therefore, you can get ssl-certificates from let's encrypt and follow the instructions there to switch to ssl. You need some internet Name like [[http://www.myname.com|www.myname.com]] registered for your server to get this (e.g. via Dyndns). The process to make your server visible is something to be explained a bit more, but thats basically what you need to do (official internet-name/DNS- entry and ssl-encryption). as long as you don't want to make the server world-reachable and use it nly fr testing, your are also fine without DNS and SSL, but you should make sure, that your firewall blocks http(80) and https(443)-ports. 
 + 
 +Well: You are done. Now its up to you to fill Apache with content. Have fun! 
 + 
 +==== Manage Database with phpMyAdmin ==== 
 + 
 +To manage your local Database, it would be nice to have phpMyAdmin installed first (via Package-manager). After that, copy the config.sample.inc.php to config.inc.php under /srv/www/htdocs/phpMyAdmin to use the socket <font inherit/monospace;;inherit;;#000000background-color:#ffffff;>/run/mysql/mysql.sock</font>  you specified before for mysql. 
 + 
 +You can finish the setup of your phpMyAdmin by visiting [[http://localhost/phpMyAdmin/index.php|http://localhost/phpMyAdmin/index.php]] 
 + 
 +===== Installing Eclipse ===== 
 + 
 +Get Eclipse with PDT here: [[https://www.eclipse.org/pdt/|https://www.eclipse.org/pdt/]] 
 + 
 +You may download the file, extract the contents (e.g. to ~/eclipse) and run the installer there in userspace (no superuser is required). 
 + 
 +===== Filling Content to your Server ===== 
 + 
 +This is a demo to install some small Software to your Server. I will use the github- Project [[https://github.com/obel1x/ep3-bs.git|EP3-BS]] for testing. 
 + 
 +==== Install git-web ==== 
 + 
 +This is a nice tool, to view your git-repositorys. Install it, and create a directory named /srv/git and make it writeable to users. Restart your webserver. 
 + 
 +You should already be able to go to [[http://localhost/git/|http://localhost/git/]] and see an empty project- Directory. 
 + 
 +==== Download some Project ==== 
 + 
 +To get the git-project, open a terminal, change to /srv/git and execute "git clone [[https://github.com/obel1x/ep3-bs.git|https://github.com/obel1x/ep3-bs.git"]]. 
 + 
 +You should already be set to open the project in eclipse. If you rightclick on the Project, you can add Composer-support to automate the installation of composer-modules while setup of ep3. 
 + 
 +Than create the Apache configuration to point to that directory: 
 +<code> 
 + 
 +Alias /ep3 "/srv/git/ep3-bs/public/" 
 +<Directory "/srv/git/ep3-bs/"> 
 +require local 
 +Options FollowSymLinks 
 +AllowOverride All 
 +DirectoryIndex index.php 
 +</Directory> 
 + 
 +</code> 
 + 
 +After that, follow the instructions in [[https://github.com/tkrebs/ep3-bs/blob/master/data/docs/install.txt|https://github.com/tkrebs/ep3-bs/blob/master/data/docs/install.txt]]. Remember to use eclipse for installing composer-modules as written above! 
 + 
 +As Database you can create a new user (e.g. named ep3) with corresponid database and fill the configuration to fit. 
 + 
 +After that, your testinstallation should work already.
  
  
  • content/apache_phpfpm.txt
  • Zuletzt geändert: 2023/10/01 10:24
  • von Daniel