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
Create the user account.
# adduser exampleuserAssign the user a strong password by running the
passwdcommand.# passwd exampleuserAdd the user to the wheel group.
# usermod -aG wheel example_userSwitch to the new user.
# su - example_userTest sudo access.
$ sudo whoamiOutput:
[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.
Switch to the
/etc/nginx/conf.ddirectory.$ cd /etc/nginx/conf.d/Back up the configuration files.
$ sudo mv default.conf default.BAK $ sudo mv http.conf http.BAK $ sudo mv https.conf https.BAKCreate a new Nginx configuration file.
$ sudo touch /etc/nginx/conf.d/example.com.confUsing a text editor, open and edit the file.
$ sudo nano /etc/nginx/conf.d/example.com.confAdd the following contents to the file. Replace
example.comwith 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.comas the website root directory. To use a different directory such as/var/www/, edit therootdirectory directive to match your directory name.If you do not have a domain name, you can use
_in theserver_namedirective as a catch-all server name. See Nginx Server Name Syntax for more information.Create the domain document root (files) directory.
$ sudo mkdir /usr/share/nginx/example.comCreate an index PHP file.
$ sudo nano /usr/share/nginx/example.com/index.phpAdd the following contents to the file.
<? php echo "Hello World! Your One-Click configuration works"; ?>Save and close the file.
Grant Nginx read and write permissions to the directory.
$ sudo chown -R nginx:nginx /usr/share/nginx/example.com/Test Nginx for configuration errors.
$ sudo nginx -tRestart Nginx to load changes.
$ sudo systemctl restart nginxTest 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.
View and copy the root user password.
$ sudo cat /root/.my.cnfThe output should look similar to the following:
[client] user=root password=lR7l3iv7Cc7QhZzLog in to MySQL as root.
$ sudo mysql -u root -pPaste the root user password from the previous step into the prompt.
Change the default root password. Replace
strong-passwordwith your own password.MariaDB [(none)]> UPDATE mysql.user SET authentication_string=PASSWORD('strong-password') WHERE USER='root';Refresh MySQL privileges.
MariaDB [(none)]> FLUSH PRIVILEGES;Exit the MySQL console.
MariaDB [(none)]> EXITTest your new password by re-accessing the MySQL console as root.
$ sudo mysql -u root -pEnter your new password.
See more resources to manage MySQL:
PHP
Verify the PHP version installed on the server.
$ php -vOutput:
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 RethansTo 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.phpAdd the following contents to the file.
<?php phpinfo(); ?>Save and close the file.
Visit your domain and load the
test.phpfile through a web browser.https://example.com/test.php
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.
- Use PHP-FPM Pools to Secure Multiple Websites
- How to Install phpRedisAdmin on CentOS 7
- How to Manage PHP Session Data with Redis on Ubuntu 20.04
- How to Setup Redis Caching for WordPress with Ubuntu 20.04 and Nginx
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.