0 Shares 793 Views 1 Comments
00:00:00
21 Jul

Dev: How To Install CentOS, Nginx, MySQL, PHP On VirtualBox From Official RPM

Oliver Krautscheid Jul 18, 2015
0 794 1

In this guide, I want to take a closer look at VirtualBox and how you can quickly set up a CentOS box with LEMP for development purposes and why it can pay off to avoid EPEL at times.

Does EPEL Include Nginx (Engine X)?

EPEL, a community-maintained package, includes a lot of useful tools, including nginx.

However, nginx maintains its own RPM, which is always up to date and can prevent security issues. Therefore, it is recommended to use the nginx RPM on production servers.

Warning: Why Should I Install Nginx Via Their Own Repo and Not EPEL?

Nginx’s repo includes a yum configuration and will automatically update itself every time you run yum update. If you install Nginx via EPEL and not the official repo, you may receive critical security patches too late.

Question: Difference Between Yum And RPM

RPM is the default package manager included in CentOS, short for Red Hat Package Manager.

The biggest disadvantage of RPM is that it is not capable of keeping track of dependencies. Remember all those dependencies yum is checking whenever you install something? Yes, RPM is not doing that, which means you have to resolve dependencies manually at times, which is a time-consuming and annoying task at best. However, some RPM providers will also include a yum configuration file.

Running Windows and CentOS simultaneously

As a webmaster, you will end up leasing servers, VPS’s and your own dedicated machines. In a best-case scenario you buy your own in-house server for development purposes, but you can also use your Windows machine and run CentOS and Windows 7 or 8 simultaneously. Here’s how it works using VirtualBox.

STEP 1: Downloading And Installing VirtualBox Images

You may skip this step if you don’t want a virtual machine.

First we need to grab a CentOS image. There are countless sites that provide pre-compiled VDI files (Virtual Disk Image). Make sure to get the latest version of CentOS, 7 unless you have very specific development requirements.

1. Head over to http://www.osboxes.org/centos/ and grab a copy of the 64bit version for VirtualBox (Personally, I prefer VirtualBox, but VMWare is great too)

2. Open VirtualBox and click New

Adding A New Virtual Machine.png

3. Next, select Other from the dropdown and enter a name for the box, e.g. CentOS:

Adding Centos Machine.png

4. Allocate sufficient memory. 512MB is the minimum requirement and the default setting, there is no limit in CentOS7. I’d suggest you allocate at least 1GB-2GB of RAM if you have like 16GB of RAM. Make sure it’s a multiple of 512 for best performance, e.g. 1024, 2048 and so on.

Allocating Memory To Centos Virtual Machine.png

5. Select “Use an existing virtual hard drive file” and browse to the location where you stored the Cent OS 7 VDI file:

Use An Existing Vdi File To Add Machine.png

6. Click Create and you’re done. Finally, click Start for the initial launch of your machine.

7. You will be asked to log into the account osboxes. The password for the account is osboxes.org:

Centos 7 Osboxes Credentials Password.png

8. VirtualBox should tell you that the OS supports mouse pointer integration, so it will automatically capture the mouse when you hover over the box and click on it.

STEP 2: Installing LEMP On CentOs 7

You may have noticed that osboxes.org also provides a CentOS VDI that already includes LEMP, but for this tutorial I wanted to compile it from official RPM’s.

LEMP stands for Linux, Nginx, MySQL and PHP. So I highly suggest you first take a look at your production servers and compare what versions they are running. If you are running MySQL 5.6 on your production server, then it is a good idea to verify that the RPM will also install this particular version and not 5.7 or a later version once they are available.

Installing Nginx (Engine X) via RPM

1. I have previously explained how to install RPM’s (repositories) on Linux, in short: We are using the command rpm -ivh

Centos 7 Default Applications.png

2. Check nginx.org for the latest stable release . Today, I would execute this command:

sudo rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

Next, check the nginx.repo file:

vi /etc/yum.repos.d/nginx.repo

3. It should include this:

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/OS/OSRELEASE/$basearch/
gpgcheck=0
enabled=1

4. Ok, we just installed the Nginx repo and we verified the basic repo config file exists, all we have to do now is to install nginx using yum:

sudo yum install nginx

