Install WordPress with LEMP (Shortcut way)


#1

Learn how to deploy LEMP (Linux, NGINX, MariaDB, PHP 7.2) for running WordPress

Required

  1. Minimum 512 MB RAM server. Try Digital Ocean / Vultr
  2. Putty for SSH

1. Update Ubuntu:

sudo apt update && sudo apt upgrade -y && sudo apt dist-upgrade && sudo apt autoclean && sudo apt autoremove -y

2. Install MariaDB & Secure MySQL Installation, Login to MySQL

sudo apt install mariadb-server -y && sudo mysql_secure_installation && mysql -u root -p

3. Make database for WordPress

    CREATE DATABASE wordpress;
    CREATE USER wordpressuser@localhost IDENTIFIED BY 'password';
    GRANT ALL PRIVILEGES ON wordpress.* TO wordpressuser@localhost;
    FLUSH PRIVILEGES;
    EXIT;

4. Install NGINX, PHP and setup UFW

sudo apt install nginx -y && sudo apt install php-fpm php-mysql php-curl php-mbstring php-gd php-json php-xml php-xmlrpc php-cgi php-zip php-pear -y && ufw enable && ufw allow ssh && ufw app info "Nginx Full" && ufw allow 'Nginx Full' && ufw status && service nginx restart

5. Delete default and create a new Nginx Server Block

rm /etc/nginx/sites-available/default && rm /etc/nginx/sites-enabled/default && cd /etc/nginx/sites-available/
nano example

6. Update Server block

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.2-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;
}

7. Create symbolic links between two directories

ln -s /etc/nginx/sites-available/example /etc/nginx/sites-enabled/
sudo nginx -t
service nginx restart
systemctl restart php7.2-fpm.service
systemctl restart mysql
apt update

8. Install Let’s Encrypt SSL Certificate for your domain

add-apt-repository ppa:certbot/certbot && apt update && apt install python-certbot-nginx && certbot --nginx -d example.com -d www.example.com

Test renew

certbot renew --dry-run

9. Install WordPress at /var/www/html directory

cd /var/www/html && wget https://wordpress.org/latest.tar.gz && tar -xvzf latest.tar.gz && mv -v wordpress/* /var/www/html && rm -rf index.nginx-debian.html latest.tar.gz wordpress && chown -R www-data:www-data /var/www/ && sudo chmod -R 755 /var/www

10. 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.2/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


Next, reload both the php-fpm and nginx services.

sudo service php7.2-fpm reload sudo service nginx reload

Finally, the WordPress Installation has been completed successfully with LEMP.


Credits: @Paritosh, thanks for the efforts.

For detailed version see https://gulshankumar.net/install-wordpress-with-lemp-on-ubuntu-18-04/
Thanks


How to increase website speed after hosting digital ocean
How to increase website speed after hosting digital ocean
How to increase website speed after hosting digital ocean
#9

How to insert SSL into it? I didn’t install Let’s Encrypt. I have installed Cloudflare SSL for 15 years. Also Should I add ipv6 support into it?


#10

Hello @Turk,

If you have Cloudflare SSL, you can skip LE installation (Step 8.)

Yes, you can add support for IPV6 using DNS AAAA record. Cloudflare supports this feature.

Thanks & Regards,
Gulshan