Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
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] Daniel | content:apache_phpfpm [2021/06/24 11:35] – [Howto setup a LAMP-Server in 2018-2020] Daniel | ||
---|---|---|---|
Zeile 1: | Zeile 1: | ||
- | ====== Howto setup a LAMP-Server in 2018 ====== | + | ====== Small 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, | 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 ===== | + | To get the Differences, |
- | 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:// | + | * Apache-Prefork. That way, Apache is one Application with many threads - which is slower, consumes more memory and doesn' |
+ | * PHP-Module integrated in the Apche- Server which is not released | ||
+ | * Using Network Connection to connect | ||
+ | * 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 ==== | ||
+ | |||
+ | 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:// | ||
+ | |||
+ | | ||
- 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** | The most important thing to consider when making performant LAMP is to **not overextend memory-usage** | ||
Zeile 38: | Zeile 58: | ||
Use " | Use " | ||
- | ===== Install MySql ===== | + | ==== Install |
In OpenSuSE MariaDB is available and working out of the Box (maybe change the Admin- Password at first Start). MySQL is tuneable in / | In OpenSuSE MariaDB is available and working out of the Box (maybe change the Admin- Password at first Start). MySQL is tuneable in / | ||
Zeile 53: | Zeile 73: | ||
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 | ||
+ | |||
+ | < | ||
+ | socket = / | ||
+ | |||
+ | </ | ||
+ | |||
+ | You should than deactivate TCP/IP with " | ||
Start Mysql with " | Start Mysql with " | ||
- | ===== 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 "< |
+ | |||
+ | |||
+ | ==== 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 95: | Zeile 127: | ||
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:// | 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:// | ||
Zeile 108: | Zeile 140: | ||
</ | </ | ||
+ | |||
* I would suggest using a newer Version of php-fpm than in the default Repositories. E.g. using the Version of Repository " | * I would suggest using a newer Version of php-fpm than in the default Repositories. E.g. using the Version of Repository " | ||
* Either install the new Version with 1-Click-Install there **or** | * Either install the new Version with 1-Click-Install there **or** | ||
Zeile 115: | Zeile 148: | ||
</ | </ | ||
- | * Than, install mod_fcgi - it is used to tunnel request to php-fpm: | ||
- | < | ||
- | sudo zypper install apache2-mod_fcgid | ||
- | sudo a2enmod proxy proxy_fcgi setenvif | ||
- | |||
- | </ | ||
* Copy the configuration-files for php-fpm: | * Copy the configuration-files for php-fpm: | ||
Zeile 129: | Zeile 156: | ||
</ | </ | ||
+ | |||
* Than go to / | * Than go to / | ||
* Explanation: | * Explanation: | ||
- | * This here is new for the setup: in "/ | ||
- | * 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 " | The " | ||
Zeile 141: | Zeile 167: | ||
* 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 "/ | ||
+ | |||
+ | < | ||
+ | listen = / | ||
+ | listen.owner = wwwrun | ||
+ | listen.group = www | ||
+ | listen.mode = 0660 | ||
+ | |||
+ | </ | ||
+ | |||
+ | You need to make the file be created by systemd, so create a file / | ||
+ | |||
+ | < | ||
+ | d / | ||
+ | |||
+ | </ | ||
+ | |||
==== PHP Configuration ==== | ==== PHP Configuration ==== | ||
Zeile 156: | Zeile 204: | ||
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 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** |
- | And again don' | + | Better |
- | and see [[https://www.php.net/ | + | For me, i needed: php-pear, |
+ | Which can be found in the Repo: [[https:// | ||
- | ===== Tell Apache | + | After that, modules can be installed by e.g. "pecl install imagick" |
- | After php-fpm | + | Restart |
- | | + | ==== Tell Apache to use php-fpm ==== |
+ | |||
+ | For making Apache use php-fpm as php-server, you use the module " | ||
+ | |||
+ | Caution: this has noting to do with " | ||
+ | |||
+ | | ||
+ | < | ||
+ | |||
+ | sudo a2enmod setenvif rewrite proxy proxy_fcgi | ||
+ | |||
+ | </ | ||
+ | |||
+ | Now, tell proxy_fcgi to use php: | ||
+ | |||
+ | * Create | ||
< | < | ||
Zeile 194: | Zeile 258: | ||
</ | </ | ||
+ | |||
+ | ==== Start and check Apache ==== | ||
Now you can start and enable apache2 | Now you can start and enable apache2 | ||
Zeile 199: | Zeile 265: | ||
sudo systemctl start apache2 | sudo systemctl start apache2 | ||
- | sudo systemctl enable | + | sudo systemctl enable |
</ | </ | ||
- | You are done. Now its up to you to fill Apache with content. Have fun! | + | check if the modules have beend loaded: |
+ | |||
+ | < | ||
+ | apache2ctl -M | ||
+ | |||
+ | </ | ||
+ | |||
+ | This should include proxy_fcgi_module now. | ||
+ | |||
+ | ==== Create a PHP- Test- File ==== | ||
+ | |||
+ | Create the File / | ||
+ | |||
+ | < | ||
+ | <?php | ||
+ | |||
+ | // Show all information, | ||
+ | phpinfo(); | ||
+ | |||
+ | ?> | ||
+ | |||
+ | </ | ||
+ | |||
+ | Now open your Web- Browser and go to: [[http:// | ||
+ | |||
+ | 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. | ||
+ | |||
+ | In Production, you should not run a plain http-server, | ||
+ | |||
+ | 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 / | ||
+ | |||
+ | You can finish the setup of your phpMyAdmin by visiting [[http:// | ||
+ | |||
+ | |||
+ | ===== Installing Eclipse ===== | ||
+ | |||
+ | Get Eclipse with PDT here: [[https:// | ||
+ | |||
+ | 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:// | ||
+ | |||
+ | |||
+ | ==== 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:// | ||
+ | |||
+ | ==== Download some Project ==== | ||
+ | |||
+ | To get the git-project, | ||
+ | |||
+ | 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: | ||
+ | < | ||
+ | |||
+ | Alias /ep3 "/ | ||
+ | < | ||
+ | require local | ||
+ | Options FollowSymLinks | ||
+ | AllowOverride All | ||
+ | DirectoryIndex index.php | ||
+ | </ | ||
+ | |||
+ | </ | ||
+ | |||
+ | After that, follow the instructions in [[https:// | ||
+ | |||
+ | 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. | ||