5. Confirm with y

6. Make sure to launch the service using the service command

service nginx start

You can then verify it’s running using netstat on port 80:

Starting Nginx Port 80.Png

Installing MySQL via Yum or RPM

The simplest way would be to use the yum package manager, but MySQL also provides their own repo.

yum install mysql mysql-server

Let’s grab the RPM from MySQL.com and proceed.

1. You know the drill, first we need the MySQL repo. Head over to http://dev.mysql.com/downloads/repo/yum/ and get a copy. If you’re on CentOS 7, get a copy of Red Hat Enterprise Linux 7 RPM Package. Red Hat is the commercial CentOS distribution. The latest right now is mysql-community-release-el7-5.noarch.rpm.

2. Run the command we used previously:

sudo rpm -ivh http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm

3. IMPORTANT: If it’s getting stuck at “Retrieving” then go to the download site above and download it manually and open it with the CentOS archive manager (double-click)

In the bundled tar file you will find the MySQL-server-5.6.22-1.el7.x86_64.rpm
Install Mysql Server Rpm.png

4. Let’s verify the content of the mysql-community.repo file in

vi /etc/yum.repos.d/mysql-community.repo

It should look somewhat similar to this:

# Enable to use MySQL 5.6
[mysql56-community]
name=MySQL 5.6 Community Server
baseurl=//repo.mysql.com/yum/mysql-5.6-community/el/5/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

5. Alright, we now have the repo. Make sure to verify it’s all there, check for mysql56-community-source

yum repolist all | grep mysql

6. Finally, we can install MySQL

sudo yum install mysql-community-server

7. mysql-community-libs will replace maridb-libs which CentOS provides by default. It will also resolve all perl dependencies along the way. If you like you can verify the fingerprint.

When you check the transaction log, you will get the warning Warning: RPMDB altered outside of yum., you can find out why this message appears here

8. Now let’s see if MySQL will start:

sudo service mysqld start

(Note the ‘d’ is not a typo, it stands for daemon)

You may get the message “Redirecting to /bin/systemctl start mysqld.service”

9. Verify it’s running:

sudo service mysqld status

Done!

Installing PHP

Last, but not least we are going to install PHP using yum. So far we have installed CentOS on VirtualBox, downloaded Nginx and MySQL RPM’s from their official sources, namely nginx.org and mysql.com, and installed the correct packages to run the services.

Oracle provides a PHP 5.5 RPM for EPEL6 if you are interested, but to make things short we will use yum now:

yum install php php-mysql

There’s also PHP-FPM, a FastCGI implementation, but it does not seem to be maintained so I will not recommend it here.

Conclusion

In this guide, I’ve shown you why sometimes it is a good idea to use official RPM’s rather than rely on EPEL to keep your software updated. Especially nginx receives security patches from time to time. In order to avoid exploits, it is a good idea to use the yum-compatible repositories.

If you found this guide useful, I’d appreciate a share.

About Us

Webmaster .Net is your all-in-one resource for blogging tips, system administration guides, industry news and a growing community of webmasters.

Can't find something or want to tip us?Contact@webmaster.net

Bulls and Bears

One Response

Leave a Comment

Your email address will not be published.

Webmaster Tutorials, Wordpress
0 shares673 views

WordPress SQL Query: Select And Delete Posts Between Two Dates

Oliver Krautscheid - Apr 08, 2017

If you are wondering how to delete posts for a certain date, you will need to know how Wordpress stores…

Advertising and Ad Networks, Copywriting
0 shares810 views

15 Tips For Increasing Facebook Ads CTR – Full Guide [2017 Update]

Cam Connor - Mar 30, 2017

In this article, we'll talk a lot about how you can write quality text ads on Facebook Ads to get…

Webmaster Tutorials
0 shares1530 views

10 Steps To Configure Nginx For WordPress, Drop Varnish And Cut Your CPU Load By 50%

Oliver Krautscheid - Oct 10, 2016

Are you using Varnish on your Wordpress blog? Possibly the Varnish script by Unixy? Great! Get rid off it. Here's…

Follow Us And get latest news

© 2016 Webmaster.Net - Property of Peakstone Media Ltd. - All rights reserved. | Privacy Policy | DMCA | Contact Us | Advertise