ubuntu php-fpm nginx code example
Example 1: ubuntu lemp
// NGINX
sudo apt update
sudo apt install nginx
// MYSQL
sudo apt install mysql-server
sudo mysql
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
FLUSH PRIVILEGES;
exit;
sudo mysql -u root -p
// PHP
sudo apt install php-fpm php-mysql
// Website
sudo mkdir /var/www/your_domain
sudo chown -R $USER:$USER /var/www/your_domain
// Website Configuration
sudo nano /etc/nginx/sites-available/your_domain
server {
listen 80;
server_name your_domain www.your_domain;
root /var/www/your_domain;
index index.html index.htm index.php;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
sudo ln -s /etc/nginx/sites-available/your_domain /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
// Place your application in your folder
nano /var/www/your_domain/index.html
// Check PHP
nano /var/www/your_domain/info.php
<?php
phpinfo();
Example 2: install php linux nginx command line
sudo apt update && sudo apt install php-fpm
Example 3: nginx php-fpm
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_sc$
fastcgi_buffers 256 128k;
fastcgi_connect_timeout 300s;
fastcgi_send_timeout 300s;
fastcgi_read_timeout 300s;
include fastcgi_params;
fastcgi_param PHP_VALUE "upload_max_filesize = 256M \n post_max_size=256M \n max_input_vars=1000000";
}