Top Tags

Php-fpm 8.0 with Nginx, MySQL

Install PHP-FPM 8.0 with Nginx on Ubuntu 20.04 and MySQL

Install

bash
1sudo apt install nginx -y
2sudo apt install software-properties-common -y
3sudo add-apt-repository ppa:ondrej/php -y
4sudo apt update
5sudo apt install php8.0-fpm -y
6sudo apt install php8.0-mysql php8.0-curl php8.0-mbstring php8.0-xml php8.0-zip -y

Configure PHP-FPM

php
1cgi.fix_pathinfo=0
2memory_limit=256M
3upload_max_filesize=50M
4post_max_size=50M

sudo systemctl restart php8.0-fpm

Configure Nginx

bash
1/etc/nginx/sites-available/dev.local
bash
1server {
2 listen 80;
3 server_name dev.local www.dev.local;
4
5 root /var/www/dev.local;
6 index index.php index.html;
7
8 location / {
9 try_files $uri $uri/ /index.php?$query_string;
10 }
11
12 location ~ \.php$ {
13 include snippets/fastcgi-php.conf;
14 fastcgi_pass unix:/var/run/php/php8.0-fpm.sock;
15 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
16 include fastcgi_params;
17 }
18
19 location ~ /\.ht {
20 deny all;
21 }
22}

Enable the site:

bash
1sudo ln -s /etc/nginx/sites-available/dev.local /etc/nginx/sites-enabled/
2sudo nginx -t
3sudo systemctl reload nginx

Set Up the Web Directory

bash
1sudo mkdir -p /var/www/dev.local
2sudo chown -R www-data:www-data /var/www/dev.local
3sudo chmod -R 755 /var/www/dev.local

Verify

php
1<?php
2phpinfo();

Create MySQL user for db

sql
1CREATE USER 'admin'@'localhost' IDENTIFIED BY 'pass';
2GRANT ALL PRIVILEGES ON example_db.* TO 'admin'@'localhost';
3FLUSH PRIVILEGES;