The Complete Guide to Install Nginx on CentOS 7 with phpMyAdmin

Installing LEMP (Linux, Nginx, MariaDB, PHP)

Nginx installation and configuration:
  1. Install dependencies before installing Nginx.
    sudo yum install epel-release
  2. Install Nginx using yum.
    sudo yum install nginx
  3. Start Nginx services.
    sudo systemctl start nginx
  4. Check your Nginx server if it is working using your browser.
    http://youripaddress/
  5. Enable Nginx at boot start.
    sudo systemctl enable nginx
PHP installation and configuration:
  1. Include php-mysql php-fpm package.
    sudo yum install php-mysql php-fpm
  2. Browse php.ini directory file.
    sudo nano /etc/php.ini
  3. Look for cgi.fix and update it with the data below.
    cgi.fix_pathinfo=0
  4. Configure www.conf by browsing its location and updating its www.conf file.
    sudo nano /etc/php-fpm.d/www.conf
    listen = /var/run/php-fpm/php-fpm.sock
    
    listen.owner = nobody
    listen.group = nobody
    
    user = nginx
    group = nginx
    
  5. Start PHP processor.
    sudo systemctl start php-fpm
  6. Enable PHP processor to start at boot.
    sudo systemctl enable php-fpm
Virtual hosts configuration and other configuration:
  1. Create a directory for sites-available and sites-enabled.
    mkdir -p /etc/nginx/sites-available
    mkdir -p /etc/nginx/sites-enabled
    
  2. Add a configuration file in sites-available folder.
    sudo nano /etc/nginx/sites-available/yourdomain.com.conf
  3. Add a configuration in your configuration file (yourdomain.com.conf) using the data below.
    server {
        listen	 80;
        server_name  www.yourdomain.com yourdomain.com;
    
        # note that these lines are originally from the "location /" block
        root   /var/www/yourdomain.com/public_html;
        index index.php index.html index.htm;
    
        location / {
            try_files $uri $uri/ /index.php?$args;
        }
        error_page 404 /404.html;
        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
            root /var/www/yourdomain.com/public_html;
        }
    
        location ~ .php$ {
            try_files $uri =404;
            fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
        }
    }
    
  4. Create a symbolic link to sites-enabled.
    sudo ln -s /etc/nginx/sites-available/yourdomain.com.conf /etc/nginx/sites-enabled/yourdomain.com
  5. Browse nginx.conf file.
    sudo nano /etc/nginx/nginx.conf
  6. Add the code below inside http to enable your configuration (yourdomain.com.conf) file.
    include /etc/nginx/sites-enabled/*;
  7. Create a directory for your website.
    mkdir -p /var/www/yourdomain.com/{public_html,logs}
  8. Browse www directory and change ownership and permission in www directory to access publicly.
    cd /var/www
    
    sudo chown nginx:nginx * -R
    sudo chmod 755 * -R
    
  9. Restart Nginx service.
    sudo systemctl restart nginx
  10. To know if you have successfully installed and configured PHP, test it using the following steps:
    1. Create a PHP file to your site directory.
      sudo nano /var/www/yourdomain/public_html/info.php
    2. Add a PHP code to test it.
      <?php phpinfo(); ?>
    3. Check your browser to see if it is working by displaying its PHP version and information.
      http://your-server-ip/info.php
MariaDB Installation and Configuration:
  1. Get components, helper package and install using yum.
    sudo yum install mariadb-server mariadb
  2. Start the database services.
    sudo systemctl start mariadb
  3. Secure your database. Read instructions and steps.
    sudo mysql_secure_installation
  4. Start MariaDB at boot by enabling it.
    sudo systemctl enable mariadb

Probewise

I create WordPress themes and plugins with simplicity for all people. I am also a blogger, layout artist and a computer technician.

Join the Discussion

Your email address will not be published.

Back to top