Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Beide Seiten der vorigen Revision Vorhergehende Überarbeitung Nächste Überarbeitung | Vorhergehende Überarbeitung | ||
content:apache_phpfpm [2022/03/02 18:39] – [Tell Apache to use php-fpm] Daniel | content:apache_phpfpm [2025/02/19 14:30] (aktuell) – [LAMPf: Linux / Apache / MariaDB / PHP- FPM- Serverguide] Daniel | ||
---|---|---|---|
Zeile 1: | Zeile 1: | ||
- | ====== Apache PHP- FPM- Serverguide ====== | + | ====== |
- | ===== Howto setup a LAMP-Server in 2018-2020 ===== | + | Note: The here explained way of setting up a webserver is very performant plus very slim and basic and may be a very good way if your machine is old and/or your ressources are low and you want to deliver solid, fast and small services based on native distribution- liked builds. But it needs some manual maintanance and a well working, full featured Linux- Distribution, |
+ | |||
+ | For example: if you want to make those Services available on the internet, you should definitively want to make webservices SSL- secured. Getting automatic SSL- Certificates and renew them in a good way, will work if you know how to set it up, but the setup is just another thing to care about. | ||
+ | |||
+ | So nowadays there are solutions to make complexity for that more handy which would be e.g. using Docker or Podman - which would be another, very different approach for large system, delivering a full, extremly powerful service- infrastructure in a pre- build way (it also delivers apache with php-fpm and automatic ssl-acme-challanges out of the box in many packages!). | ||
+ | |||
+ | So if you plan to set up a new fully flagged Server which will have many needed services, don't use this setup. Just after installation go straight into installing and setting up e.g. Docker and go on and use it for all services you can find there. | ||
+ | |||
+ | You can find the new way how to setup a server here: [[.: | ||
+ | |||
+ | So this for me is deprecated as i bought a new server here. I won't spend any time here. If you wann know more about nowadays setups, feel free and write a mail to me, maybe i will deliver docs to this than. HF and GL obel1x | ||
+ | |||
+ | |||
+ | ===== Howto setup a LAMP-Server in 2018 - 2020+ ===== | ||
This documentation is about how to set up a LAMP- Server (Linux, Apache, MySql aka MariaDB, PhP) in the current, most stable way for home office usage. The reason for me writing this is, that default Installations of common Distruibutions are often based on an old styled configuration, | This documentation is about how to set up a LAMP- Server (Linux, Apache, MySql aka MariaDB, PhP) in the current, most stable way for home office usage. The reason for me writing this is, that default Installations of common Distruibutions are often based on an old styled configuration, | ||
Zeile 8: | Zeile 21: | ||
* Apache-Prefork. That way, Apache is one Application with many threads - which is slower, consumes more memory and doesn' | * Apache-Prefork. That way, Apache is one Application with many threads - which is slower, consumes more memory and doesn' | ||
- | * PHP-Module | + | * PHP-Module |
* PHP- Modules, which must be compiled againt the apache-mod_php- module. Updating mod_php means updating all modules. | * PHP- Modules, which must be compiled againt the apache-mod_php- module. Updating mod_php means updating all modules. | ||
* Using Network Connections with overhead to connect to | * Using Network Connections with overhead to connect to | ||
Zeile 20: | Zeile 33: | ||
* Using Socket Connections to connect to | * Using Socket Connections to connect to | ||
* MariaDB | * MariaDB | ||
- | |||
==== Choosing Installation-Media & Install Basic System ==== | ==== Choosing Installation-Media & Install Basic System ==== | ||
- | 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:// | + | 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:// |
- Download the DVD-Image from the Webpage as described there | - Download the DVD-Image from the Webpage as described there | ||
- | - Make the Installation- Media | + | - Create |
- 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 | ||
Zeile 33: | Zeile 45: | ||
==== Basic System- Scaling thoughts ==== | ==== Basic System- Scaling thoughts ==== | ||
- | The most important thing to consider when making performant LAMP is to **not overextend memory-usage** | + | 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: | The remaining Memory should be Split around this Values: | ||
Zeile 57: | Zeile 69: | ||
Use " | Use " | ||
- | ==== Install | + | ==== Install |
- | 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. Check with: |
+ | < | ||
+ | |||
+ | sudo zypper install mariadb | ||
+ | |||
+ | </code> | ||
- | You should check the Parameters align with the memory of your machine (see above): Settings for 4 GB Memory (at all), are: | + | MySQL is tuneable in / |
* innodb_buffer_pool_size = 768M | * innodb_buffer_pool_size = 768M | ||
Zeile 74: | Zeile 91: | ||
For a local setup, you should use Sockets and disable networking. To do this, set | For a local setup, you should use Sockets and disable networking. To do this, set | ||
- | < | ||
+ | < | ||
socket = / | socket = / | ||
Zeile 82: | Zeile 99: | ||
You should than deactivate TCP/IP with " | You should than deactivate TCP/IP with " | ||
- | Start Mysql with " | + | Start Mysql with |
+ | |||
+ | < | ||
+ | systemctl | ||
+ | |||
+ | </ | ||
+ | |||
+ | at the command line as root, it should work now. | ||
- | 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/ | + | To setup passwords, |
==== Install Apache ==== | ==== Install Apache ==== | ||
Zeile 95: | Zeile 119: | ||
* Open the Software Store | * Open the Software Store | ||
- | * Install | + | * Install |
- | * Remove | + | * Remove |
* Commit the Changes | * Commit the Changes | ||
* in / | * in / | ||
Zeile 124: | Zeile 148: | ||
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. | ||
+ | |||
+ | After that, open yast and go to sysconfig- editor. Search for APACHE_MPM and select event. | ||
+ | |||
+ | Test running apache with | ||
+ | |||
+ | < | ||
+ | systemctl start apache2.service | ||
+ | |||
+ | systemctl status apache2.service | ||
+ | ● apache2.service - The Apache Webserver | ||
+ | Loaded: loaded (/ | ||
+ | Active: active (running) since Tue 2022-11-22 19:43:17 CET; 1s ag | ||
+ | |||
+ | </ | ||
+ | |||
+ | If thats fine, please stop apache once again to configure php-fpm first. | ||
==== Install PhP-FPM ==== | ==== Install PhP-FPM ==== | ||
Zeile 134: | Zeile 174: | ||
< | < | ||
- | sudo zypper remove apache2-mod_php7 | + | sudo zypper remove apache2-mod_php8 |
- | sudo a2dismod | + | sudo a2dismod |
</ | </ | ||
Zeile 143: | Zeile 183: | ||
< | < | ||
- | sudo zypper install | + | sudo zypper install |
</ | </ | ||
Zeile 150: | Zeile 190: | ||
< | < | ||
- | sudo cp /etc/php7/ | + | sudo cp /etc/php8/ |
- | sudo cp /etc/php7/ | + | sudo cp /etc/php8/ |
</ | </ | ||
- | * Than go to /etc/php7/fpm and briefly check if php-fpm.conf is ok for you | + | * Than go to /etc/php8/fpm and briefly check if php-fpm.conf is ok for you |
* Explanation: | * Explanation: | ||
Zeile 170: | Zeile 210: | ||
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. | 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/ | + | So this here is new for the setup: in "/etc/php8/ |
< | < | ||
Zeile 189: | Zeile 229: | ||
==== PHP Configuration ==== | ==== PHP Configuration ==== | ||
- | 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. | + | I do not recommend using php.ini in /etc/php8/fpm, but to put it in /etc/php8/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: | After that, start php-fpm: | ||
Zeile 203: | Zeile 243: | ||
==== About PHP- Modules ==== | ==== About PHP- Modules ==== | ||
- | many modules for PHP are offered in the Distrubution. I **would not recommend using those** | + | many modules for PHP are offered in the Distrubution. I **would not recommend using those** |
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. | ||
- | For me, i needed: | + | For me, i needed: |
Which can be found in the Repo: [[https:// | Which can be found in the Repo: [[https:// | ||
- | After that, modules can be installed by e.g. "pecl install imagick" | + | After that, modules can be installed by e.g. "pecl install imagick" |
+ | |||
+ | To make pecl/paer alter the ini automagically, | ||
+ | < | ||
+ | |||
+ | pear config-set php_ini / | ||
+ | pecl config-set php_ini / | ||
+ | |||
+ | </ | ||
Restart php-fpm for the changes and check the log of php-fpm (usually in / | Restart php-fpm for the changes and check the log of php-fpm (usually in / | ||
Zeile 219: | Zeile 267: | ||
For making Apache use php-fpm as php-server, you use the module " | For making Apache use php-fpm as php-server, you use the module " | ||
- | Caution: this has noting to do with " | + | Caution: this has noting to do with " |
* To enable this and all its dependencies, | * To enable this and all its dependencies, | ||
Zeile 239: | Zeile 287: | ||
# This is to forward all PHP to php-fpm | # This is to forward all PHP to php-fpm | ||
< | < | ||
- | SetHandler " | + | SetHandler " |
</ | </ | ||
DirectoryIndex index.php | DirectoryIndex index.php | ||
Zeile 259: | Zeile 307: | ||
</ | </ | ||
- | |||
==== Start and check Apache ==== | ==== Start and check Apache ==== | ||
Zeile 297: | Zeile 344: | ||
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. | ||
+ | |||
+ | If you get Permission denied even if your file is world- readable and the user wwwrun can access the content, in Leap 15.4 there are strict permissions in AppArmor. So check Yast / AppArmor and Check the Protocols. You will most likely find entries that needs to be changed (affects also: executing programs with proc_open() in php). After that, Access should work. | ||
In Production, you should not run a plain http-server, | In Production, you should not run a plain http-server, | ||
Zeile 304: | Zeile 353: | ||
==== Manage Database with phpMyAdmin ==== | ==== 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 / | + | 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 / |
You can finish the setup of your phpMyAdmin by visiting [[http:// | You can finish the setup of your phpMyAdmin by visiting [[http:// | ||
+ | |||
+ | Hint: phpMyAdmin in Opensuse seems to be reduced in functionality. For example generating config.inc.php with [[http:// | ||
+ | |||
+ | ==== About security of your WEB- Page (Scripts) ==== | ||
+ | |||
+ | There are really a lot of important Documentations about security of your Webserver going in Details for each functionality. They are important - as functions should be set as tight as possible. | ||
+ | |||
+ | But there are more basic security settings that may prevent damage if the functional security is breached. So the basic security might be very important - and here especially the file permissions. One big security-hole that is very common misunderstand at permissions is this one: | ||
+ | |||
+ | **If you make a file ONLY readable for the user of the webserver (400) and make that user own that file, you may expect this user to not be able to write to that file. THIS IS WRONG !** | ||
+ | |||
+ | Instead, in Linux/Unix the user owning a file can ALWAYs change its permissions. So the user will be able to make it writeable again and write to that file. The ONLY way to prevent the webservers- user form writing to files is not to make this user own that file. So you should make your file owned by root and use groups for controlling the access. | ||
+ | |||
+ | If you need more detailled file permissions, | ||
===== Installing Eclipse ===== | ===== Installing Eclipse ===== | ||
Zeile 347: | Zeile 410: | ||
As Database you can create a new user (e.g. named ep3) with corresponid database and fill the configuration to fit. | 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 | + | ==== Using Eclipse to work on that Project ==== |
+ | |||
+ | In Eclipse now add a project and use GIT smart import from that directory location - it should configure git and eclipse + php the right way and you should be ready to go programming! | ||
+ | |||
+ | ==== Setup Debugging of PHP ==== | ||
+ | |||
+ | To setup Debugging of code, install xdebug for php via pecl: | ||
+ | < | ||
+ | |||
+ | pecl install xdebug | ||
+ | |||
+ | </ | ||
+ | |||
+ | Now, also add | ||
+ | |||
+ | < | ||
+ | xdebug.mode=debug | ||
+ | |||
+ | </ | ||
+ | |||
+ | Now restart php-fpm and check the php_info() if xdebug is enabled and if Step debugging is active. Otherwise check logs. | ||
+ | |||
+ | Adjusting timeouts in apache fcgi: Add Timeouts to / | ||
+ | |||
+ | < | ||
+ | ... | ||
+ | | ||
+ | | ||
+ | ... | ||
+ | |||
+ | </ | ||
+ | |||
+ | And of course restart apache2. | ||
+ | |||
+ | ==== Setup of Eclipse ==== | ||
+ | |||
+ | You need to add the PHP- Environement and the Debugger in Eclipse. | ||
+ | |||
+ | {{.: | ||
+ | |||
+ | and | ||
+ | |||
+ | {{.: | ||
+ | |||
+ | Mind to use the Port phpinfo tells you. Thats it start debugging with e.g. index.php of the project: | ||
+ | |||
+ | {{.: | ||
+ | |||
+ | That should | ||
+ | |||
+ | You can walk through the code with F5 (dive into), F6 (step over) or just let the work go on with F8. | ||
+ | |||
+ | You are done setting up webserver, php-fpm, mariadb and eclipse plus your new git- repository. hafe fun! | ||