Welcome back to yet another tutorial in the CentOS 7 series! This time I will (again) continue where I left of last time, with the installation of PHP (specifically, PHP-FPM). The last tutorials are a prerequisite for this one, so if you haven’t followed those yet, now is the time to do so.

We’re going to install MySQL to make our server fairly complete, that is for a large number of PHP-based applications (like WordPress, MyBB, or WHMCS). MySQL, however, is no longer the database of choice for Linux distributions. The fact that it was purchased by Oracle was something most people could live with, but when parts of the source code were becoming private they crossed a line.

Thankfully, the original founder of MySQL jumped in and started MariaDB. MariaDB started out as a “fork” of MySQL and has since been adding features. The nice thing is that it’s completely binary compatible, meaning that all the stuff you can do with MySQL you can do with MariaDB, and more! Therefore MariaDB is nowadays the default choice for many Linux distributions. This means it’s also available on CentOS.

With the theory explain, let’s get started!

Preparing your environment

First let’s start by ensuring your system is up-to-date. This will not only update any packages that may have an update pending, but will also update the repository caches ensuring that any packages added meanwhile have been added:

sudo yum update

When is asks you to continue, please type ‘y’ to ensure everything gets updated properly.

With that out of the way there’s actually nothing else to do before we can start with the installation, so let’s move ahead!

Installation

To install MariaDB, run the following command:

sudo yum install mariadb-server

It again asks you if you want to continue. Several other packages have been selected as well as dependencies. This includes ‘mariadb’ which is the client rather than the server. Type ‘y’ again to start the installation.

Once the installation is finished, MariaDB will have been installed but is not yet running. In order to start it, type:

sudo systemctl start mariadb

To ensure it also starts automatically with the server, run the following command:

sudo systemctl enable mariadb

So, now you’ve got MariaDB running but other than connecting to it, you can’t really use it from PHP yet because we haven’t installed the proper package for that. So, in case you want to connect to MariaDB from PHP (big chance that you will), run the following command:

sudo yum install php-mysql

This installs the proper MySQL packages for PHP (including php-pdo, which is for PDO – a database abstraction layer). When done, run:

sudo systemctl restart php-fpm

This ensure that PHP-FPM also gets these recent changes.

Well, that’s it! If you now put an application (say, WordPress) into the directory mentioned in the NGINX tutorial and run the installer, you should be all good!

With the basics now covered, it’s time for the next step: multiple websites per server. The next tutorial will show you how that’s done!

Maarten Kossen was the administrator of LowEndBox from 2013 to 2015, and brought many ideas and improvements to the website during his leadership. Today he is member of our community and LowEndTalk.

8 Comments

MKV:

If one is using a true lowendbox with limited resources (especially memory) it might be a good idea to add a couple of settings to /etc/my.cnf or /etc/my.cnf.d/ to save memory. The least one can do is add

performance_schema=off

under section [mysqld]. Performance schema takes up a HUGE amount of available memory. And I really mean HUGE, up to something like 75% of available memory on a 512MB box as I have seen. Another setting that might be handy if one is using InnoDB tables and does not want to see the ibdata growing and never shrinking is

innodb_file_per_table=1

Using that settings deleting a database will also free most of the space. Otherwise the space is gone. There are other settings as well and it is worth googling for “mysql configuration low memory”.

This one’s absolutely useless. Might as well name the tutorial “Handling services in CentOS 7”. You could pretty much replace “MariaDB” with any other package/service and it would be another “tutorial”.

What about the most basic task after installing MariaDB/MySQL? Securing it. Easiest way is to run “mysql_secure_installation”.

Also, ignore all those LEB-MySQL-optimization etc scripts, most of them set some of the values too low. There’s no need to, for example, set the key_buffer to 512KB or what ever those scripts set it to.

Disabling InnoDB may not always be an option because some applications might need it. I believe Roundcube webmail, for instance neeeds it and I have seen many others. It also has quite a few benefits from an appication programmers point of view. MyISAM is not a very reliable engine, either.

However, when using InnoDB in a low-end box the

innodb_file_per_table=1

setting should definitely be added to the configuration. And one should NEVER EVER have the performance_schema on, always off, like I wrote above. So

performance_schema=off

is the way to go.

Just like you said it is easy to tune the wrong parts and key_buffer is definitely one of them. If one needs to tune such important settings to ridiculously low value one should consider switching to a VPS with a bit higher memory.

Do not use LowEndBox for support issues. Go to your hosting provider and issue a ticket there. Coming here saying "my VPS is down, what do I do?!" will only have your comments removed.

Akismet is used for spam detection. Some comments may be held temporarily for manual approval.

Use <pre>...</pre> to quote the output from your terminal/console, or consider using a pastebin service.

Your email address will not be published. Required fields are marked *

Comment

Name *

Email *

Website

Notify me of followup comments via e-mail. You can also subscribe without commenting.

About LowEndBox

Low End Box is dedicated to helping people run websites and services on low end dedicated servers and virtual private servers, where you only need to pay a few dollars a month to get full root access. Our mission is to help people find cheap vps hosting. [Learn More]

Virtual Private Server (VPS) Hosting FAQ

1. What is a VPS?
"VPS" stands for virtual private server, and effectively means a virtual software instance running within a physical computer server. A virtual private server works like a dedicated physical server but relies on a virtualized software engine often referred to as a "hypervisor" to provide the interface between the physical server and the virtual instance (aka "vps") operating system.

2. Why Do I want a VPS?
By electing to use a "VPS" you are choosing to use a sliver of a physical dedicated server, which generally means lower costs, becuase you are only utilizing a piece of the phsyical capacities of the underlying server. Additionally VPS plans are often portable, providing easy migration from location to location and server to server along with being able to upgrade or downgrade your resources with only a few clicks (rather than having to change out physical server components, etc) as your needs dictate.

4. Where can I learn more?
LowEndBox has published an indepth frequently asked questions article on virtual private servers, why you want a cheap VPS, and lots more. If after reading you have more questions consider checking out our community message board, LowEndTalk, where thousands of users are happy to answer questions.