prerequisites install WordPress on ubuntu
how to install wordpress on ubuntu LEMP nginx
sudo apt install mysql-server
sudo apt install php-pear php-fpm php-dev php-zip php-curl php-xmlrpc php-gd php-mysql php-mbstring php-xml sudo service nginx restart
Creation mysql database from command line – install wordpress on ubuntu
step 1 create database
step 2Add permission to mysql user (if necessary)
Starts here install wordpress on ubuntu (Apache / nginx Debian)
step 1: create new directory – install wordpress on ubuntu
1.a create new directory
1.b change permission to 755 (opiontal_
1.c Navigate to the directory
step 2: Download WordPress & Unzip – install wordpress on ubuntu
root@localhost:/var/www/html/files# wget https://wordpress.org/latest.tar.gz
–2021-07-14 10:21:12– https://wordpress.org/latest.tar.gz
Resolving wordpress.org (wordpress.org)… 198.143.164.252
Connecting to wordpress.org (wordpress.org)|198.143.164.252|:443… connected.
HTTP request sent, awaiting response… 200 OK
Length: 15750424 (15M) [application/octet-stream]
Saving to: ‘latest.tar.gz’
latest.tar.gz 100%[===================>] 15.02M 5.86MB/s in 2.6s
2021-07-14 10:21:16 (5.86 MB/s) – ‘latest.tar.gz’ saved [15750424/15750424]
step 2.a unzip tar wordpress zip on ubutu commandline
step 3: Move files top directory from wordpress folder.
step 4: Delete folder and zip archive – install wordpress on ubuntu
The shortcut or Shell Script
If you created database already
rename & Edit WordPress wp-config.php ubtunu
rename
mv wp-config-sample.php wp-config.php
make sure change permissions before installing a plugin..
also you can copy existing plugins & themes other website in same server.
all
cp source to destination more at CP command
cp -r /var/www/html/wordpress1.in/wp-content/themes/* /var/www/html/woprdpress2.com/wp-content/themes/
cp -r /var/www/html/wordpress1.in/wp-content/plugins/* /var/www/html/woprdpress2.com/wp-content/plugins/
to verify
ls – l /var/www/html/woprdpress2.com/wp-content/themes/
single
cp -r /var/www/html/wordpress1.in/wp-content/plugins/pluginname /var/www/html/woprdpress2.com/wp-content/plugins/pluginname
change ownership of wordpress directory root server user (imp)
sudo chown -R www-data:www-data /var/www/html/files/
sudo chown -R jagdisshanandh:jagdisshanandh /var/www/*
3rd way fast nginx shell script install wordpress on ubuntu
Part 1 DB creation part
1.mysql -u root -prootpass -e “create database dbname;”
user creation example below:
sudo mysql -e “CREATE USER ‘datadog’@’localhost’ IDENTIFIED BY ‘h3ub7BmyGv UL5TskBFlG9rF’;”
mysql -u root -prootpasss -e “CREATE USER ‘datadog’@’localhost’ IDENTIFIED BY ‘h3ub7BmyGv UL5TskBFlG9rF’;”
Part 2 wp & db details add
sudo mkdir /var/www/html/website.com && cd /var/www/html/website.com && wget https://wordpress.org/latest.tar.gz && tar xfz latest.tar.gz && mv wordpress/* ./ && rmdir ./wordpress/ && rm -f latest.tar.gz && mv wp-config-sample.php wp-config.php && sudo nano ./wp-config.php
b. Change database details c. save file and exit by (CTRLX+X and Then type and Press Enter)
tail /var/log/nginx/error.log
Part 3 server block domain to directory setup for nginx
cat >/etc/nginx/sites-enabled/website <<EOF
server {
listen 80;
root /var/www/html/website/;
server_name website.com www.website.com;
include /etc/nginx/conf.d/global.config; #remaining info
}
EOF
website = website directory
cat >/etc/nginx/sites-enabled/files <<EOF
server {
listen 443;
root /var/www/html/files/;
server_name file.sarkariresult.in;
include /etc/nginx/conf.d/global.config;
}
EOF
incase ssl https nginx server block configuration
cat >/etc/nginx/sites-enabled/website.com<<EOF
server {
listen 443;
root /var/www/html/website.com/;
server_name website.com www.website.com;
ssl_certificate /etc/nginx/ssl/certname.pem;
ssl_certificate_key /etc/nginx/ssl/certname.key;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
#fastcgi_pass unix:/run/php/php7.2-fpm.sock;
fastcgi_pass 127.0.0.1:9000;
}
}
EOF
also nginx server block explained
verify and reload the server
nginx -t && nginx -s reload
etc/nginx/sites-enabled/yourdesiredname
Create or upload ssl certificates to a folder and point theme more at nginx ssl certificate configuration
above code
nano /etc/nginx/ssl/certname.pem
//add code and save
nano /etc/nginx/ssl/certname.key
global.config; need to edit o directly above for php settings
//ln -s /etc/nginx/sites-available/website.com /etc/nginx/sites-enabled/website.com
chown www-data:www-data -R /var/www/html/
Point domain IP to Server IP.
wordpress nginx server block sample
server {
listen 80;
root /var/www/html/wordpress/public_html;
index index.php index.html;
server_name SUBDOMAIN.DOMAIN.TLD;
access_log /var/log/nginx/SUBDOMAIN.access.log;
error_log /var/log/nginx/SUBDOMAIN.error.log;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.2-fpm.sock; #8.1 php version or tcp port
}
location ~ /\.ht {
deny all;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
}
sample 2
# Redirect HTTP -> HTTPS server { listen 80; server_name www.sample.com sample.com; include snippets/letsencrypt.conf; return 301 https://sample.com$request_uri; } # Redirect WWW -> NON-WWW server { listen 443 ssl http2; server_name www.sample.com; ssl_certificate /etc/letsencrypt/live/sample.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/sample.com/privkey.pem; ssl_trusted_certificate /etc/letsencrypt/live/sample.com/chain.pem; include snippets/ssl.conf; return 301 https://sample.com$request_uri; } server { listen 443 ssl http2; server_name sample.com; root /var/www/html/sample.com; index index.php; # SSL parameters ssl_certificate /etc/letsencrypt/live/sample.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/sample.com/privkey.pem; ssl_trusted_certificate /etc/letsencrypt/live/sample.com/chain.pem; include snippets/ssl.conf; include snippets/letsencrypt.conf; # log files access_log /var/log/nginx/sample.com.access.log; error_log /var/log/nginx/sample.com.error.log; location = /favicon.ico { log_not_found off; access_log off; } location = /robots.txt { allow all; log_not_found off; access_log off; } location / { try_files $uri $uri/ /index.php?$args; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php7.2-fpm.sock; } location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ { expires max; log_not_found off; } }