Skip to content

Instantly share code, notes, and snippets.

@Jakiboy
Created April 4, 2023 20:46
Show Gist options
  • Save Jakiboy/ec15652abefd7dfa85b102bd59b5fc6d to your computer and use it in GitHub Desktop.
Save Jakiboy/ec15652abefd7dfa85b102bd59b5fc6d to your computer and use it in GitHub Desktop.
PHP (Optimisation)

PHP (Optimisation)

⚡ Configuration

@ /etc/php/7.4/apache2/php.ini
@ /etc/php/7.4/fpm/php.ini

Global

memory_limit = 256M
max_input_vars = 5000
max_execution_time = 300
max_input_time = 120
upload_max_filesize = 32M
post_max_size = 32M
display_errors = Off
xdebug.mode = off

Opcache

opcache.enable = 1
opcache.enable_cli = 1
opcache.memory_consumption = 128
opcache.file_cache = /bin/php/cache
opcache.jit_buffer_size = 256M (PHP8)
opcache.jit = tracing (PHP8)

⚡ PHP-FPM

Installation:

apt-get install php7.4-fpm

Configuration:

@ /etc/php/7.4/fpm/pool.d/www.conf

Setup

a2enmod proxy_fcgi setenvif
a2enconf php7.4-fpm
php-fpm7.4 -t
service php7.4-fpm restart
service apache2 restart

Vhost (Apache)

<VirtualHost *:80>
  ServerAdmin webmaster@{domain}
  ServerName {domain}
  ServerAlias www.{domain}
  DocumentRoot "/var/www/html/{domain}"
  DirectoryIndex index.php
  <Directory  "/var/www/html/{domain}/">
    Options +Indexes +Includes +FollowSymLinks +MultiViews
    AllowOverride All
    Require all granted
  </Directory>
  <FilesMatch ".php$">
    SetHandler "proxy:unix:/var/run/php/php7.4-fpm.sock|fcgi://localhost/"
  </FilesMatch>
  ErrorLog ${APACHE_LOG_DIR}/error.log
  CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Vhost (Nginx)

server {
         listen       80;
         server_name  {domain};
         root         /var/www/html/{domain};

         access_log /var/log/nginx/{domain}-access.log;
         error_log  /var/log/nginx/{domain}-error.log error;
         index index.html index.php;

         location / {
                      try_files $uri $uri/ /index.php$is_args$args;
         }

         location ~ \.php$ {
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass unix:/var/run/php7.4-fpm.sock;
            fastcgi_index index.php;
            include fastcgi.conf;
    }
}

Authors:

  • Jihad Sinnaour - Jakiboy (Initial work)

⭐ Support:

Please give it a Star if you like the project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment