The Apache Foundation

How To Set Up Apache Virtual Hosts on CentOS 7

An Apache Virtual Hosts allows multiple websites to run on the same server. If you only have one CentOS 7 server or VPS, this is an efficient way to host multiple sites or domains that are cleanly separated from each other. There is no limit to the number of virtual hosts for the Apache server however you must keep your hardware limitations in mind.

Getting Started

To complete this walkthrough successfully the following are required:
• A node (Dedicated or Cloud Server)running CentOS 7
• All commands must be entered as root
• A complete LAMP implementation

Tutorial – Apache Virtual Hosts

For the purpose of this article, we will set up a virtual host for globo.tech on our instance of Apache.

We will start with disabling SELinux. This will make testing the setup easier and can be re-enabled later with the proper context to handle the new virtual host.
setenforce 0
sed -i 's/enforcing/disabled/' /etc/sysconfig/selinux
sed -i 's/enforcing/disabled/' /etc/selinux/config

Each virtual host must have its own top-level directory under /var/www. Use the mkdir command to create the directory for globo.tech and the public_html subdirectory.
mkdir -p /var/www/globo.tech/public_html/

Since this directory is owned by the root user, we will need to specifically grant access rights to Apache.
chown -R apache. /var/www/
chmod -R 755 /var/www/globo.tech/

