This tutorial has been written to help you set up a server running Ubuntu 20.04 with Nginx and WordPress.
If you are looking for a solution that is fast, scalable, secure, and low maintenance then this guide is perfect for you. It will take you step-by-step through the process of installing the latest version of Ubuntu on your VPS server. Then it will show you how to install WordPress on your freshly installed Ubuntu server in less than 10 minutes! If this sounds too good to be true then read on because I'll show you how...
1: Copy Instance IP Address
2: Generate Puttgen Private Key using the Private & Public Keys Generated While Creating Your Instance
Conversions > Import Key > Select Your PrivateKey File
Click Save Private Key > Press YES
3: Open Putty
Paste Your IPAddress
Under Connection > SSH > Auth > Click Browse & Select the private key file generated from puttygen
4: Click the Open Button on Putty to connect through SSH > Accept
5: login as: default value on username is ubuntu
6: Type the series of commands one by one
sudo su -
sudo apt update && apt upgrade -y
sudo apt autoremove
sudo apt install ufw
sudo ufw allow ssh
sudo ufw allow http
sudo ufw allow https
sudo ufw enable
7: Install NGINX
sudo add-apt-repository ppa:ondrej/nginx -y
apt update && apt upgrade -y
sudo apt install nginx -y
service nginx status
..Output
...
root@ubuntu-nginx-test:~# service nginx status
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; disabled; vendor preset: enabled)
Active: active (running) since Wed 2021-07-21 02:34:01 IST; 41s ago
Docs: man:nginx(8)
Main PID: 16743 (nginx)
Tasks: 2 (limit: 2010)
Memory: 4.0M
CGroup: /system.slice/nginx.service
├─16743 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
└─16744 nginx: worker process
Jul 21 02:34:01 ubuntu-nginx-test systemd[1]: Starting A high performance web server and a reverse proxy server...
Jul 21 02:34:01 ubuntu-nginx-test systemd[1]: nginx.service: Failed to parse PID from file /run/nginx.pid: Invalid argu>
Jul 21 02:34:01 ubuntu-nginx-test systemd[1]: Started A high performance web server and a reverse proxy server.
lines 1-14/14 (END)
Now type CTRL+C to end the Nginx service status output. And then open your browser and visit your server’s public IP address (http://public_ip_address/).
8: In Oracle Cloud, I had encountered some issues regarding the firewall rules. Deploying an instance and set the firewall rules on the VCN subnet section for HTTP and HTTPS requests is not enough, because after adding the rules the accessibility will same as without adding any VCN rules.
sudo iptables -I INPUT 6 -m state --state NEW -p tcp --dport 80 -j ACCEPT
sudo netfilter-persistent save
9: Install Stable PHP
sudo add-apt-repository ppa:ondrej/php -y
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-opcache php7.4-redis \
php7.4-soap php7.4-zip -y
sudo php -v
..Output
...
root@ubuntu-nginx-test:~# php -v
PHP 7.4.21 (cli) (built: Jul 1 2021 16:09:41) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.21, Copyright (c), by Zend Technologies
10. Install MariaDB database
sudo apt-get install software-properties-common
sudo apt-key adv --fetch-keys 'https://mariadb.org/mariadb_release_signing_key.asc'
sudo add-apt-repository 'deb [arch=amd64,arm64,ppc64el] http://mirrors.up.pt/pub/mariadb/repo/10.4/ubuntu focal main'
sudo apt install mariadb-server -y
sudo mysql_secure_installation
..output
...
root@ubuntu-nginx-test:~# sudo mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
haven't set the root password yet, you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorisation.
You already have your root account protected, so you can safely answer 'n'.
Switch to unix_socket authentication [Y/n] Y
Enabled successfully!
Reloading privilege tables..
... Success!
You already have your root account protected, so you can safely answer 'n'.
Change the root password? [Y/n] Y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] Y
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] Y
... Success!
By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] Y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] Y
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
11: Create Database & Configure
CREATE DATABASE wp_example CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'user'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON wp_example.* TO user@localhost IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
exit;
12: Download WordPress & Configure
cd tmp
wget -c https://wordpress.org/latest.tar.gz
tar -xvzf latest.tar.gz
sudo mkdir /var/www/html/sitename
sudo rsync -avP wordpress/ /var/www/html/sitename
sudo chown -R www-data:www-data /var/www/html/sitename
sudo chmod 755 -R /var/www/html/sitename
13: Configure NGINX
sudo nano /etc/nginx/sites-available/default
server{
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.php index.html index.htm index.nginx-debin.html;
server_name server_domain_or_IP;
location / {
try_files $url $url/ -404;
}
location ~ \.php$ {
include $nippets/fastcgi.php.conf;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
sudo nginx -t
sudo systemctl reload nginx
Now, open your WordPress website URL and set up the basic information like database credentials and the site information.
Sometimes: Users Get
Change Nginx configuration file
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
Check and Add
Add index index.php;
In the server block here
So, that is the basic configuration file for WordPress on Nginx.
Comments
Post a Comment