Table of Contents
- Step 1: Update Package List
- Step 2: Install Nginx
- Step 3: Install MySQL Server
- Step 4: Install PHP and Required Extensions
- Step 5: Configure PHP-FPM
- Step 6: Configure Nginx for WordPress
- Step 7: Create MySQL Database and User for WordPress
- Step 8: Download and Configure WordPress
- Step 9: Complete WordPress Installation
To install WordPress with LEMP (Linux, Nginx, MySQL, PHP) on Ubuntu 20.04, follow these steps:
Step 1: Update Package List
sudo apt updateStep 2: Install Nginx
sudo apt install nginxStep 3: Install MySQL Server
sudo apt install mysql-serverDuring the installation, you’ll be prompted to set a password for the MySQL root user.
Step 4: Install PHP and Required Extensions
sudo apt install php-fpm php-mysqlStep 5: Configure PHP-FPM
Edit the PHP-FPM configuration file:
sudo nano /etc/php/7.4/fpm/php.iniFind the line ;cgi.fix_pathinfo=1 and change it to:
cgi.fix_pathinfo=0Save and close the file. Then, restart PHP-FPM:
sudo systemctl restart php7.4-fpmStep 6: Configure Nginx for WordPress
Create a new Nginx server block configuration for your WordPress site:
sudo nano /etc/nginx/sites-available/yourdomain.comReplace yourdomain.com with your actual domain name, and add the following configuration:
server {
listen 80;
server_name yourdomain.com www.yourdomain.com;
root /var/www/yourdomain.com;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
error_log /var/log/nginx/yourdomain.com_error.log;
access_log /var/log/nginx/yourdomain.com_access.log;
}Create a symbolic link to enable the site:
sudo ln -s /etc/nginx/sites-available/yourdomain.com /etc/nginx/sites-enabled/Test the Nginx configuration:
sudo nginx -tIf the test is successful, restart Nginx:
sudo systemctl restart nginxStep 7: Create MySQL Database and User for WordPress
Login to MySQL:
sudo mysqlCreate a new database:
CREATE DATABASE wordpressdb;Create a new user and grant privileges:
CREATE USER 'wordpressuser'@'localhost' IDENTIFIED BY 'your_password'; GRANT ALL PRIVILEGES ON wordpressdb.* TO 'wordpressuser'@'localhost'; FLUSH PRIVILEGES; EXIT;Replace 'your_password' with a strong password.
Step 8: Download and Configure WordPress
cd /tmp
wget https://wordpress.org/latest.tar.gz
tar -zxvf latest.tar.gz
sudo mv wordpress /var/www/yourdomain.comUpdate ownership and permissions:
sudo chown -R www-data:www-data /var/www/yourdomain.com
sudo chmod -R 755 /var/www/yourdomain.comCopy the default configuration file:
sudo cp /var/www/yourdomain.com/wp-config-sample.php /var/www/yourdomain.com/wp-config.phpEdit the WordPress configuration file:
sudo nano /var/www/yourdomain.com/wp-config.phpUpdate the database connection details:
define('DB_NAME', 'wordpressdb');
define('DB_USER', 'wordpressuser');
define('DB_PASSWORD', 'your_password');Replace 'your_password' with the password you set for the MySQL user.
Step 9: Complete WordPress Installation
Visit http://yourdomain.com in your web browser to complete the WordPress installation. Follow the on-screen instructions, and you’ll be prompted to provide the database information and set up the admin user.
Once the installation is complete, you can log in to the WordPress admin dashboard.
That’s it! You’ve successfully installed WordPress with LEMP on Ubuntu 20.04. Adjust the configurations based on your specific requirements.