Knowledgebase

Getting Started with the CentOS LEMP RCS Marketplace App Print

  • 0

Introduction

RCS's One-Click LEMP application is a Linux web development stack consisting of Nginx, MariaDB/MySQL, and PHP on your choice of Ubuntu or CentOS. This article explains the initial setup steps, default paths, and other configuration details.

The examples in this guide use IP address 192.0.2.123 and the domain name example.com, which you should replace with your instance's actual address and domain name.

After deployment, you can access the server's default webpage via HTTP at http://192.0.2.123 or HTTPS at https://192.0.2.123. When first deployed, the server has a self-signed SSL certificate which requires bypassing the HTTPS warning.

To install a Let's Encrypt SSL certificate, you'll need to create a DNS "A" record for your server. Then, use the instructions from your domain registrar, or follow this guide if you use RCS DNS.

Connect to the Server

SSH to the server as root using the IP address and password shown on the server information page.

Create a Non-Root sudo User

  1. Create the user account.

    # adduser exampleuser
    
  2. Assign the user a strong password by running the passwd command.

    # passwd exampleuser
    
  3. Add the user to the wheel group.

    # usermod -aG wheel example_user
    
  4. Switch to the new user.

    # su - example_user
    
  5. Test sudo access.

    $ sudo whoami
    

    Output:

    [sudo] password for exampleuser:
    root
    

Continue the rest of this guide as the sudo user.

Nginx Configuration

  • The default Nginx web root (web files) directory is /usr/share/nginx/html.
  • The Nginx configuration file directories are /etc/nginx, and /etc/nginx/conf.d.

To set up Nginx, backup all default configuration files.

  1. Switch to the /etc/nginx/conf.d directory.

    $ cd /etc/nginx/conf.d/
    
  2. Back up the configuration files.

    $ sudo mv default.conf default.BAK
    $ sudo mv http.conf http.BAK
    $ sudo mv https.conf https.BAK
    
  3. Create a new Nginx configuration file.

    $ sudo touch /etc/nginx/conf.d/example.com.conf
    
  4. Using a text editor, open and edit the file.

    $ sudo nano /etc/nginx/conf.d/example.com.conf
    
  5. Add the following contents to the file. Replace example.com with your actual domain name.

    server {
        listen 80 default_server;
        listen [::]:80 default_server;
        server_name example.com;
    
        # Webroot directory and files
        root /usr/share/nginx/example.com;
        index index.php index.html;
    
        # Handle PHP Files
        location ~ \.php$
        {
            try_files      $uri =404;
            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.
        location ~ /\.ht {
            deny  all;
        }
    }
    

    Save and close the file.

    This configuration file uses /usr/nginx/share/example.com as the website root directory. To use a different directory such as /var/www/, edit the root directory directive to match your directory name.

    If you do not have a domain name, you can use _ in the server_name directive as a catch-all server name. See Nginx Server Name Syntax for more information.

  6. Create the domain document root (files) directory.

    $ sudo mkdir /usr/share/nginx/example.com
    
  7. Create an index PHP file.

    $ sudo nano /usr/share/nginx/example.com/index.php
    
  8. Add the following contents to the file.

    <? php
    
    echo "Hello World! Your One-Click configuration works";
    
    ?>
    
  9. Save and close the file.

  10. Grant Nginx read and write permissions to the directory.

    $ sudo chown -R nginx:nginx /usr/share/nginx/example.com/
    
  11. Test Nginx for configuration errors.

    $ sudo nginx -t
    
  12. Restart Nginx to load changes.

    $ sudo systemctl restart nginx
    
  13. Test the configuration by visiting your domain.

    http://example.com
    

Install SSL Certificates

You need a DNS "A" record pointing to your server's IP address to use a Let's Encrypt SSL certificate.

To install a Let's Encrypt certificate, follow our guide: Install a Free Let's Encrypt TLS/SSL Certificate on a CentOS 7 LEMP Server with Certbot

MySQL

MariaDB is the drop-in replacement for MySQL installed on the RCS One-Click server. It uses the same syntax and database commands.

  1. View and copy the root user password.

    $ sudo cat /root/.my.cnf
    

    The output should look similar to the following:

    [client]
    user=root
    password=lR7l3iv7Cc7QhZz
    
  2. Log in to MySQL as root.

    $ sudo mysql -u root -p
    

    Paste the root user password from the previous step into the prompt.

  3. Change the default root password. Replace strong-password with your own password.

    MariaDB [(none)]>  UPDATE mysql.user SET authentication_string=PASSWORD('strong-password') WHERE USER='root';
    
  4. Refresh MySQL privileges.

    MariaDB [(none)]> FLUSH PRIVILEGES;
    
  5. Exit the MySQL console.

    MariaDB [(none)]> EXIT
    
  6. Test your new password by re-accessing the MySQL console as root.

    $ sudo mysql -u root -p
    

    Enter your new password.

See more resources to manage MySQL:

PHP

  1. Verify the PHP version installed on the server.

    $ php -v
    

    Output:

    PHP 7.4.23 (cli) (built: Aug 26 2021 15:51:37) ( NTS )
    Copyright (c) The PHP Group
    Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.23, Copyright (c), by Zend Technologies
    with Xdebug v3.0.4, Copyright (c) 2002-2021, by Derick Rethans
    
  2. To access a list of installed PHP extensions, create a PHP script in your document root (website files) directory.

    $ sudo nano /usr/share/nginx/example.com/test.php
    
  3. Add the following contents to the file.

    <?php
    
    phpinfo();
    
    ?>
    

    Save and close the file.

  4. Visit your domain and load the test.php file through a web browser.

    https://example.com/test.php
    

    One-Click LEMP PHP Extensions

  5. The most common PHP extensions are pre-installed on the server. To install other extensions, use your package manager. For example:

    $ sudo yum install php-tokenizer php-bcmath php-sodium
    

For more information on using PHP, refer to the following resources.

Next Steps

You have successfully deployed RCS's One-Click LEMP application and configured installed services. Next, fine-tune your server with the following resources according to your web development needs.


Was this answer helpful?
Back

Powered by WHMCompleteSolution