Following on from my last post of upgrading MySQL to MariaDB my next task was to install Nginx as a replacement web server to Apache. I’ve been using Nginx for over a year now and am really impressed with it’s performance compared to Apache. I will also be enabling Nginx to use OpenCart.

With that installing it on CentOS 7 is doddle, first thing is to import the repository

Then install it using yum

then start and enable the service so it starts at boot time

That’s the basic we will need to add some basic configuration so we need to edit ‘/etc/nginx/nginx.conf’ and replace it’s contents with

We will store our website config files in the ‘/etc/nginx/conf.d’ directory next we will enable site config which is using OpenCart, now my website root directory is in the ‘/home/centos/public’ directory which is running under a system user called ‘centos’ (just substitute ‘centos’ with the user you are using) so if the user is not there we will have to add them so in the terminal

Then add a password

And type your password when prompted. We will also need to make our public directory and make sure our user directories has all the right permissions so these commands should do it.

Now we can add our OpenCart Nginx config file so open the file with

and put this in it and save the file

Dont worry too much about the location block at line 37 as this just deals with the PHP handling also the rewrite rules are because OpenCart has weird rules for routing page and SEO urls.

Now we have done that we can restart Nginx with

You can test the configuration by putting a ‘index.html’ file in the public folder and you should see it working, we can’t yet upload OpenCart or test PHP yet because we will need to compile that, I will deal with that in my next post.

Any question please use the comments and I will try my best in answering.

  • Pingback: Compiling PHP 7 on CentOS | Shaun Freeman()

  • tcowin

    Good stuff! Thanks for putting all of this together. It’s a help in getting a CentOS7/PHP7 server up and running. Question I had relates to generic WordPress hosting vs. OpenCart. What is specific to OpenCart above that I might want to change for a more generic situation (I have WordPress, Drupal and some Symfony stuff, but in this case I think I’m pretty much just using WP).

    • Thanks for you comment.
      To answer your question everything between ‘# START Rewrite rules’ and ‘# END Rewrite rules’ can be omitted if not using OpenCart those rewrite rules are only need for OpenCart because of it’s strange way it routes the application. WordPress will run fine without them not sure about Drupal or Symfony as I have not used these.
      Hope this helps you.