Lesson 2 of 3
Installing a web stack
1 min
A typical PHP site needs a web server, PHP and a database. Here's a clean setup with Nginx, PHP-FPM and MariaDB.
Install the packages
sudo apt install nginx php-fpm php-mysql mariadb-server
sudo mysql_secure_installationCreate the database
sudo mysql
CREATE DATABASE shop;
CREATE USER 'shop'@'localhost' IDENTIFIED BY 'a-long-random-password';
GRANT ALL ON shop.* TO 'shop'@'localhost';Give each site its own database user; never connect the application as root.
Configure Nginx
Create /etc/nginx/sites-available/shop:
server {
server_name shop.yourcompany.com;
root /var/www/shop;
index index.php;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php-fpm.sock;
}
}Enable it, then test and reload:
sudo ln -s /etc/nginx/sites-available/shop /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginxAdd HTTPS
sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d shop.yourcompany.comAlways run nginx -t before reloading. A syntax error in one site's config can take every site on the server offline.