Setting up blog with WordPress: Step 2- Setting up wordpress under your nginx.

Hey there,

We have already setup a server and is now ready with the wordpress. First we must know what actually wordpress, So wordpress is a CMS i.e. Content Management Software. It is built in php and supports a large number of plugins for doing almost every thing. It has plugin from google analytics to privacy policy page.

You do not have to write a single line of code to get your website started. It is as simple as that. You can read about it more here on  wordpress. So lets get started with the wordpress installation.

  1. SSH into your AWS server by running.
    ssh -i keyfile.pem ubuntu@your_server_ip
  2. Go to directory you want to install wordpress it will be generally /var/www/wesite_name and run
    wget http://wordpress.org/latest.tar.gz
    tar xfz latest.tar.gz
  3. You have downloaded the latest version and extracted it.
  4. Now you want a mysql server running.
    sudo apt-get install mysql-server
  5. If you are facing error with mysql installation try this digital ocean article.
  6. Now we need to create a database for wordpress to connect with.
    mysql -u username -p
  7. Then enter your passoword and create schema by using the below commands
    create schema database_name;
  8. Check, you are still in that directory where you installed wordpress. Now run
    mv wordpress/* ./
  9. It will move the file from extracted folder to your root folder.
  10. Now the extracted directory and .tar file that was downloaded.
  11. Open wp-config.php in edit mode and change the database name host and other credentials in that file.
    vi wp-config.php
  12. Now try opening your public URL given. What it did not open ? Yes because we have not told nginx where to find the files to serve.
  13. We have Nginx installed but we do not have php to process .php files. We need to install those.
    sudo apt-get install php5-fpm php5-mysql
  14. Now we have php installed just restart the server by using
    sudo service nginx restart
  15. Again if you open in browser it will show the same error its because of that only. We need to tell nginx to serve file from.
  16. Open nginx config settings.
    sudo vi /etc/nginx/sites-available/default
  17. We are editing the default file which is already linked to the sites-enabled directory.
  18. Now add these line to tell the server you directory.
    server {
            listen   80;
         
    
            root /usr/share/nginx/www;
            index index.php index.html index.htm;
    
            server_name example.com;
    
            location / {
                    try_files $uri $uri/ /index.html;
            }
    
            error_page 404 /404.html;
    
            error_page 500 502 503 504 /50x.html;
            location = /50x.html {
                  root /usr/share/nginx/www;
            }
    
            # pass the PHP scripts to FastCGI server listening on the php-fpm socket
            location ~ \.php$ {
                    try_files $uri =404;
                    fastcgi_pass unix:/var/run/php5-fpm.sock;
                    fastcgi_index index.php;
                    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                    include fastcgi_params;
                    
            }
    
    }
  19. Now for permission run these commands and these will fix all the permissions.
    chown -R www-data:www-data your-wordpress-directory
    sudo find /var/www/wordpress/ -type d -exec chmod 755 {} \;
    sudo find /var/www/wordpress/ -type f -exec chmod 644 {} \;
  20. Now restart the nginx server and open public ip in your browser you will see the wordpress settings page.
  21. Enter the setting and your wordpress site is up.

If you have any problem anywhere setting up or any error is coming try searching on google or stackoverflow cause this is where i learn everything.

Next part of the tutorial is live here.

If you missed the first part read it here.


Gaurav Yadav

Gaurav is cloud infrastructure engineer and a full stack web developer and blogger. Sportsperson by heart and loves football. Scale is something he loves to work for and always keen to learn new tech. Experienced with CI/CD, distributed cloud infrastructure, build systems and lot of SRE Stuff.

2 COMMENTS
  • Setting up blog with Wordpress and Nginx: Step 1- Setting up aws server and nginx. - Learn Steps
    Reply

    […] Next step of the tutorial is live. Start reading it. […]

  • Setting up blog with WordPress and Nginx: Step 3- Setting up DNS Mapping and SMTP Using Yandex - Learn Steps
    Reply

    […] Setting up WordPress Blog with aws and nginx: part 2 […]

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.