Install WordPress with NGINX in CentOS

in #tutorials3 years ago

Setup:

This tutorial requires the user to have root privileges on the server.
Before working with WordPress you need to have LEMP (NGINX PHP MYSQL) on your server. If you dont have LEMP in your server you can set up those by following this tutorial.
STEPS:

  1. Download WordPress from the official website.
    wget http://wordpress.org/latest.tar.gz
    The above command will download the Zip file to the current working directory. Now unzip the file using the below command
    tar -xzvf latest.tar.gz
    2.Create WordPress Database and User
    As we have already installed MYSQL on your server, Create a Database and user. If not installed go to the setup section in this tutorial.
    mysql -u root -p
    Log in using the root password and Create Database
    CREATE DATABASE wordpress;
    Then create a new user
    CREATE USER wordpressuser@localhost;
    Set password for the new user
    SET PASSWORD FOR wordpressuser@localhost= PASSWORD("password");
    Note: You can replace the database, name, and password, with whatever you prefer.
    Refresh the MYSQL and exit
    FLUSH PRIVILEGES;
    exit;
    3.Setup the WordPress configuration
    Copy the sample configuration file to use
    cp ~/wordpress/wp-config-sample.php ~/wordpress/wp-config.php
    Now edit the configuration file
    sudo nano ~/wordpress/wp-config.php
    Find the section that contains the below fields and update with the correct Database, user and password
    // ** MySQL settings - You can get this info from your web host ** //
    /
    * The name of the database for WordPress /
    define('DB_NAME', 'wordpress');
    /
    * MySQL database username /
    define('DB_USER', 'wordpressuser');
    /
    * MySQL database password /
    define('DB_PASSWORD', 'password');
    Save and Exit the file.
    4.Copy the files
    Create a directory to store the WordPress files
    mkdir /var/www/wordpress
    Now copy the files to the created directory
    sudo cp -r ~/wordpress/ /var/www/wordpress

    Give ownership of the directory to the Nginx user
    cd /var/www/
    sudo chown nginx:nginx * -R
    5.Setup NGINX server blocks
    Now we need to set up the WordPress virtual host in Nginx. Although WordPress has an extra step in its installation, the Nginx website gives us an easy configuration file.
    sudo nano /etc/nginx/conf.d/default.conf
    Sample configuration file
#The default server
#
server {
listen 80;
server_name _;
#charset koi8-r;

#access_log  logs/host.access.log  main;

location / {
    root   /var/www/wordpress;
    index index.php  index.html index.htm;
}

error_page  404              /404.html;
location = /404.html {
    root   /usr/share/nginx/html;
}

# redirect server error pages to the static page /50x.html
#
error_page   500 502 503 504  /50x.html;
location = /50x.html {
    root   /usr/share/nginx/html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
#    proxy_pass   http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
    root           /var/www/wordpress;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    include        fastcgi_params;
}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
#    deny  all;
#}

Changes have to be done in the above file
if you want to access WordPress with the domain name change the server_name _; with server_name yourdomain.com
Add index.php within the index line.
Change the root to /var/www/wordpress;
Uncomment the section beginning with “location ~ .php$ {“,
Change the root to access the actual document root, /var/www/wordpress;
Change the fastcgi_param line to help the PHP interpreter find the PHP script that we stored in the document root home.
Save and exit the file
Now restart the Nginx for the changes to take effect
service nginx restart or
systemctl restart nginx
6.Access the WordPress from your browser
If everything happens smoothly, you have your WordPress ready.
Access your WordPress with the server’s IP or domain name (If you configured it in the previous step)
http://< ip>

Congratulations, Now you have a strong base to build your site.
If you want to secure your site with a free SSL certificate, Follow this tutorial.If you encounter any issues, please do not hesitate to post a comment here.

wordpress_centos.jpg

Coin Marketplace

STEEM 0.17
TRX 0.13
JST 0.027
BTC 60828.34
ETH 2917.60
USDT 1.00
SBD 2.38