PHP Configuration on Ubuntu
Table of contents
PHP7.4
sudo apt install php7.4 php7.4-fpm php7.4-mysql php-common php7.4-cli php7.4-common php7.4-json php7.4-opcache php7.4-readline php7.4-mbstring php7.4-xml php7.4-gd php7.4-curl
sudo systemctl start php7.4-fpm
sudo systemctl enable php7.4-fpm
systemctl status php7.4-fpm
PHP without version
sudo apt update
sudo apt install php-fpm php-mysql
sudo apt install php-curl php-gd php-intl php-mbstring php-soap php-xml php-xmlrpc php-zip
sudo systemctl restart php7.2-fpm
Configure Nginx with php7.2
Common 502 Bad Gateway
error
- Misconfiguration on
fastcgi_pass
with incorrectphp version
can trigger 502 bad gateway error.
server {
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
server_name [example.com];
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
Add info.php
-
A couple of PHP samples
<?php phpinfo(); ?>
<?php echo "Page requested on: " . date("Y-m-d H:i:sa");?>
Test PHP
<?php sleep(1); ?>
<h1>Date: <?php echo date("l jS F"); ?></h1>
Increase upload size with php.ini
and wp-config.php
- Point 1 or Point 2 are dependent configurations
-
Run
vim /etc/php/7.4/fpm/php.ini
upload_max_filesize = 100M post_max_size = 100M
-
Add below to
wp-config.php
@ini_set( 'upload_max_filesize' , '128M' ); @ini_set( 'post_max_size', '128M'); @ini_set( 'memory_limit', '256M' ); @ini_set( 'max_execution_time', '300' ); @ini_set( 'max_input_time', '300' );
-
Reload
systemctl reload php7.4-fpm