Introduction
WordPress is the most popular and used content management systems (CMS) it allows users to setup webpage which MySQL backend alongside PHP processing. It is one of the best choice for a website designer.
We will use LEMP Stack to setup and get WORDPRESS up and runnning.
L – LINUX
E – NGINX
M- MySQL
P- PHP
Pre-requisites
- Ubuntu 22.04 server with sudo priviliges.
- LEMP Stack installed.
- TSL/SSL dynamic site security using NGINX encryption.
- Domain Name of a webpage
Step 1 — Create MySQL Database
Login to MySQL or if you authentication method to use a password for the MySQL root account use the 2nd commands.
$ sudo mysql or $ mysql -u root -p
Create a database with any name we are using wordpress
to keep thing simple.
mysql> CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
Now we create a separate MySQL user account that we will use exclusively to operate on our new database.We are using here the name wordpressuser
to keep it simple.
Once the Database and user is created then Exit from MySQL.
mysql> CREATE USER 'wordpressuser'@'localhost' IDENTIFIED BY 'password'; mysql> GRANT ALL ON wordpress.* TO 'wordpressuser'@'localhost'; mysql> EXIT;
Step 2 — Installing PHP Extensions
We need a PHP extension in order to communicate with MySQL.
$ sudo apt update $ sudo apt install php-curl php-gd php-intl php-mbstring php-soap php-xml php-xmlrpc php-zip
After the extension installation restart the PHP-FPM
$ sudo systemctl restart php8.1-fpm
Step 3 — Configure NGINX
Note the server’s domain name and IP address are protected by a TLS/SSL certificate
We are deploying /etc/nginx/sites-available/wordpress
as an example here to keep thinsg simple, definately you can change the path of your configuration file.
The default route is /var/www/html
but we are using /var/www/wordpress
as the root directory of our WordPress installation.
Now open this
$ sudo nano /etc/nginx/sites-available/wordpress
Change the output of file /etc/nginx/sites-available/wordpress
server { . . . 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 max; log_not_found off; } . . . } # Inside of the existing location / block, let’s adjust the try_files. # Instead of returning a 404 error as the default option, control is passed to the index.php file with the request arguments. server { . . . location / { #try_files $uri $uri/ =404; try_files $uri $uri/ /index.php$is_args$args; } . . . }
Now check the configuration
$ sudo nginx -t
If no errors reload NGINX
$ sudo systemctl reload nginx
Step 4 — Downloading WordPress
First chnage the directory
cd /tmp
Download the latest version
$ curl -LO https://wordpress.org/latest.tar.gz
Exract the compress folder to wordpress directory
$ sudo tar xzvf latest.tar.gz
Now we will copy sample configuration file to the WordPress filename
$ cp /tmp/wordpress/wp-config-sample.php /tmp/wordpress/wp-config.php
$ sudo cp -a /tmp/wordpress/. /var/www/<^>your_domain/wordpress
Now assign ownership to the www-data user and group. Here NGINX runs users and groups.
$ sudo chown -R www-data:www-data /var/www/your_domain/wordpress
Now Files are now in the server’s document root and have the right ownership.
Step 5 — Configuring WordPress Config file
We have to adjust. some secret keys to provide some security for the installation.
To get the Secure value from WordPress
$ sudo curl -s https://api.wordpress.org/secret-key/1.1/salt/
Output
# DO NOT COPY MY KEYS VALUE Output - define('AUTH_KEY', '1jl/vqfs<XhdXoAPz9 DO NOT COPY THESE VALUES c_j{iwqD^<+c9.k<J@4H'); define('SECURE_AUTH_KEY', 'E2N-h2]Dcvp+aS/p7X DO NOT COPY THESE VALUES {Ka(f;rv?Pxf})CgLi-3'); define('LOGGED_IN_KEY', 'W(50,{W^,OPB%PB<JF DO NOT COPY THESE VALUES 2;y&,2m%3]R6DUth[;88'); define('NONCE_KEY', 'll,4UC)7ua+8<!4VM+ DO NOT COPY THESE VALUES #`DXF+[$atzM7 o^-C7g'); define('AUTH_SALT', 'koMrurzOA+|L_lG}kf DO NOT COPY THESE VALUES 07VC*Lj*lD&?3w!BT#-'); define('SECURE_AUTH_SALT', 'p32*p,]z%LZ+pAu:VY DO NOT COPY THESE VALUES C-?y+K0DK_+F|0h{!_xY'); define('LOGGED_IN_SALT', 'i^/G2W7!-1H2OQ+t$3 DO NOT COPY THESE VALUES t6**bRVFSD[Hi])-qS`|'); define('NONCE_SALT', 'Q6]U:K?j4L%Z]}h^q7 DO NOT COPY THESE VALUES 1% ^qUswWgn+6&xqHN&%');
You can directly paste this values which is visible on your system , just open WordPress configuration file.
$ sudo nano /var/www/your_domain/wordpress/wp-config.php
Delete the lines and paste in the values here /var/www/<^>your_domain<^>/wordpress/wp-config.php
. . . define('AUTH_KEY', 'VALUES COPIED FROM THE COMMAND LINE'); define('SECURE_AUTH_KEY', 'VALUES COPIED FROM THE COMMAND LINE'); define('LOGGED_IN_KEY', 'VALUES COPIED FROM THE COMMAND LINE'); define('NONCE_KEY', 'VALUES COPIED FROM THE COMMAND LINE'); define('AUTH_SALT', 'VALUES COPIED FROM THE COMMAND LINE'); define('SECURE_AUTH_SALT', 'VALUES COPIED FROM THE COMMAND LINE'); define('LOGGED_IN_SALT', 'VALUES COPIED FROM THE COMMAND LINE'); define('NONCE_SALT', 'VALUES COPIED FROM THE COMMAND LINE'); . . .
Now we will configure database connection settings
/var/www/<^>your_domain<^>/wordpress/wp-config.php
Change the wordpress , wordpressuser, and password and add the last line ine the configuration file.
. . . define( 'DB_NAME', 'wordpress' ); /** MySQL database username */ define( 'DB_USER', 'wordpressuser' ); /** MySQL database password */ define( 'DB_PASSWORD', 'password' ); . . . define( 'FS_METHOD', 'direct' );
Step 6 — Configuring WordPress Webpage Interface
In your system open a web browser and type the server’s domain name or public IP address.
- Select the language you would like to use .
- In main setup page choose site title and username for example admin and a password for example pass and your email address .
- And then you should be successfully login.
Finally, WordPress should be installed and running and ready to use.