What is LEMP?
LEMP is a combination of Linux, Nginx, MySQL/MariaDB and PHP 7.4 which is used to deploy WordPress.
This guide is only intend for single WordPress per server. Not multiple.
To Install WordPress, please follow step-by-step guide. In case of any doubt, feel free to ask below or Tweet me. I will reply instantly asap.
#1. Sign up Digital Ocean to grab $100 free credits (Valid for 60 days)
#2. Login to Digital Ocean and Choose Droplets from create menu
#3. Please choose Ubuntu 18.04 x64
#4. Choose Droplet Size
#5. Choose Datacenter region
#6. Enable IPV6, Name your Droplet and Create Droplet
#7. Droplet Creation is under process, you will soon receive login credential via e-mail
#8. Note down your IP Address
There are two kind of IP address: IPV4 and IPV6 that is suppose to be updated in A and AAAA DNS record respectively.
#9. Update your DNS records
In case you don’t know who is your DNS manager, you can spy with DNS checker tool.
Since, I am a Cloudflare user by using its nameserver therfore it is my DNS manager.
- For root domain or any subdomain, put IPV4 address in A record and IPV6 address in AAAA record
- For www, use CNAME record pointing to root domain itself. Ref: screenshot
# 10. Check your Digital Ocean account’s E-mail Inbox for getting Server Login credential
# 11. Login Server using SSH application Putty. Don’t have? Download and Install it.
Putty is a free open source terminal emulator which we will use for login to our Digital Ocean server. You can download Putty application here. Make sure to install it.
#12. Search Putty on your Windows
This is a SSH application, we will use to login to our Server.
#13. Login to your Server using SSH Application – Putty
Step 1. Open putty, Enter root@your-server-ip-address in the hostname field and click open.
Step 2. Copy password from e-mail and do right click in SSH to paste. Please don’t try CTRL + V shortcut, sorry it will not work. Password will be invisible, don’t be panic. Press enter to login.
Step 3. If security dialogue prompt, select yes. (Only for first time)
#14. Now you are logged in. Set a new password.
Digital Ocean server will force you to update password.
Step 1. (current) UNIX password: Do Right click to paste and Press enter.
Step 2. Enter new UNIX password: Copy a strong password using Dashlane password Generator. Keep new password safe in Notepad.
Step 3. Retype new UNIX password: do right click to paste new password and Press enter again. Now you should be logged in.
#15. Update repositories
Type below command and press enter key
sudo apt update
#16. Upgrade & dist-upgrade
sudo apt upgrade -y
Press Enter key when below screen prompt and ask Keep the local version currently installed …
Then, run below command
sudo apt dist-upgrade
#17. Run autoclean & autoremove to do the housekeeping.
sudo apt autoclean
sudo apt autoremove
#18. After that, reboot the server
#19. Please Login to Putty again after 30 seconds
Copy password, do right click to paste into SSH and press enter key.
#20. Install MariaDB
sudo apt install mariadb-server -y
#21. Secure MySQL Installation
Answer below questions
- Enter current password for root (enter for none): Press Enter key
- Set root password? [Y/n]: Press Enter key.
- New password: Type your password, you can use Dashlane to generate. Right to click paste.
- Re-enter new password: Re-type your password.
After successful password set, you will see
Password updated successfully! Reloading privilege tables.. ... Success!
Also, you need answer following questions.
Remove anonymous users? [Y/n]: Press Y and enter
Disallow root login remotely? [Y/n]: Press Y and enter
Remove test database and access to it? [Y/n]: Press Y and enter
Reload privilege tables now? [Y/n]: Press Y and enter
#22. Create a new Database for WordPress
Database is where WordPress store all post, pages, themes, plugin, etc information.
Step 1. Login to MariaDB using below command, press Enter key.
sudo mysql -u root -p
Step 2. Create a new Database, and Grant Privileges to use its user with password
create database wordpress; grant all on wordpress.* to gulshan@localhost identified by 'PNybncuXfG2VxtP'; flush privileges; exit;
Where your …
Database is wordpress
username is gulshan
password is PNybncuXfG2VxtP
Tip: Consider using unique login credential
#23. Install PHP 7.4 and some required modules for WordPress
sudo apt install software-properties-common sudo add-apt-repository ppa:ondrej/php sudo apt update sudo apt install php7.4-fpm php7.4-common php7.4-mysql php7.4-xml php7.4-xmlrpc php7.4-curl php7.4-gd php7.4-imagick php7.4-cli php7.4-dev php7.4-imap php7.4-mbstring php7.4-soap php7.4-zip php7.4-bcmath -y
#24. Secure PHP-FPM
By default, php-fpm allow executing php files which even don’t exist in the server. It can be disabled by editing the php.ini file (located at /etc/php/7.4/fpm/php.ini).
You can do it manually by setting cgi.fix_pathinfo=0 in the php.ini file. Or you can run below command to do it automatically.
ls /etc/php/ sed -i 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g' /etc/php/7.4/fpm/php.ini systemctl restart php7.4-fpm.service
#25. Install NGINX
sudo apt install nginx -y
If NGINX installed successfully, you will see Welcome to nginx! page by visiting IP address.
#26. Assign proper permission
chown -R www-data:www-data /var/www/ sudo chmod -R 755 /var/www
#27. Configure UFW Firewall for improving security
Press y and Enter key
ufw allow ssh
ufw app info "Nginx Full"
ufw allow 'Nginx Full'
service nginx restart
#28. Configure Nginx Server Block
This is important where you need configure your domain, how NGINX should handle your PHP files.
First of all, we will delete default files.
rm /etc/nginx/sites-available/default rm /etc/nginx/sites-enabled/default
Then create a new server block
cd /etc/nginx/sites-available/ nano gulshankumar-org
- Make sure to update domain name at 5th line
- By default your path is /var/www/html/, update if required for installing new WordPress at same server or if you have rename HTML directory to something else.
- Enter below command and Press ctrl+o to save and ctrl+x to exit.
How to save? Press CTRL+O and Enter key.
Then, you can exit using command CTRL+X.
#29. Create symbolic links between two directories
To activate server block, you need to create symbolic links between two directories (/etc/nginx/sites-available/ and /etc/nginx/sites-enable). A symbolic link is nothing, just interlinking of two folders so that the content of one appear in other.
ln -s /etc/nginx/sites-available/gulshankumar-org /etc/nginx/sites-enabled/ sudo nginx -t service nginx restart systemctl restart php7.4-fpm.service systemctl restart mysql apt-get update
#30. Install Let’s Encrypt SSL Certificate for your domain
Warning: Don’t run this command while Cloudflare is active. Your domain must point to the Server IP address.
add-apt-repository ppa:certbot/certbot apt-get update apt-get install python-certbot-nginx
Obtain Certificate for your domain name
certbot --nginx -d gulshankumar.org -d www.gulshankumar.org
#31. Install WordPress In LEMP
Assuming, you want to install WordPress at default directory /var/www/html/, enter below command to install WordPress file.
When you type above command, you change your current directory to /var/www/html/
For your information, this is as per defined path in our NGINX server block. When you install a new WordPress, you may need to change this path.
tar -xvzf latest.tar.gz
mv -v wordpress/* /var/www/html
Clear Junks & Fix permission
rm -rf index.nginx-debian.html latest.tar.gz wordpress
chown -R www-data:www-data /var/www/
sudo chmod -R 755 /var/www
#32. Visit your blog domain name to setup WordPress for the first time.
Step 1. Provide basic Database login credential to begin WordPress Setup
Step 2. And, what! Just click on Run Installation button.
Step 3. Fill up Basic details and Install WordPress.
Step 4. Login to WordPress
5. Enter your username and Password to login WordPress.
6. Finally, we are in WordPress Dashboard.
#33. Tweak PHP Configuration for running WordPress smoothly
Most fancy theme and plugin requires high-end configuration to run. Therefore, we should make this changes.
Edit php.ini file
sudo nano /etc/php/7.4/fpm/php.ini
Use CTRL+W to quickly Find parameter in SSH and make changes as suggested below.
Change 30 to 300
Change 60 to 600
Change set to 128M to 256M
Change 8M to 64M
Change 2M to 32M
After this, please reload both the php-fpm and nginx services.
sudo service php7.4-fpm reload sudo service nginx reload
Finally, the WordPress Installation has been completed successfully with LEMP. I greatly appreciate your valuable time for reading this article. See you in the next tutorial!
Credits & Special Thanks to