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 $50 free credits.
#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
sudo reboot
#19. Please Login to Putty again after 30 seconds
root@server-ip-address
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
sudo mysql_secure_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
ufw enable
Press y and Enter key
ufw allow ssh
ufw app info "Nginx Full"
ufw allow 'Nginx Full'
ufw status
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.
server { listen 80; root /var/www/html; index index.php index.html index.htm; server_name .example.com; client_max_body_size 0; error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location / { try_files $uri $uri/ /index.php?q=$uri&$args; } location ~* \.php$ { if ($uri !~ "^/uploads/") { fastcgi_pass unix:/run/php/php7.4-fpm.sock; } include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name; } location = /favicon.ico { log_not_found off; access_log off; } location = /robots.txt { log_not_found off; access_log off; allow all; } location ~* .(css|gif|ico|jpeg|jpg|js|png)$ { expires 1y; log_not_found off; } # Enable Gzip compression. gzip on; # Disable Gzip on IE6. gzip_disable "msie6"; # Allow proxies to cache both compressed and regular version of file. # Avoids clients that don't support Gzip outputting gibberish. gzip_vary on; # Compress data, even when the client connects through a proxy. gzip_proxied any; # The level of compression to apply to files. A higher compression level increases # CPU usage. Level 5 is a happy medium resulting in roughly 75% compression. gzip_comp_level 5; # Compress the following MIME types. gzip_types application/atom+xml application/javascript application/json application/ld+json application/manifest+json application/rss+xml application/vnd.geo+json application/vnd.ms-fontobject application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/bmp image/svg+xml image/x-icon text/cache-manifest text/css text/plain text/vcard text/vnd.rim.location.xloc text/vtt text/x-component text/x-cross-domain-policy; }
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.
cd /var/www/html
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.
wget https://wordpress.org/latest.tar.gz
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.
https://example.com
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.
max_execution_time
Change 30 to 300
max_input_time
Change 60 to 600
memory_limit
Change set to 128M to 256M
post_max_size
Change 8M to 64M
upload_max_filesize
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
https://help.gulshankumar.net/t/how-to-install-wordpress-with-lamp-lemp-in-ubuntu-18-04/2954
Thanks a lot gulshran .you save my breath
i search everywhere but not find any good article
you explained very well along with security concern
well done
Finally I loved this step by step tutorial with proper images.
Thanks Bhaiya you are awesome
Hi,
Thank you for this awesome guide.
How can I install WordPress multisite on Ubuntu 18.04 with Nginx?
Thanks Gulshan, Finally I moved to NGINX server. You have created a great tutorial for beginners.
You’re welcome bro :)
Thank you for your tutorial, its the first one that actually showed me the wordpress setup page.
When I went to upload a plugin I received this message. “The uploaded file exceeds the upload_max_filesize directive in php.ini”
How do I increase the max filesize?
Please see the step 33.5
Thanks sos un groso, very well tutorial
How to auto-renew SSL?
Add below cron job
crontab -e
Add below command and save.
15 3 * * 7 certbot renew --post-hook "service nginx restart"
Very well. thank you so much
Hello Gulshan Bro, First i want to say you that this is very beautiful and required post. I am really appreciating your work. but i have a problem can you please tell me
i have a droplet with digitalocean ($5/month plan) and i want to host multiple wordpress sites only with nginx(lemp ubuntu 18.04).
In simple i mean that this tutorial is complete to install a single wordpress and i did it but tell host it in some other sites
Hey Rohit,
Assuming, second site is example2.org
You need to follow steps this way.
1. create a new directory and add WordPress (Ref: steps 31)
cd /var/www/
mkdir example2
wget https://wordpress.org/latest.tar.gz
tar -xvzf latest.tar.gz
mv -v wordpress/* /var/www/example2
rm -rf index.nginx-debian.html latest.tar.gz wordpress
chown -R www-data:www-data /var/www/
sudo chmod -R 755 /var/www
2. Create a new Server block with root path located to new directory as created in step 1.
cd /etc/nginx/sites-available/
nano gulshankumar-org
server {
listen 80;
root /var/www/example2;
index index.php index.html index.htm;
server_name example2.org www.example2.org;
...
3. Point your example2.org domain to DNS, then install SSL
certbot --nginx -d example2.org -d www.example2.org
4. Create new MySQL database
sudo mysql -u root -p
create database example2;
grant all on example2.* to example2@localhost identified by 'TYPE HERE PASSWORD';
flush privileges;
exit;
5. Proceed to Installation by visiting your site
https://example2.org
Let me know if you have any additional question. You can always visit our forum for quick assistance.
Thanks & Regards,
Gulshan
It Really Works Gulshan Bro. Thanks Really dear You are awesome…
i want redirect too www plz help me urgent
If your WordPress General Settings has www version, server will do automatically. No additional action is required. In case you started WordPress installation at non-www version, then you need to migrate by changing at Database level.