Apache will also need to know where to look for additional *.conf files as each virtual host will have one. Open the main configuration file for Apache at /etc/httpd/httpd.conf and add this line at the end.
nano /etc/httpd/conf/httpd.conf
IncludeOptional sites-enabled/*.conf

Now we will create two additional folders enable virtual hosts on the system. One directory will hold all the virtual host files while the other will hold symbolic links for each virtual host published by Apache.
mkdir /etc/httpd/sites-available
mkdir /etc/httpd/sites-enabled

Once that is done we can create the *.conf file for the virtual host. In this case, we will create the globo.tech.conf file in /etc/httpd/site-available directory. Remember that we’ve already instructed Apache to look for additional config files at this location.
cd /etc/httpd/sites-available/
nano globo.tech.conf

<VirtualHost *:80>
ServerAdmin webmaster@globo.tech
ServerName www.globo.tech
ServerAlias globo.tech
DocumentRoot /var/www/globo.tech/public_html
ErrorLog /var/www/globo.tech/error.log
CustomLog /var/www/globo.tech/access.log combined
</Virtualhost>

Then we will need to create the symbolic link for globo.tech in the /etc/httpd/sites-enabled directory.
ln -s /etc/httpd/sites-available/globo.tech.conf /etc/httpd/sites-enabled/globo.tech.conf

After all the above steps have been completed, it is now time to restart Apache. Use this command in order for the server to publish the globo.tech virtual host.
systemctl restart httpd.service

If the instructions have been followed completely, you can place your website files in the root document directory of globo.tech at /var/www/globo.tech/public_html. All you need to do is point your browser to the domain name at the server IP to see your virtual host.

Conclusion

We hope you have enjoyed learning about setting up an Apache virtual host on CentOS 7. You can always experiment further by adding more sites to your server. If you have found this article useful, please consider sharing it.

Cassandra is a reliable, clusterable, highly-scalable database capable of handling large quantities of data on commodity hardware. If you have big data needs, and are looking for a proven open source solution that has received battle testing from many large companies, then Cassandra may be exactly what you’re looking for. If you have a CentOS 7 server, this guide will get you up and running with a single Cassandra node. It will use pre-packaged Cassandra distributions built for CentOS, making installation and upgrades a snap. You can then build it out by performing additional installations on other servers, then clustering the resulting instances for higher scalability and reliability. This article will guide you on how to install Apache Cassandra on CentOS 7 Server.

Getting Started

You’ll need the following in place in order to complete this guide:
• 1 server (Cloud Server or Dedicated Server) with CentOS 7
• Root access

Tutorial

Begin by applying all available patches and security updates to your CentOS 7 server.

yum -y update

Cassandra is written in Java. As such, you’ll need the Java VM installed in order to run it. Do so via Yum.

yum -y install java

Packages for Cassandra are shipped in a Datastax repository. In order to automatically retrieve these packages, and to fetch upgrades in the future, we’ll create this repository so Yum can use it.

nano /etc/yum.repos.d/datastax.repo

[datastax]
name = DataStax Repo for Apache Cassandra
baseurl = http://rpm.datastax.com/community
enabled = 1
gpgcheck = 0

Now Cassandra is ready to be installed.

yum -y install dsc20

With Cassandra installed, we must now start the daemon via systemd.
/etc/init.d/cassandra start

The systemd unit is now created. Use “systemctl start cassandra” to launch the new unit.

systemctl enable cassandra.service

While the database should be running, it is not yet configured to launch on boot. Let’s tell systemd that Cassandra should automatically launch whenever your system boots.

[root@cassandra ~] systemctl status cassandra

cassandra.service - SYSV: Starts and stops Cassandra
Loaded: loaded (/etc/rc.d/init.d/cassandra)
Active: active (exited) since Thu 2016-09-15 04:36:47 UTC; 14s ago
Docs: man:systemd-sysv-generator(8)
Process: 9413 ExecStart=/etc/rc.d/init.d/cassandra start (code=exited, status=0/SUCCESS)

Let’s ensure that Cassandra is running using this command.

[root@cassandra ~] cqlsh

Connected to Test Cluster at localhost:9160.
[cqlsh 4.1.1 | Cassandra 2.0.17 | CQL spec 3.1.1 | Thrift protocol 19.39.0]
Use HELP for help.
cqlsh>

Cassandra ships with a powerful command line utility, cqlsh. Launch it to perform various vital tasks with your database.

[root@cassandra ~] nodetool status

Datacenter: datacenter1
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
-- Address Load Tokens Owns (effective) Host ID Rack
UN 127.0.0.1 46.21 KB 256 100.0% 7dd2b7d9-404e-4a77-a36d-cc8f55168c0d rack1
[root@cassandra ~]#

Likewise, the nodetool command shows the status of your Cassandra node.

Conclusion

You now have a fresh Cassandra instance into which you can load large amounts of data. Share this guide with anyone you may know of who is in search of a big data solution, so they too can enjoy the benefits of an easy Cassandra installation. If you found this article helpful, feel free to share it with your friends and let us know in the comments below!

Swapping is a valuable Linux process that can allow you to essentially add more memory to your Linux instance than it actually possesses by overwriting new new information into a preconfigured swap space. By default, our GloboTech Cloud instances come without swap enabled as swap can slow down the performance of a system. However, depending on your landscape you may still find the ability to artificially increase your memory a useful tool even at the cost of some performance.

Swapping will first and foremost allow you to circumvent a system needing more memory than is physically available. If a running process does not have enough memory, your Linux instance will switch to using the swap space and start swapping out less used RAM (random access memory) chunks known as pages and giving this memory to the process. In any Linux system, a significant number of memory pages that used by applications are in fact only used during their initialization. This means that even when running at full memory capacity, your Linux system will still have the capacity to utilize swap and free the memory from these unused pages.

However, as stated above, swapping does have a downside as it can be a slow process due to its direct reading and writing off of the main hard disk instead of to memory. While memory speeds are measured in nanoseconds, disk speed is instead measured in milliseconds. This means that when using swap, you may find that accessing the disk can be even tens of thousands of times slower than accessing the physical memory, and the more swapping that occurs, the slower your system will become. If you have an instance that a system is constantly swapping memory, and not only for a few particular use cases, then the only true solution will be increasing the RAM. If not, then swap is a reliable choice that can save you trouble in situations of tight memory availability. Without swap on your server, you can run into cases where your instance is simply out of memory and will crash, taking your applications temporarily offline. This makes swap ideal as a back-up plan in the case that your memory is overloaded, so that you can rest in peace knowing your system will be protected from memory-induced crashes.

If you find swap to be a good choice for your Linux-based instance, this guide will show you how you can add swap memory to your GloboTech Linux-based instance. Note that the information in this guide will pertain to the majority of Linux-based distributions such as CentOS, RHEL, Fedora, Ubuntu, and Debian.

Tutorial

Swap memory can be allotted to your instance in one of two ways. The first, more complicated method requires the creation of a new partition to be used for swapping. For this, you will oftentimes have to repartition your disk in order to create the empty partition required and this can create more difficulties for your landscape and can be rather risky.

The second method, creating a swap file, removes this requirement and is the preferred way to add swap memory with as little impact as possible on your existing infrastructure. The swap file acts as a swap partition with the advantage being that you will not need an actual empty partition or need to repartition the disk to use it. The size allotted to the file will determine the amount of swap memory that will be available on your server. This is the easiest method of adding swap memory as it is fail-proof, requires zero risky repartitioning, and can be done in only a few easy steps.

1. Ensure you have enough space

The swap file we create will require filesystem space. You will need to check your available space to make sure that you have enough by using the command:

df -h

The output should show something like the following example, where you can see that we have 8.8GB available on the disk:

Filesystem Size Used Avail Use% Mounted on
udev 491M 0 491M 0% /dev
tmpfs 100M 4.4M 95M 5% /run
/dev/sda1 9.7G 877M 8.8G 9% /
tmpfs 497M 0 497M 0% /dev/shm

2. Allocate the swap file

Having ensured that we have enough space on our system, we will now actually create the swap using the fallocate utility. You can also create your swap file using dd, but the fallocate tool is quicker and simpler to use and is the preferred method. Since our system only has 8.8GB of available disk space, we will create a swap file that is 1GB only. If you have more space on your system, you can create a larger swap file. As the root user, execute the following command replacing the size with your desired size to create a swap file in /swapfile. Use M to indicate Megabytes and G for Gigabytes when giving the size:

fallocate -l 1G /swapfile.swap

If you run into any issues using fallocate, you can always use dd as a fallback. Execute the following as root:

dd if=/dev/zero of=/swapfile.swap bs=1024 count=1048576

3. Set file permissions

With the file created, we will need to set restrictive permissions on it in order to prevent it from accidental alterations by system users, which would break the file.

chmod 600 /swapfile.swap

4. Prepare the swap file

Next, we will use the mkswap utility to configure the created file to be used as swap space. Execute the following command to turn the file into swap:

mkswap /swapfile.swap

5. Mount the swap file

The file is not yet available in your system until you mount it. Activate it using swapon:

swapon /swapfile.swap

To make the changes permanent, we will add the swap file to the fstab file. This will allow the new swap file to be mounted automatically on boot. Open the /etc/fstab file in any text editor such as nano shown below:

nano /etc/fstab

Add the following line to the file:

/swapfile.swap none swap defaults 0 0

6. Prevent system processes from abusing of the swap

Since swap memory is not as able to handle heavy usage as regular RAM without taking performance hits, we can takes steps to ensure that processes won’t abuse the swap space. This will help keep your system from slowing down, and can be accomplished by modifying the swappiness sysctl parameter. This parameter represents the preference/avoidance of the kernel for swap space, and can take any value from 0 to 100 with the default being 60. A lower swappiness value will improve the responsiveness on your system by reducing RAM swapping. Set the swappiness by opening the sysctl file in any text editor (for example, nano):

nano /etc/sysctl.d/99-sysctl.conf

Find the line for the vm.swappiness parameter, and modify it to look like the following with a swappiness value of 10:

vm.swappiness=10

Save and close the file when you are finished.

Conclusion

Congratulations! Having completed all steps in this guide, your Linux instance. Now that all steps are completed, your system has a permanent swap file created which will be auto mounted at every reboot. Enjoy the extra memory!

Ark: Survival Of The Fittest
Ark: Survival of the Fittest is a popular action game that features survival-themed crafting, combat, and most notably, the ability to tame and ride dinosaurs. Ark: Survival of the Fittest is a special game mode with fast-paced rounds in which the last player standing wins.

Ark: Survival of the Fittest must be played using specific servers. This guide will walk you through the steps of setting up this server on CentOS 7.

Getting started

Here’s what you’ll need in order to install the Ark: Survival of the Fittest server:
• 1 server (Cloud Server or Dedicated Server) running a fresh installation of CentOS 7.
• Root access to the server
• For basic support of up to 10 players, 2 vCores and 6GB of RAM or the equivalent will be needed.

Tutorial

The very first step is to update your system. This is also the time to install the basic dependencies.

yum update -y
yum install nano wget tar glibc.i686 libgcc.i686 libstdc++.i686 -y

Create an user specifically to access the Steam related content you’ll need for installation. It’s unsafe to use the root user for this purpose.

adduser -s /usr/sbin/nologin steam

Let’s make some quick preparations to your system before installation. First, for the purposes of the server, you’ll need to increase the amount of simultaneous system files that can be opened by altering sysctl.conf.

echo "fs.file-max=100000" >> /etc/sysctl.conf
sysctl -p

Then, alter the system limits configuration file with the following:

echo "* soft nofile 1000000" >> /etc/security/limits.conf
echo "* hard nofile 1000000" >> /etc/security/limits.conf

Finally, enable the PAM limits module on the system to prepare it for use as a multiuser server.

echo "session required pam_limits.so" >> /etc/pam.d/system-auth

Now you can proceed with the installation of the Ark: Survival Evolved server.

cd /home/steam
/home/steam# su -s /bin/bash steam
wget https://steamcdn-a.akamaihd.net/client/installer/steamcmd_linux.tar.gz
tar -zxvf steamcmd_linux.tar.gz
rm steamcmd_linux.tar.gz
./steamcmd.sh

After entering the Steam command line interface, type this command to install the game server.

login anonymous
force_install_dir ./arkserver
app_update 445400 validate

You will have to wait while the server software downloads. This can take a variable amount of time depending on your connection, but you are done once you see the following.

Update state (0x61) downloading, progress: 99.95 (3222988684 / 3224465090)
Success! App '445400' fully installed.

Now that the server is installed, exit the command line interface with quit.

Switch over to the root user so you can set up the server configuration.

In order for the Ark server to automatically start on boot, you can create an init script. This is what you will name it:

nano /etc/systemd/system/arkserver.service

And now, simply add the following content to the file: (Make sure that the ExecStart line corresponds to what you had in the previous file)

[Unit]
Description=ARK Survival Server
[Service]
Type=simple
User=steam
Group=steam
Restart=on-failure
RestartSec=5
StartLimitInterval=60s
StartLimitBurst=3
ExecStart=/home/steam/arkserver/ShooterGame/Binaries/Linux/ShooterGameServer TheIsland?listen?SessionName=?ServerPassword=?ServerAdminPassword= -server -log
ExecStop=killall -TERM srcds_linux
[Install]
WantedBy=multi-user.target

Now start the Ark server, and enable it to start on boot.

systemctl --system daemon-reload
systemctl start arkserver.service
systemctl enable arkserver.service

Use systemctl to verify that the server is actually running. Here’s the command you should use, and an example of expected output:

service arkserver status

? arkserver.service - ARK Survival Server
Loaded: loaded (/etc/systemd/system/arkserver.service; disabled; vendor preset: disabled)
Active: active (running) since Fri 2016-08-12 23:57:27 UTC; 3s ago
Main PID: 27027 (ShooterGameServ)
CGroup: /system.slice/arkserver.service
??27027 /home/steam/arkserver/ShooterGame/Binaries/Linux/ShooterGameServer TheIsland?listen?SessionName..

Adjust the firewall rules from the default settings. (If you have already altered the firewall in some way, you may need to make further adjustments.) You’ll have to open up these ports to allow traffic to flow to and from the Ark server:

firewall-cmd --add-port=27015/udp
firewall-cmd --add-port=7777/udp
firewall-cmd --add-port=32330/tcp

This is what each port is for:
• UDP 27015: Query port for Steam’s server browser
• UDP 7777: Game client port
• TCP 32330: RCON for remote console server access (optional)

Here’s an equivalent command you can use with iptables, if you prefer:

iptables -A INPUT -p udp -m udp --sport 27015 --dport 1025:65355 -j ACCEPT
iptables -A INPUT -p udp -m udp --sport 7777 --dport 1025:65355 -j ACCEPT
iptables -A INPUT -p tcp -m tcp --sport 32330 --dport 1025:65355 -j ACCEPT

Conclusion

Installation is now complete. If you’ve set it up properly, you should now be able to host games of Ark: Survival of the Fittest for up to 10 players. Add more vCores and RAM to enable even more players to join your server.

The Linux, Apache, MySQL and PHP (LAMP) stack is a versatile application environment. Resource use and configuration is minimal, making it a prime candidate for commodity hosting environments. Deployment is easy, and ranges from making simple in-place edits to full virtualization and containerization. Developers are familiar with LAMP, and it is simple to gain and acquire talent to build and launch LAMP-based applications and sites. This guide will deploy a secure and capable LAMP stack on the CentOS 7 operating system.

Getting Started

Before you begin, make sure you have the following:
• 1 server (Cloud Server or Dedicated Server) running a fresh installation of CentOS 7

At this guide’s conclusion, this server will be capable of hosting one or more LAMP-based sites.

Tutorial

Let’s go. Start by updating all the installed packages on your server. This will apply all current bugfixes and security patches. When complete, reboot so the new server environment is active. Perform this step regularly to keep your system updated and secure.

yum update -y && shutdown -r now

We’ll begin by installing the Apache web server. Apache will both serve up your content and interpret PHP scripts. This is easier to reason about than other solutions, which split PHP execution into separate processes.

yum install httpd

Now we start the Apache server.

systemctl start httpd.service

We must also enable it to start on boot, otherwise it will not launch automatically when the system restarts.

systemctl enable httpd.service

Next we’ll install the database. Instead of MySQL, we’ll use MariaDB. MariaDB is a drop-in MySQL replacement that is backwards-compatible with MySQL and all of its tooling. It includes a number of additional storage engines and scalability features that make it a better fit for large-scale database use.

Start by installing the mariadb package.

yum install mariadb-server mariadb

Again, we’ll start the server itself.

systemctl start mariadb

We now need to set the MySQL root password, which is needed for administering databases and permissions. When asked for your current root password, simply press enter. Keep this password in a secure place, as you’ll need it whenever adding or modifying databases.

mysql_secure_installation

Set root password? [Y/n]
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] y
... Success!
By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!

You can now enable MariaDB to start on boot.

systemctl enable mariadb.service

Next we install the PHP runtime. We’ll begin by installing the base package needed by all PHP scripts.

yum install php php-mysql

With PHP installed, Apache must be restarted so it integrates with the newly-installed runtime.

systemctl restart httpd.service

PHP is an incredibly modular language. Chances are high that you’ll need a number of extensions to deploy or develop PHP apps. Many of these modules are packaged for CentOS. Here we show how to use Yum to find and install the php-gd module. Use this for any modules your PHP site requires.

yum search php-
php-bcmath.x86_64 : A module for PHP applications for using the bcmath library
php-cli.x86_64 : Command-line interface for PHP
php-common.x86_64 : Common files for PHP
php-dba.x86_64 : A database abstraction layer module for PHP applications
php-devel.x86_64 : Files needed for building PHP extensions
php-embedded.x86_64 : PHP library for embedding in applications
php-enchant.x86_64 : Enchant spelling extension for PHP applications
php-fpm.x86_64 : PHP FastCGI Process Manager
php-gd.x86_64 : A module for PHP applications for using the gd graphics library
php-intl.x86_64 : Internationalization extension for PHP applications
php-ldap.x86_64 : A module for PHP applications that use LDAP
php-mbstring.x86_64 : A module for PHP applications which need multi-byte string handling
php-mysql.x86_64 : A module for PHP applications that use MySQL databases
......

yum install php-gd -y

We’re almost done. Let’s test the installation to ensure everything is working.

cd /var/www/html

In CentOS, the document root directory is /var/www/html. All of your PHP scripts must be located here by default in order to be run by Apache.

To test, we’ll create a PHP info file at index.php. This will use a simple function call to display lots of information about your PHP environment. More fundamentally, it will ensure that Apache is executing PHP scripts. The file should be called index.php.

nano index.php

<?php
phpinfo();
?>

To test your environment, access your server at http://your_ip. If that doesn’t work, try http://your_ip/index.php. If all goes well, you’ll see lots of PHP diagnostic details about the environment and loaded modules.

Conclusion

You now have a flexible environment into which you can deploy any number of PHP sites. Simply upload a PHP application, follow its installation instructions, and easily run blogs, wikis or other powerful tools and services. If you found this article helpful, feel free to share it with your friends and let us know in the comments below!

MySQL replication is a technique by which a master database will be automatically copied to one or more slave databases, making data backup, recovery, and analysis a much easier prospect. The following guide will walk you through a basic MySQL replication setup using just two servers, one master and one slave. We’ll also be using MariaDB, a popular drop-in replacement for MySQL.

Getting Started

Before you begin, make sure you have the following:
• 2 servers (Cloud Server or Dedicated Server), both running a fresh installation of CentOS 7
• Root access to both machines

Tutorial

Note: these are the local IP addresses our servers will be using for the purposes of this guide.
• Server Master IP: 10.0.0.179
• Server Slave IP: 10.0.0.180

Before starting, we need to make sure that Selinux is disabled on each of our servers.

setenforce 0
sed -i 's/enforcing/disabled/' /etc/sysconfig/selinux
sed -i 's/enforcing/disabled/' /etc/selinux/config

Let’s also install MariaDB on each server, making sure to secure the installation.

yum install mariadb-server mariadb -y
systemctl start mariadb.service
mysql_secure_installation

Now we can begin the setup, focusing first on the master server. Go to my.cnf on the master server and add these 3 lines:

nano /etc/my.cnf

[mysqld]
...
server_id=1
log-bin
replicate-do-db=globotech

Replace globotech with the name of the database that you want to replicate.

To save the changes, you will have to restart MariaDB.

systemctl restart mariadb.service

Now let’s load up MariaDB itself so that we can better configure the replication.

mysql -u root -p

MariaDB [(none)]> grant replication slave on *.* to 'slave_user'@'%' identified by 'globopassword';
MariaDB [(none)]> flush privileges;

Replace slave_user with the slave username and globopassword with its password.
MariaDB [(none)]> show master status;
+--------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+--------------------+----------+--------------+------------------+
| mariadb-bin.000001 | 475 | | |
+--------------------+----------+--------------+------------------+
1 row in set (0.00 sec)

Make a note of the log file “mariadb-bin.000001” and the log position “475” for later on in the guide.
MariaDB [(none)]> exit

The next step is to configure with the slave server. Like before, open up its my.cnf and add these 2 lines:
[mysqld]
...
server_id=2
replicate-do-db=globotech

Of course, replace globotech with the name of your own database.

Next, restart MariaDB so the changes will be recognized.

systemctl restart mariadb.service

We will now configure the slave to connect to the master.

mysql -u root -p

MariaDB [(none)]> stop slave;
MariaDB [(none)]> change master to master_host='10.0.0.179' , master_user='slave_user' , master_password='globopassword' , master_log_file='mariadb-bin.000001' , master_log_pos=475;
MariaDB [(none)]> start slave;

Replace 10.0.0.179 with the IP address for your master server, and add in the log file and log position that you noted earlier.

We’re almost done. Let’s check the replication status.

MariaDB [(none)]> SHOW SLAVE STATUS\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 10.0.0.179
Master_User: slave_user
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mariadb-bin.000001
Read_Master_Log_Pos: 475
Relay_Log_File: mariadb-relay-bin.000002
Relay_Log_Pos: 531
Relay_Master_Log_File: mariadb-bin.000001
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB: globotech
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 475
Relay_Log_Space: 827
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
1 row in set (0.00 sec)

Finally, let’s test that replication is actually occurring. Log in to the master server and enter MariaDB.

mysql -u root -p

Create the database globotech and insert a table.
MariaDB [(none)]> create database globotech;
MariaDB [(none)]> use globotech;
MariaDB [globotech]> create table staff (c int);
MariaDB [globotech]> insert into staff (c) values (3);
MariaDB [globotech]> select * from staff;
+------+
| c |
+------+
| 3 |
+------+
1 row in set (0.00 sec)

Once logging into the slave server, you should see the same database and table.
mysql -u root -p

MariaDB [(none)]> use globotech;
MariaDB [globotech]> select * from staff;
+------+
| c |
+------+
| 3 |
+------+
1 row in set (0.00 sec)

Conclusion

With MySQL (or in this case, MariaDB) replication, you’ll be able to better protect your databases in the case of failure, and safely analyse data without worrying about corrupting your production copy. If you found this article helpful, feel free to share it with your friends and let us know in the comments below!

Counter-Strike: Global Offensive, also known as “GO” or “CS:GO” for short, is the fourth game in the popular Counter-Strike game series developed by Valve and distributed on its online platform, Steam. Able to run as a console game on Windows, MacOSX, and most recently, Linux, Counter-Strike:GO is a first-person shooter that features brand new maps, characters, and game modes alongside with classic Counter-Strike content. This game is notable for the fact that it allows players to host their own servers, resulting in a high degree of possible gameplay through the ability to introduce individual customization. The high flexibility in gameplay thanks to the personal servers makes Counter-Strike:GO a game that will entertain most people, and can provide a good break from a hard day’s work.

If you are interested in setting up your CentOS 7 server to run Counter-Strike: Global Offensive, this guide will show you the necessary steps.

Getting Started

The following prerequisite is necessary to complete this tutorial:
• 1 Node (Cloud Server or Dedicated Server) running CentOS 7.
• Root access to the node.

In this tutorial, a new user will also be created specifically for running the game. If you want to enable online play, you will additionally need the following (optional):
• Steam Account
• Counter-Strike: Global Offensive Game Ownership

Tutorial

Before we can progress to the actual installation and setup process of Counter-Strike:GO for your server, it is good practice to ensure that you have the latest information from the Linux package repository concerning available packages and package versions. Using the default package manager, yum, we can fetch this information first with the command update, before then upgrading the available packages. Make sure your system is up to date by executing these two commands as root to update the information and then upgrade required packages. If you are not the root user, but your current user has superuser privileges, precede both of the following commands (and all further root commands) with the additional command sudo to execute it as root. You may be prompted for the root password when using sudo.

yum update
yum upgrade

Counter-Strike:GO uses the digital distribution platform Steam, which is also developed by Valve. In order to be able to access Steam as well as complete the rest of the tutorial, you will need to install the following prerequisite libraries and packages using yum, this time with the install command:

yum install glibc.i686 libstdc++.i686 wget nano tar screen

With the prerequisites installed, now it is time to create a new user on our system to handle all Steam-related content. Ensure that you are logged in as root or can use sudo, then execute the following two simple commands. The first command will create the new user, while the second will then set the password. In our tutorial, we will name the user “csgo,” but you are free to replace the text below with whichever name you choose. This also applies to the password, which for the case of simplicity we have kept the same as the username.

adduser csgo
passwd csgo

Installing Steam and Counter-Strike:GO

At this point in the guide, we will switch to the Steam user we just created with the command su. Upon entering this command, you will be prompted for the Steam user’s password. Afterwards, we will navigate to that user’s home directory by using the ~ shortcut:

su csgo
cd ~

As the GO user, you will need to install the SteamCMD software in order to be able to install the Counter-Strike server. This software will allow you to interact with the Steam digital platform in order to download and manage games and applications such as Counter-Strike:Global Offensive. Download the SteamCMD package as an archive using the web utility wget:

wget https://steamcdn-a.akamaihd.net/client/installer/steamcmd_linux.tar.gz

The file downloaded above is a compressed TAR archive that containers the installer for SteamCMD. To be able to access its contents and run the installation script, you will need to unarchive the file using the command tar.

tar xf steamcmd_linux.tar.gz

Next, we will open the Steam command line interface, from which we will be able to install the Counter-Strike:GO server. First, ensure that you are in the correct directory that has the SteamCMD script. This directory should be located at the following location in the csgo home repository:

cd ~/Steam

Open the SteamCMD interface by running the steamcmd.sh bash script from the unarchived package:

./steamcmd.sh

By running steamcmd.sh, you will open the terminal shell for SteamCMD. In this command line interface, you must execute the following commands, which will login to Steam as an anonymous user in order to force install Counter-Strike:GO to the /csgo directory. Note that the 740 in the final line refers to the Counter-Strike:GO application and is its identification code for updates.

login anonymous
force_install_dir ./csgo
app_update 740 validate

The installation process will complete when all the contents are downloaded and the screen will say the following message:

Success! App '740' fully installed

When your installation has completed, you will need to return to the csgo user shell. To exit the SteamCMD interface, type the following and press the Enter key:

quit

Note that for updating your Counter-Strike:GO server, you will need to run the above commands in SteamCMD from open to exit each time you want to update.

As the SteamCMD installer has installed Counter-Strike:GO in the Steam user’s location, we will switch back to the csgo user in order to complete the remainder of the setup for Counter-Strike:GO. As a reminder, you can switch back to the root user at any time by opening a new root user shell or by exiting the current csgo user shell. To open a new root shell when you need it, type the following and give the root password when prompted:

su

Setting Up Remote Play

The current setup without any further configuration will limit players only to local connections, known as LAN. This means that other players on the same network as you will be able to access the server, but it will be inaccessible to other networks. In order to be able to connect to the Internet and play remotely with other users, you will need to obtain something called a “Game Server Login Token,” or GSLT. This token can only be obtained if you have a Steam account and own the Counter-Strike: Global Offensive game. For more information, you can see Valve’s wiki page, which covers what is needed to play online.

We will briefly cover how to register the game server login token, also known as the “GSLT,” if you do in fact have both a Steam account and own the original game. As per the wiki page instructions, you must access the following URL:

http://steamcommunity.com/dev/managegameservers

At the above URL, you will need to login with the Steam account that possesses Counter-Strike:GO. There, you will find a creation utility. Follow the on-screen instructions, using the App ID 730. Note that although the application itself is 740 (as in the case when updating with SteamCMD above), you will need to use the ID 730 for the token registration online. The creation utility will also prompt you to set an optional memo describing your new server. After validating the form, you will be provided with the GSLT and some information concerning the server, such as the last connection made. This page should look similar to the following:

Game
Authentication token (GSLT)
Last connection
Memo
730 *********************************

After you have copied the token, you will need to use the sv_setsteamaccount command in order to enable online play. Replace LOGIN_TOKEN in the line below with your own token value and execute:

sv_setsteamaccount LOGIN_TOKEN

It is important to provide the token information to Counter-Strike:GO before the configuration file for the server, as is detailed further on in this tutorial. The reason is that the server.cfg file used for server configuration is executed too late in the startup process for the GLST to be registered, resulting in your server failing during login.

Configuring the Counter-Strike:GO Server

The Counter-Strike:Global Offensive server configuration file will allow you to make the modifications you want to your server. Open and/or create this file for editing using the nano text editor in the same location as your CS:GO user’s home repository:

nano ~/csgo/csgo/cfg/server.cfg

Within this file, add the following lines, replacing the text ServerName and RconPassword with your desired values for the server. These will be used by individuals in order to access it:

hostname "ServerName"
rcon_password RconPassword

Beyond these two basic settings, you can find far more in the developer wiki for Counter-Strike: Global Offensive. Save and close the file for the changes to take into effect. You can start up your CS:GO server at any time by using the following command:

cd /home/csgo/csgo/
screen -dmS csgo ./srcds_run -game csgo -console -port 27015 +game_type 0 +game_mode 1 +mapgroup mg_bomb +map de_nuke -autoupdate

To make your life easier, you can also easily create a small script that will start up your server for you. Create the following file using the text editor nano:

nano ~/startcsgo.sh

Edit this file to have the following contents. You may need to ensure that the directories correspond correctly to your own file structure.

#!/bin/sh
cd /home/csgo/csgo
screen -S "Counter-Strike: Global Offensive Server" ./srcds_run -game csgo -usercon +game_type 0 +game_mode 1 +mapgroup mg_bomb +map de_dust2

Notice that the command above used the value 1 after game_mode and 0 after game_type. These two options are used to determine the gameplay on your server. You have the following possible combinations to modify the gameplay:

Mode game_mode game_type
Classic Casual 0 0
Classic Competitive 0 1
Arms Race 1 0
Demolition 1 1

When you have configured the file as you want, save and close. To be able to execute this file, you will need to edit its permissions using the command chmod to add the +x for “executable” to the script:

chmod +x ~/startcsgo.sh

Since we created this file, we can now also use it instead of the above command to start the server by running it as the CS:GO user:

cd ~/ && ./startcsgo.sh

On CentOS 7, systemd is responsible for starting up various programs to run on boot. You can use systemd to enable your Counter-Strike:GO server start up at boot. To do this, we will need to create a new service named for CS:GO. As the root user, use nano to open up the following file in the folder for systemd:

nano /lib/systemd/system/csgo.service

Input the following text into the file in order to create the daemon for systemd. Replace the text GSLT_CODE with the actual code of your token. Note again that the game mode and game type have been set. These you are free to modify as you wish according to the instructions following the initial, simple startup script.

[Unit]
Description=My CSGO Server
[Service]
Type=simple
User=steam
Group=steam
Restart=on-failure
RestartSec=5
StartLimitInterval=60s
StartLimitBurst=3
ExecStart=/home/steam/csgo/srcds_run srcdds -game csgo -console -usercon +game_type 0 +game_mode 1 +mapgroup mg_active +map de_dust2 +sv_setsteamaccount GSLT_CODE -net_port_try 1
ExecStop=killall -TERM srcds_linux
[Install]
WantedBy=multi-user.target

Having saved and closed the file, it is necessary to update your CentOS 7 system with the information about the new service we just added. Interact with systemd by using the command systemctl as root:

systemctl --system daemon-reload
systemctl start csgo.service
systemctl enable csgo.service

You can now easily check if the Counter-Strike:GO server is running with one simple call to systemctl to check its status:

systemctl status csgo.service

Configuring Your Firewall

If you have a firewall running on your server, which is likely as it runs by default for fresh server installations, you will also need to open up some ports so that the Counter-Strike:GO server will be able to be accessed. You have two options at this point: choose to remain with firewalld, or switch to iptables configurations. We recommend sticking with firewalld, as it is the default shipped with CentOS 7. However, those who have previously had experience with iptables may prefer it so we have also provided the instructions for how to configure the firewall.

Recommended Firewall Option: firewalld

The following lines of code will add the TCP and UDP ports 27015 to your firewall before reloading the firewall.

firewall-cmd --zone=public --add-port=27015/tcp --permanent
firewall-cmd --zone=public --add-port=27015/udp --permanent
firewall-cmd --reload

The ports we opened in the previous step are required for enabling play in the server. The ways the specific ports are used for Counter-Strike:GO are detailed below:

UDP 27000 to 27015: Game client traffic
UDP 27015 to 27030: Typically Matchmaking and HLTV
UDP 4380: Steamworks P2P Networking and Steam voice chat

Alternate Firewall Option: iptables

If you prefer to use iptables, the classic user application for managing Linux firewalls, instead for modifying the ports, you will have to make some modifications to your system first. This is because in CentOS 7, iptables was replaces by firewalld. If you still want to use iptables, you will have to disable the running firewall and use the package manager yum to install the necessary package and enable it to run on boot:

systemctl stop firewalld
systemctl mask firewalld
yum install iptables-services
systemctl enable iptables

Afterwards, you will be able to use stop,start, and restart to manage the service as shown in the below line:
systemctl [stop|start|restart] iptables

The modification of ports using iptables will take the following form, as seen in this example to open TCP on port 3030:
iptables -I INPUT -p tcp --dport 3030 -j ACCEPT

For each port listed in the instructions for firewalld, you will need to replicate those commands using the syntax shown in the above example for TCP port 3030:
iptables -A INPUT -p udp -m udp --sport 27000:27030 --dport 1025:65355 -j ACCEPT
iptables -A INPUT -p udp -m udp --sport 4380 --dport 1025:65355 -j ACCEPT

You can easily find more information online about how to apply configurations for iptables if you want to learn more about its usage. To save your new iptables configurations when finished, use:
service iptables save

Regardless of whether you choose to remain with firewalld or use iptables, completing this steps will allow connections to be made to your server for remote gameplay.

Conclusion

Congratulations on finishing! Having installed and configured the Counter-Strike:GO server on your CentOS 7 slave, you are now free to enjoy the customizable gaming experience! See just what your server can handle and relax a little from a long work day. If this guide was helpful to you, please share it with others who might also be interested in setting up their own Counter-Strike servers.

Nagios is a very popular server monitoring software application that’s been in development since 1999 and is still regularly updated. The server administrator who uses Nagios gains access to a wide variety of features such as SSH-enabled remote monitoring, network and host traffic monitoring, and a versatile plugin ecosystem. Nagios is free and open source under the GNU General Public License, version 2.

Getting started

Before you begin, make sure you have the following prepared:
• 1 Remote server (Cloud Server or Dedicated Server) running CentOS 7.
• All commands should be run as the root user

Tutorial

The first step is to make sure that Selinux is disabled.

setenforce 0
sed -i 's/enforcing/disabled/' /etc/sysconfig/selinux
sed -i 's/enforcing/disabled/' /etc/selinux/config

Once you’ve done that, you’ll need to install some basic prerequisite packages for Nagios.

yum install gcc glibc glibc-common gd gd-devel net-snmp openssl-devel wget unzip nano -y

Let’s install the Apache webserver and PHP.

yum install httpd php php-cli -y

We’ll be adding a Nagios user to our system, along with nagcmd, so that Nagios and Apache can be integrated together.

useradd nagios
groupadd nagcmd
usermod -a -G nagcmd nagios
usermod -a -G nagcmd apache

Now, we’ll proceed with the installation of Nagios proper. This requires that you download Nagios and the Nagios plugins from the official site.

cd /tmp
wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.2.1.tar.gz
wget https://nagios-plugins.org/download/nagios-plugins-2.1.2.tar.gz

Unzip the Nagios archive you downloaded and use the script inside to install the program.

tar -zxvf nagios-4.2.1.tar.gz
cd nagios-4.2.1/
./configure --with-command-group=nagcmd
make all
make install
make install-init
make install-config
make install-commandmode
make install-webconf

Open the contact file in your favorite text editor and change the enclosed email address to your own.

nano /usr/local/nagios/etc/objects/contacts.cfg

[...]
# This contact definition inherits a lot of default values from the 'generic-contact'
# template which is defined elsewhere.
define contact{
contact_name nagiosadmin ; Short name of user
use generic-contact ; Inherit default values from generic-contact template (defined above)
alias Nagios Admin ; Full name of user
email nagios@localhost ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ****** } [...]

Now, set the password that you'll use to access Nagios.

htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

After that, you can unzip and install the Nagios plugins from the second archive you downloaded.

cd /tmp
tar -zxvf nagios-plugins-2.1.2.tar.gz
cd nagios-plugins-2.1.2/
./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-openssl
make
make install

Just to be safe, check that your config file has no errors.

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

Nagios Core 4.2.1
Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 09-06-2016
License: GPL
Website: https://www.nagios.org
Reading configuration data...
Read main config file okay...
Read object config files okay...
Running pre-flight check on configuration data...
Checking objects...
Checked 8 services.
Checked 1 hosts.
Checked 1 host groups.
Checked 0 service groups.
Checked 1 contacts.
Checked 1 contact groups.
Checked 24 commands.
Checked 5 time periods.
Checked 0 host escalations.
Checked 0 service escalations.
Checking for circular paths...
Checked 1 hosts
Checked 0 service dependencies
Checked 0 host dependencies
Checked 5 timeperiods
Checking global event handlers...
Checking obsessive compulsive processor commands...
Checking misc settings...
Total Warnings: 0
Total Errors: 0
Things look okay - No serious problems were detected during the pre-flight check

The final step is to start up the Nagios and Apache daemons.

service httpd start
service nagios start

In order to access your Nagios interface, you can use the convenient web-based interface. This should be located at this URL:

http://your_ip/nagios/

Here's the login information that you can use the first time:

Login : nagiosadmin
Password : The password you set previously

Feel free to change the login name to something more obfuscated.

Conclusion

Now that you know how to install Nagios on your system, you can use it as a quick and simple, yet full-featured, monitoring tool for any system under your purview. If you found this article helpful, feel free to share it with your friends and let us know in the comments below!

GitLab is a popular Git repository hosting service written in the programming language Ruby that allows for collaborative revision control on coding projects with a cloud-based, streamlined work flow. GitLab is similar to the equally prevalent Git-repository hosting service GitHub, but more developed in its features as a platform that also provides enhanced security and project flexibility. These security features include an increased flexibility when managing permissions, the ability to protect branches, and additional authentication features to allow security when coding at the fine-granular level. Luckily for our purposes, GitLab is provided in two main versions, the Enterprise Edition and the Community Edition, alongside with an additional online platform that allows for a simple introduction to how GitLab operates. While both the main editions pack a punch in features, the Community Edition has the benefit of being free and thus being a good way to explore the benefits of integrating GitLab into your landscape.

This tutorial will show you how you can install GitLab on your CentOS 7 server so that you too can experience its benefits.

Getting Started

Before proceeding with the steps in this guide, make sure you have the following:
• 1 Node (Cloud Server or Dedicated Server) running a clean installation of CentOS 7.
• Root access to the node or superuser permissions.

Please ensure that you also have root access or your user has sudo permissions.

Tutorial

As a matter of good server management, it is important to keep your server updated on the latest packages available for installation. Prior to beginning the installation process of GitLab, we will first ensure that the CentOS 7 server has the latest information about packages using the help of the default package manager yum as root. If you are not the root user but have superuser privileges, append sudo to the front of each command meant to be run as root. Using sudo will allow you to run that particular line as root when needed.

yum update -y

GitLab has two main prerequisite packages that must be installed before GitLab can be obtained and configured for your system. The first package, postfix, is a popular mail transfer service agent, and the second, openssh-server, installs server application for the OpenSSH protocol. Like in this case, multiple packages can be easily installed together in one line by using the yum syntax:

yum install [package1] [package2]

Following this syntax, we will install both prerequisites at the same time. By appending the -y flag to yum install …, you are able to skip the “Yes to continue” prompt during the installation of each package:

yum install postfix openssh-server -y

We will need both Postfix and the OpenSSH server to be running for the rest of the guide. We can turn on the services using the command systemctl, which interacts with the system to manage services (processes) running on it.

systemctl start sshd
systemctl start postfix

You can furthermore ensure that these services are always running on boot by using systemctl with the option enable. This means that you will no longer have to manually enter the start commands to run the services, rather, they will be started automatically for you each time your CentOS 7 boots. Execute the systemctl enable command for both Postfix and the OpenSSH server:

systemctl enable postfix
systemctl enable sshd

Depending on the age of your server, you may also be missing more packages that are needed within this tutorial to install GitLab, but are not technically GitLab prerequisites. These two packages respectively will handle downloads as well as some other basic server policy functions that are useful/required for many other packages.

yum install curl policycoreutils -y

If you have not made any custom configurations to the firewall on your server, the firewall service firewalld will be up and running to protect your server. While the protection is very useful, we will have to add the exceptions for HTTP and HTTPS access to the firewall configuration to proceed:

firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https

Having added the exceptions, reload the firewalld service using the service manager in order for the changes to take into effect:

systemctl reload firewalld

Having configured your firewall, the CentOS 7 server is now ready to install GitLab. First, obtain the repository using the curl package installed above. curl will save the url location to a local file with the same name as specified by the -O flag.

curl -O curl -O https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh

When you have downloaded the package you want, complete the repository installation by executing:

sh script.rpm.sh

Now you are free to actually install the community edition of the GitLab package, named gitlab-ce. This command will install the latest version available in the fetched repository at the time using yum:

yum install gitlab-ce -y

You will know that the installation process is successful when you see the following output on your screen:

gitlab: Thank you for installing GitLab!
gitlab: To configure and start GitLab, RUN THE FOLLOWING COMMAND:
sudo gitlab-ctl reconfigure
gitlab: GitLab should be reachable at...

Just as the prompt suggestions upon completion, now we will configure GitLab to work on your server. Start the configuration process using the gitlab-ctl command:

gitlab-ctl reconfigure

After having run the command, navigate to your GitLab online. This is done easily by opening a browser page to the following URL, replacing the address 10.10.0.35 with your own IP address:

http://10.10.0.35/

When the browser opens the link, you will see the landing page for GitLab. This page includes a brief blurb about GitLab, as well as a prompt to register or sign into GitLab such as the following:

GitLab Community Edition
Open source software to collaborate on code
Existing user? Sign in. New user? Sign up.

As this is the first time accessing GitLab, you will need to set a new password and username for the GitLab root user by registering those credentials. You will need to use this root username and password each time to access GitLab, so be sure to memorize them or keep them in a safe place.

Upon successful login, you will see the GitLab index page, which will portray all projects you have currently linked.

Conclusion

With the easy and quick setup for GitLab, you are now ready to start exploring! Check out the GitLab website for more information about what GitLab can do, and be sure to share this guide with your friends if you enjoyed it.

Moodle is a software platform built for dynamic content management that is geared towards educational usage, such as in creating e-learning portals for schools, universities, and workplaces. Moodle supports a high range of content that it can manage as well as an extensive range of community plugins that make it an easily-tailored solution to many educational challenges and in a variety of environments. Moodle can be run from a Linux web server that provides the basic stack for web applications, and can simplify planning and management for educators and non-educators alike.

In this tutorial, we will show you how you can install Moodle for yourself on a CentOS 7 server.

Getting Started

In order to perform this tutorial, you will need the following:
• 1 Node (Cloud Server or Dedicated Server) running a clean installation of CentOS 7.
• All commands must be entered as root

Please ensure that you have the proper access to root and are able to log in as the user or execute the sudo command. If your server does not yet have the LAMP platform, which refers to the specific stack of running Apache, MySQL, and PHP on Linux for web applications, we will cover how to install the necessary tools in the first part of the guide.

One last thing to note before getting started is the IP address and hostname we will be using for our server in this tutorial. Whenever you see references to these, please replace them with your own settings where appropriate. The tutorial hostname will be my.server.com, with an IP address of 10.10.0.35.

Tutorial

Before beginning the Moodle installation, it is recommended to update your server with information concerning the latest available packages and package versions. You can retrieve this information with the default package manager yum for CentOS 7. As the root user, run the below command in order to update your package repository information:

yum -y update

If you have SELinux running on your server for security, you will also need to disable it for the purposes of this guide. To do so, open the configuration file for SELinux in the text editor nano:

nano /etc/sysconfig/selinux

This file will have a line that looks like SELINUX=. This parameter can have one of three values: enforcing, permissive, or disabled. If this line says enforcing, as in SELINUX=enforcing, then you will need to change the value to either permissive or disabled.

After editing the configuration file, save and close. You must reboot your system for the new changes to take into effect:

reboot

You can verify the new status of SELinux by running the sestatus command. The output of this command should look as either of the two following lines:

SELinux status: disabled
SELinux status: permissive

Installing the LAMP Platform

As mentioned above, the LAMP platform refers to a specific setup of the Apache web server, MySQL database, and PHP running together on Linux. This setup is used when running web applications on your server as, when run in conjunction, provide the minimum support functionality necessary to run applications such as Moodle.

The EPEL repository is an additional package repository that is not included by default in your server installation. In this guide, we will be using some packages from this repository, and therefore, we must first add it to the server in order to be able to use it. Configure your CentOS 7 machine to use this additional package repository with the following two commands, which uses the package manager yum:

yum -y install epel-release

After adding the EPEL repository, we can start to install the basic packages needed for Moodle to run. The first package, httpd, will install the Apache web server. This is the world’s most popular software for hosting web services of any sort on your own machine. Install the Apache package using yum:

yum -y install httpd

You can start the Apache web server and enable it to start automatically on boot with these two quick commands:

systemctl start httpd
systemctl enable httpd

The next package required, the MySQL database, takes a little more work to install than Apache. First, you must add the necessary MySQL package repository for yum much like we added the EPEL repository. Since yum uses the package manager rpm, and what we want to do is add a new repository for yum, we can add it using rpm as such:

rpm -Uvh http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

Now, we can simply use the yum install command again to install MySQL:

yum install -y mysql-server

While installing MySQL, the system will prompt you to provide a password for the MySQL root user. We recommend to set the password here to avoid having to manually create it further on, and you will need this password for later in the tutorial.

To start MySQL and enable it to startup on server boot, we now use the same two commands we used to start Apache for the mysqld service:

systemctl start mysqld
systemctl enable mysqld

Finally, to round out the LAMP stack, you will need to have PHP, which comes in the php package. It is this that enables your website to have dynamic content such as Moodle. Moodle furthermore will require a few more PHP-related extensions that are also installed with the main PHP installation using these commands. Note that we split the installation into several commands in order to make it easier to see what packages are required, but you can also execute their installation in one long command of the form yum -y install [package_1] [package_2] […] [package_n], keeping a single space as the separator between packages.

yum -y install php php-mysql php-xml php-xmlrpc php-soap php-pgsql php-gd php-iconv php-mbstring php-curl php-openssl php-tokenizer php-ldap php-pecl-apc php-ctype php-zip php-simplexml php-spl php-pcre php-dom php-xml php-intl php-json

To start using PHP on your web server, you will have to then restart Apache. Using the systemctl command, we can restart the service:

systemctl restart httpd

Due to the heavy reliance of Moodle on PHP for processing dynamic content, website performance can be negatively affected. However, a slow web server is oftentimes something that we precisely try to avoid. Luckily, there is a solution called PHP Zend OpCache that speeds up PHP execution by removing compilation and instead directly executing PHP code on the server. To install Zen OpCache on your server, get the package using yum:

yum -y install php-pecl-zendopcache

One benefit of Zen OpCache is how customizable it can be. You can configure it for your unique situation via its configuration file in /etc/php.d/opcache.ini.

After installing Zen OpCache, you must again reload the web server for the changes to take into effect:

systemctl restart httpd

Configuring MySQL

Moodle requires some tweaking of your MySQL configuration before it can be used. The changes you will have to make depend on the Moodle version you want to use, and you can find information concerning these changes in the documentation for your desired Moodle version. In this guide, we will install a stable version 3 Moodle release. For our example, we will have to modify the /etc/mysql/my.cnf configuration file for MySQL to change information concerning the default storage engine, file format, and file per table. We will do this by opening the configuration file in the vi text editor:

vi /etc/mysql/my.cnf

In this file, you will need to find the [mysqld] section, and locate Basic Settings. Here, insert the following lines after the last statement of this section:

default_storage_engine = innodb
innodb_file_per_table = 1
innodb_file_format = Barracuda

For the changes we just made to take into effect, we must now restart MySQL using this command:

systemctl restart mysql

With the MySQL database software installed on your CentOS 7 server, you are now able to create the database for Moodle to specifically use. Open up the MySQL prompt, which uses the language SQL (Structured Query Language) meant for database interactions. Replace the text PASSWORD in the line below and run:

mysql -u root -p PASSWORD

If the prompt now reads mysql>, you are now in the SQL terminal. From here, you can execute all sorts of commands that allow you to interact with MySQL. First, create the actual database for Moodle to store its data in with this command, which sets the database name to “moodle.” If you would like to use a different name, replace moodle in the line below to a name of your choice.

CREATE DATABASE moodle DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;

With the database created, you will also need to setup the username and password of the Moodle user. In the command below, replace USERNAME and PASSWORD with the respective Moodle user username and password in order to create the user:

create user 'USERNAME'@'localhost' IDENTIFIED BY 'PASSWORD';

While the user has been created, they do not yet have any permissions to interact with the Moodle database. Give the user read and write permissions by executing the following SQL statement, replacing the USERNAME and PASSWORD fields as necessary:

GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,CREATE TEMPORARY TABLES,DROP,INDEX,ALTER ON moodle.* TO USERNAME@localhost IDENTIFIED BY 'PASSWORD';

If you have an error occur during user setup that states that you must use a hash value password (as will happen if using MySQL 5.6+), you can solve it by generating the hash and using that value instead of the password in the above commands. Obtain the hash by entering this in the SQL prompt (replacing PASSWORD with your password):

SELECT password('PASSWORD');

The above command will produce output that looks similar to this string, *AD51BAFB2GD003D3480BCED0DH81AB0BG1712535, and represents the hash value of the password. Replace your password with this hash in all sections that begin with IDENTIFIED BY ‘ in the failing code lines.

After creating the database and database user, exit the SQL prompt:

quit;

Restart MySQL again for the new changes to be verified:

service mysql restart

Installing Moodle

There are two possibilities for how to obtain Moodle on your CentOS 7 server. You can either clone the official Git repository (Git is a distributed version control system) for Moodle and then check out to a specific version branch (basically a code version), or you can get the code base for a specific version as a zip file. Both methods are fairly straight forward, but the Git method can be easier to maintain long term for keeping your Moodle setup up to date.

Installing with Git

If you choose to install Moodle via Git, thereby meaning that your local installation will be linked to the remote Moodle repository, then you will need the Git package. Install it with:

yum -y install git

To host the Moodle repository, we will create a new directory under /opt by cloning the remote repository. Cloning means that using Git, we will make an exact copy of the Moodle code base, with all versions available, in our local directory.

cd /opt
git clone git://git.moodle.org/moodle.git

Check that the directory for Moodle, /opt/moodle exists in the current directory by looking at the output of the ls command, which lists files and repositories in the current folder:

ls

Switch to the repository:

cd moodle

Here is the point at which you choose which Moodle version you want to use. The information for each version is stored inside the Git repository, with each “branch” representing a unique version. Find online the name of the branch you would like to use or use this command to list all branches available:

git branch -a

Once you have decided upon a branch, you can setup a local branch in your repository that will follow the remote version. Here, the branch we chose is MOODLE_30_STABLE for a stable Moodle version 3, but you should replace this with your own version.

git branch --track MOODLE_30_STABLE origin/MOODLE_30_STABLE

After setting up the branch for tracking, you are not currently using that version yet. To actually switch the code base in the Moodle repository to the corresponding version of the Moodle code, use the following (remembering to replace MOODLE_30_STABLE with your desired version):

git checkout MOODLE_30_STABLE

Installing from Zip File

If you instead choose to install Moodle from a zip file, you will require the download utility wget. Install this utility with:

yum -y install wget

Next, change directory to /opt just like you would if installing with Git. Find the Moodle version you would like to use here and replace stable31/moodle-3.1.2.zip in the line below to download the corresponding zip file:

wget https://download.moodle.org/download.php/stable31/moodle-3.1.2.zip

The file we just downloaded is compressed. To uncompress it and make its contents usable, use unzip the file into the new directory moodle:

unzip moodle-3.1.2.zip -d moodle

At this point, you have your desired Moodle version in either a regular or Git repository under /opt/moodle. However, for Moodle to work on your server, you must also have Moodle in the webroot. This webroot is, by default, located in /var/www and is the root point of your website. By choosing to have the main repository for Moodle outside the webroot, you are able to have more control over planned updates to the Moodle version you are using and for how you migrate versions. Copy the Moodle repository into the webroot as a normal, non-Git repository, using:

cp -R /opt/moodle /var/www/html/

Next, you must create an additional directory for Moodle to use to store its data, such as files, session information, and so on. This data directory must also be created in the webroot as such:

mkdir /var/www/html/moodledata

These repositories we created under the webroot will need to have their ownership and permissions modified for the Apache user to be able to access them. You can change the respective directory ownership and permissions with the commands chown and chmod:

chown -R apache.apache /var/moodledata
chmod -R 777 /var/moodledata
chmod -R 0755 /var/www/html/moodle
chown -R apache.apache /var/www/html/moodle

For the changes we just made to be implemented, the Apache web server must be restarted:

systemctl restart httpd

Setting Up Moodle Online

The remainder of the Moodle installation process will be done online. First, we will make the webroot temporarily writable so that this online setup can create a new configuration file config.php after completion. You can modify these permissions again with the chmod command:

chmod -R 777 /var/www/html/moodle

Next, open up your browser to the Moodle home page. Make sure to replace the tutorial IP address with your own. Go to:

http://10.10.0.35/moodle

On this page, follow the instructions to fully complete the Moodle setup. You will have to make changes that include the following:
1. Setting the language
2. Entering the data directory (moodledata) path, in our case it is /var/www/moodledata/
3. Choosing a database driver, Improved MySQL (native/mysqli) for our tutorial
4. Configuring the database settings
5. Setting mdl_ as the prefix for tables

The online installation will also helpfully provide an environment check to notify you if any of the required components to run Moodle are not installed, or not correctly installed, on your system. Go through all the prompts until the installation is complete.

It is vital to now change the permissions in the Moodle directory back again so it is not writable after completing the installation:

chmod -R 0755 /var/www/html/moodle

Conclusion

After you have completed the online setup, that’s it! You now have the learning-oriented content management platform Moodle installed and running on your CentOS 7 server. If this guide was helpful to you, kindly share it with others who may also be interested.