redhat:web-server-redhat:php-redhat

PHP Installation auf CentOS 7

Für die Implementierung von php, werden wir hier vor allem nur anschauen, wie man php über die php-fpm (FastCGI) ermöglicht und dies im aktiven System umsetzt.

  • The mod_php approach is the slowest possible way to serve php content in Apache httpd; it also is the least efficient, using the most memory
  • mod_php is not thread-safe, preventing use of modern threaded MPMs like worker and event

  • All 4 collections (rh-php70, rh-php56, php55, & php54) include the separate php-fpm service which can serve PHP content back to Apache httpd
  • This option should be seriously considered as it provides a faster, more scalable setup that is thread-safe

Als Voraussetzung, muss hier wie im ersten Tutorial beschrieben der httpd24-httpd Webserver aus dem SCL Repository installiert werden! Anschliessend kann wie folgt mit der Installation begonnen werden:

  1. Installation des Webservers(falls nicht schon installiert) und php70
    # yum install httpd24-httpd rh-php70-php-fpm.x86_64 
  2. Umschreiben der Default Apache Konfiguration, für unser Umfeld:
    # echo "ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/var/www/html/\$1" >> /opt/rh/httpd24/root/etc/httpd/conf/httpd.conf
    
    # sed -e 's/index.html/index.php index.html/' -i /opt/rh/httpd24/root/etc/httpd/conf/httpd.conf
    # sed -e 's/\/opt\/rh\/httpd24\/root\/var\/www/\/var\/www/g' -i /opt/rh/httpd24/root/etc/httpd/conf/httpd.conf
  3. Erstellen und berechtigen der benötigten Ordner:
    # mkdir -p /var/www/html
    # mkdir /var/www/cgi-bin
    
    # chown -R apache:apache /var/www/
  4. Setzen der korrekten SELinux Rules:
    # semanage fcontext -a -t httpd_sys_content_t "/var/www(/.*)?"
    # semanage fcontext -a -t httpd_sys_script_exec_t "/var/www/cgi-bin(/.*)?"
    
    # restorecon -RvF /var/www
  5. Firewall Freischalten:
    # firewall-cmd --add-service=http --permanent
    # firewall-cmd --add-service=https --permanent
    
    # firewall-cmd --reload
  6. Deamons starten und enablen:
    # systemctl enable httpd24-httpd.service rh-php70-php-fpm.service
    
    # systemctl start rh-php70-php-fpm.service
    # systemctl start httpd24-httpd.service
  7. Erstellen und testen der phpInfo-Page:
    # vim /var/www/html/index.php

    <?php
    phpinfo();
    ?>
    

Nice to know:

  • SELinux RW Context erstellen:
    # semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/tmp(/.*)?"
  • php-fpm handler Konfigurationsfile:
    /etc/opt/rh/rh-php70/php-fpm.d/www.conf

# yum list rh-php70\*



# yum install ..
# vim /etc/opt/rh/rh-php70/php.ini

..
; line 878: uncomment and add your timezone
date.timezone = "Europe/Zurich"
..

ODER Automatisiert setzen:

# sed -e 's/;date.timezone =/date.timezone = "Europe\/Zurich"/' -i /etc/opt/rh/rh-php70/php.ini
# sed -e 's/max_execution_time = 30/max_execution_time = 7200/' -i /etc/opt/rh/rh-php56/php.ini
# sed -e 's/max_input_time = 60/max_input_time = 7200/' -i /etc/opt/rh/rh-php70/php.ini
# sed -e 's/memory_limit = 128M/memory_limit = 5000M/' -i /etc/opt/rh/rh-php70/php.ini
# sed -e 's/post_max_size = 8M/post_max_size = 5000M/' -i /etc/opt/rh/rh-php70/php.ini
# sed -e 's/upload_max_filesize = 2M/upload_max_filesize = 5000M/' -i /etc/opt/rh/rh-php70/php.ini

  • redhat/web-server-redhat/php-redhat.txt
  • Last modified: 2017/12/06 11:10
  • by michael