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/03 16:07] – [PHP Configuration] Danielcontent:apache_phpfpm [2020/04/05 19:32] – [Howto setup a LAMP-Server in 2018] Daniel
Zeile 1: Zeile 1:
-====== Howto setup a LAMP-Server in 2018 ======+====== 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.
 +
  
 ===== Choosing Installation-Media & Install Basic System ===== ===== Choosing Installation-Media & Install Basic System =====
Zeile 108: Zeile 109:
  
 </code> </code>
 +
   * I would suggest using a newer Version of php-fpm than in the default Repositories. E.g. using the Version of Repository "Apache Modules". Check out other "Experimental Packages" in [[https://software.opensuse.org/package/php7-fpm?search_term=php+fpm|https://software.opensuse.org/package/php7-fpm?search_term=php+fpm]]   * I would suggest using a newer Version of php-fpm than in the default Repositories. E.g. using the Version of Repository "Apache Modules". Check out other "Experimental Packages" in [[https://software.opensuse.org/package/php7-fpm?search_term=php+fpm|https://software.opensuse.org/package/php7-fpm?search_term=php+fpm]]
   * Either install the new Version with 1-Click-Install there **or**  for the default Version, use   * Either install the new Version with 1-Click-Install there **or**  for the default Version, use
Zeile 115: Zeile 117:
  
 </code> </code>
-  * Than, install mod_fcgi - it is used to tunnel request to php-fpm: 
  
-<code> 
-sudo zypper install apache2-mod_fcgid 
-sudo a2enmod proxy proxy_fcgi setenvif 
- 
-</code> 
   * Copy the configuration-files for php-fpm:   * Copy the configuration-files for php-fpm:
  
Zeile 131: Zeile 127:
   * 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.
-  * This here is new for the setup: in "/etc/php7/fpm/php-fpm.d/www.conf" i do recommend setting "listen" to socket-file and not to ip. eg: listen = /var/run/php-fpm.sock - as long as your php and webserver resides on the same machine. Linux Sockets are much more faster. 
-  * If using sockets, make sure the path exists and is writeable by the apache- user (an that this mathces the user in www.conf for php-fpm) 
  
 The "pm"-setting in www.conf controls how much memory will be used at the end. Start with: The "pm"-setting in www.conf controls how much memory will be used at the end. Start with:
Zeile 141: Zeile 135:
   * pm.min_spare_servers = 6   * pm.min_spare_servers = 6
   * pm.max_spare_servers = 18   * pm.max_spare_servers = 18
 +
 +==== Using Sockets ====
 +
 +Whenever you can - you should use unix sockets instead of TCP/IP, because of less overhead. If you are on the same machine (apache and php-fpm), than you can.
 +
 +So this here is new for the setup: in "/etc/php7/fpm/php-fpm.d/www.conf" set
 +
 +<code>
 +listen = /var/run/php-fpm.sock
 +listen.owner = wwwrun
 +listen.group = www
 +listen.mode = 0660
 +
 +</code>
 +
 +You need to make the file be created by systemd, so create a file /usr/lib/tmpfiles.d/php-fpm.conf and paste this line there:
 +
 +<code>
 +d /run/php-fpm 0700 wwwrun root -
 +
 +</code>
 +
  
 ==== PHP Configuration ==== ==== PHP Configuration ====
Zeile 158: Zeile 174:
 === About PHP- Modules === === About PHP- Modules ===
  
-many modules for PHP are offered in the Distrubution. I **would not recommend using those** - as they 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!+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!
  
-And again don'use the packages of the distribution. Get pear itself - check [[https://pear.php.net/manual/en/installation.getting.php|https://pear.php.net/manual/en/installation.getting.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.
  
-and see [[https://www.php.net/manual/en/install.pecl.intro.php|https://www.php.net/manual/en/install.pecl.intro.php]]+For me, i needed: php-pear, php-pecl, php7-devel (for command phpize) 
 + 
 +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" 
 + 
 +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 =====
  
-After php-fpm works, you can tell mod_fcgi to use it:+For making Apache use php-fpm as php-server, you use the module "proxy_fcgi", which should be included in the apache MPM- Package. 
 + 
 +Caution: this has noting to do with "mod_fcgi"! You will not need mod_fcgi, as this would manage php itself in a new server, which we dont' want! "proxy_fcgi" offers the fcgi- interface and tunnels it to php-fpm. Thus, it will be a small wrapper, not having to manage something as big as php. 
 + 
 +  * To enable this and all its dependencies, use 
 + 
 +<code> 
 +sudo a2enmod setenvif rewrite proxy proxy_fcgi 
 + 
 +</code> 
 + 
 +Now, tell proxy_fcgi to use php:
  
-  * Edit /etc/apache2/conf.d/mod_proxy_fcgi.conf and add:+  * Create /etc/apache2/conf.d/mod_proxy_fcgi.conf and add:
  
 <code> <code>
Zeile 194: Zeile 227:
  
 </code> </code>
 +===== Start and check Apache =====
  
 Now you can start and enable apache2 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 php-fpm
  
 </code> </code>
 +
 +check if the modules have beend loaded:
 +
 +apache2ctl -M
 +
 +This should include proxy_fcgi_module now.
 +
 +==== Create a PHP- Test- File ====
 +
 +Create the File /srv/www/htdocs/phpinfo.php (with read-permissions for user wwwrun) and paste this into it:
 +
 +<code>
 +<?php
 +
 +// Show all information, defaults to INFO_ALL
 +phpinfo();
 +
 +?>
 +
 +</code>
 +
 +Now open your Web- Browser and go to: [[http://localhost/phpinfo.php|http://localhost/phpinfo.php]]
 +
 +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! You are done. Now its up to you to fill Apache with content. Have fun!
  
  
  • content/apache_phpfpm.txt
  • Zuletzt geändert: 2023/10/01 10:24
  • von Daniel