Find us on social media
WordPressLEMPPHP10 min read
Install WordPress with Nginx + PHP + MySQL
Install WordPress on a LEMP stack (Linux, Nginx, MySQL, PHP) optimized for performance.
Install WordPress with LEMP
The LEMP stack (Linux, Nginx, MySQL, PHP) is the most efficient combination for WordPress in production.
Step 1 — Install Nginx
bash
sudo apt update
sudo apt install nginx -y
sudo systemctl enable nginxStep 2 — Install MySQL
bash
sudo apt install mysql-server -y
sudo mysql_secure_installationStep 3 — Create WordPress database
bash
sudo mysql -u root -psql
CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'SecurePassword123!';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;Step 4 — Install PHP-FPM
bash
sudo apt install php-fpm php-mysql php-curl php-gd php-intl php-mbstring php-soap php-xml php-zip -yStep 5 — Download WordPress
bash
cd /tmp
curl -LO https://wordpress.org/latest.tar.gz
tar xzf latest.tar.gz
sudo mv wordpress /var/www/mysite
sudo chown -R www-data:www-data /var/www/mysite
sudo chmod -R 755 /var/www/mysiteStep 6 — Configure Nginx
Create /etc/nginx/sites-available/mysite:
nginx
server {
listen 80;
server_name mysite.com www.mysite.com;
root /var/www/mysite;
index index.php index.html;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php-fpm.sock;
}
location ~ /\.ht {
deny all;
}
client_max_body_size 64M;
}Enable the site:
bash
sudo ln -s /etc/nginx/sites-available/mysite /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginxStep 7 — Complete installation
Open http://YOUR_IP in a browser and follow the WordPress setup wizard with your database credentials.
Step 8 — Install SSL with Certbot
bash
sudo apt install certbot python3-certbot-nginx -y
sudo certbot --nginx -d mysite.com -d www.mysite.comYour WordPress is now running optimized on your Baires Host VPS with Nginx.
Was this guide helpful?