Sunteți pe pagina 1din 12

Community Menu

By: Josh Barnett Subscribe

How To Install WordPress on CentOS 7


Posted October 30, 2014 146.6k WORDPRESS CENTOS 19

Introduction
WordPress is a free and open source website and blogging tool that uses PHP and MySQL. WordPress is currently the most
popular CMS (Content Management System) on the Internet, and has over 20,000 plugins to extend its functionality. This makes
WordPress a great choice for getting a website up and running quickly and easily.

In this guide, we will demonstrate how to get a WordPress instance set up with an Apache web server on CentOS 7.

Prerequisites
Before you begin with this guide, there are a few steps that need to be completed first.

You will need a CentOS 7 server installed and configured with a non-root user that has sudo privileges. If you haven't done this
yet, you can run through steps 1-4 in the CentOS 7 initial server setup guide to create this account.

Additionally, you'll need to have a LAMP (Linux, Apache, MySQL, and PHP) stack installed on your CentOS 7 server. If you don't
have these components already installed or configured, you can use this guide to learn how to install LAMP on CentOS 7.

When you are finished with these steps, you can continue with the installation of WordPress.

Step One Create a MySQL Database and User for WordPress


The first step that we will take is in preparation. WordPress uses a relational database to manage information for the site and its
users. We have MariaDB (a fork of MySQL) installed already, which can provide this functionality, but we need to make a
database and a user for WordPress to work with.

To get started, log into MySQL's root (administrative) account by issuing this command:

mysql -u root -p

You will be prompted for the password that you set for the root account when you installed MySQL. Once that password is
submitted, you will be given a MySQL command prompt.

First, we'll create a new database that WordPress can control. You can call this whatever you would like, but I will be calling it
wordpress for this example.

CREATE DATABASE wordpress;

Note: Every MySQL statement or command must end in a semi-colon ( ; ), so check to make sure that this is present if you are
running into any issues.

Next, we are going to create a new MySQL user account that we will use exclusively to operate on WordPress's new database.
Creating one-function databases and accounts is a good idea, as it allows for better control of permissions and other security
needs.

I am going to call the new account wordpressuser and will assign it a password of password . You should definitely use a
different username and password, as these examples are not very secure.

CREATE USER wordpressuser@localhost IDENTIFIED BY 'password';

At this point, you have a database and user account that are each specifically made for WordPress. However, the user has no
access to the database. We need to link the two components together by granting our user access to the database.

GRANT ALL PRIVILEGES ON wordpress.* TO wordpressuser@localhost IDENTIFIED BY 'password';

Now that the user has access to the database, we need to flush the privileges so that MySQL knows about the recent privilege
changes that we've made:

FLUSH PRIVILEGES;

Once these commands have all been executed, we can exit out of the MySQL command prompt by typing:

exit

You should now be back to your regular SSH command prompt.

Step Two Install WordPress


Before we download WordPress, there is one PHP module that we need to install to ensure that it works properly. Without this
module, WordPress will not be able to resize images to create thumbnails. We can get that package directly from CentOS's
default repositories using yum :

sudo yum install php-gd

Now we need to restart Apache so that it recognizes the new module:

sudo service httpd restart

We are now ready to download and install WordPress from the project's website. Luckily, the WordPress team always links the
most recent stable version of their software to the same URL, so we can get the most up-to-date version of WordPress by typing
this:

cd ~
wget http://wordpress.org/latest.tar.gz

This will download a compressed archive file that contains all of the WordPress files that we need. We can extract the archived
files to rebuild the WordPress directory with tar :

tar xzvf latest.tar.gz

You will now have a directory called wordpress in your home directory. We can finish the installation by transferring the
You will now have a directory called wordpress in your home directory. We can finish the installation by transferring the
unpacked files to Apache's document root, where it can be served to visitors of our website. We can transfer our WordPress
files there with rsync , which will preserve the files' default permissions:

sudo rsync -avP ~/wordpress/ /var/www/html/

rysnc will safely copy all of the contents from the directory you unpacked to the document root at /var/www/html/ . However,
we still need to add a folder for WordPress to store uploaded files. We can do that with the mkdir command:

mkdir /var/www/html/wp-content/uploads

Now we need to assign the correct ownership and permissions to our WordPress files and folders. This will increase security
while still allowing WordPress to function as intended. To do this, we'll use chown to grant ownership to Apache's user and
group:

sudo chown -R apache:apache /var/www/html/*

With this change, the web server will be able to create and modify WordPress files, and will also allow us to upload content to
the server.

Step Three Configure WordPress


Most of the configuration required to use WordPress will be completed through a web interface later on. However, we need to
do some work from the command line to ensure that WordPress can connect to the MySQL database that we created for it.

Begin by moving into the Apache root directory where you installed WordPress:

cd /var/www/html

The main configuration file that WordPress relies on is called wp-config.php . A sample configuration file that mostly matches
the settings we need is included by default. All we have to do is copy it to the default configuration file location, so that
WordPress can recognize and use the file:

cp wp-config-sample.php wp-config.php

Now that we have a configuration file to work with, let's open it in a text editor:

nano wp-config.php

The only modifications we need to make to this file are to the parameters that hold our database information. We will need to
find the section titled MySQL settings and change the DB_NAME , DB_USER , and DB_PASSWORD variables in order for
WordPress to correctly connect and authenticate to the database that we created.

Fill in the values of these parameters with the information for the database that you created. It should look like this:

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'wordpress');

/** MySQL database username */


/** MySQL database username */
define('DB_USER', 'wordpressuser');

/** MySQL database password */


define('DB_PASSWORD', 'password');

These are the only values that you need to change, so save and close the file when you are finished.

Step Four Complete Installation Through the Web Interface


Now that you have your files in place and your software is configured, you can complete the WordPress installation through the
web interface. In your web browser, navigate to your server's domain name or public IP address:

http://server_domain_name_or_IP

First, you will need to select the language that you would like to install WordPress with. After selecting a language and clicking
on Continue, you will be presented with the WordPress initial configuration page, where you will create an initial administrator
account:
Fill out the information for the site and administrative account that you wish to make. When you are finished, click on the Install
WordPress button at the bottom to continue.

WordPress will confirm the installation, and then ask you to log in with the account that you just created:

To continue, hit the Log in button at the bottom, then fill out your administrator account information:

After hitting Log in, you will be presented with your new WordPress dashboard:
Conclusion
You should now have a WordPress instance up and running on your CentOS 7 server. There are many avenues you can take
from here. We've listed some common options below:

Set Up Multiple WordPress Sites Using Multisite

Use WPScan to Test for Vulnerable Plugins and Themes

Manage WordPress from the Command Line

By: Josh Barnett Upvote (19) Subscribe

Whats the (big) deal with big data?


Get an introduction to big data
frameworks like Hadoop, Storm, Samza,
Spark, and Flink in the
Big Data Frameworks Compared
tutorial guide.

Related Tutorials
How To Set Up Multiple WordPress Sites Using Multisite

How To Install WordPress with LEMP on Ubuntu 16.04

How To Install WordPress with LAMP on Ubuntu 16.04


How To Protect WordPress from XML-RPC Attacks on Ubuntu 14.04

How To Install Wordpress and PhpMyAdmin with Docker Compose on Ubuntu 14.04

34 Comments
Log In to Comment

manjumcp November 4, 2014

0 Hi,

I followed this document and completed the steps but not able to see the gui console in my browser.
I could see the below info in my browser.
I would request you to hep me on this.
Thanks in advance..

<?php
/**
* Front to the WordPress application. This file doesn't do anything, but loads
* wp-blog-header.php which does and tells WordPress to load the theme.
*
* @package WordPress
*/

/**
* Tells WordPress to load the WordPress theme and output it.
*
* @var bool
*/
define('WP_USE_THEMES', true);

/** Loads the WordPress Environment and Template */


require( dirname( __FILE__ ) . '/wp-blog-header.php' );

jbarnett November 4, 2014

0 I'm having a tough time replicating the issue that you're describing. Would you mind sharing the contents of your
/var/log/httpd/error_log in a Pastebin?

aslanov November 6, 2014

1 thank you very much dear friends! It's very helpfull!

MiteshGanatra November 9, 2014

0 Great article, very helpful, thanks a bunch:)


fmbetancourt November 11, 2014

0 Thanks so much for this super-helpful article! I was just bumming out about how to incorporate git into my WordPress workflow;
this totally solves the problem. Everything worked like a charm.

One question: I was unable to clone a WordPress repo that I have hosted on BitBucket. The error message said something about
the public key, yet I have the same public key in BitBucket as in GitHub, and cloning from the latter worked fine. Is there some
inherent problem with Digital Ocean and BitBucket playing nicely, by any chance?

jbarnett November 12, 2014

0 I haven't heard of issues with DigitalOcean playing nicely with BitBucket. I would try asking in our Questions section.

info301725 November 15, 2014

0 mod_rewrite dose not work??????

RinkuY January 3, 2015

0 Find "AllowOverride None" in /etc/httpd/conf/httpd.conf near line 125

and replace with

AllowOverride All

ThomasTom December 6, 2015

0 No, keep it at "AllowOverride None" and just put the wordpress .htaccess information into the main apache configuration
file. .htaccess is only meant to be used when you don't have access to the main apache configuration file.

http://haydenjames.io/disable-htaccess-wordpress-performance/

info301725 November 17, 2014

0 this is a b.s tutorial, if you are going to write a tutorial on How To Install WordPress on CentOS 7, make sure you write all the
essential steps

asb MOD November 17, 2014

0 Hey! If you explained the problem you were running into we might be able to help.

info301725 November 22, 2014

0 Apache Module mod_rewrite, Permalinks don't work. WordPress cannot write to .htaccess file

RinkuY January 3, 2015

0 Find "AllowOverride None" in /etc/httpd/conf/httpd.conf near line 125

and replace with

AllowOverride All
sputnik January 17, 2015

0 I had the same problem, but changing only this line I can not solve the problem. I suggest to read this article
[https://www.howtoforge.com/how-to-install-wordpress-on-centos-7](http://)

ThomasTom December 6, 2015

0 I don't think that's the ideal solution when you have access to the main apache configuration file. .htaccess is meant for
situations such as shared hosting where you don't have access.

You should place the content from the wordpress .htaccess file into the main apache configuration file for performance
reasons and you should leave the default "AllowOverride None".

http://haydenjames.io/disable-htaccess-wordpress-performance/

info301725 November 22, 2014

0 the other problem is I can't upgrade wordpress, its asking for FTPS credentials, any idea how to enable ftp?

info301725 November 22, 2014

0 did you even bother to touch up on postfix so i can receive email messages??

dribblecastle December 22, 2014

0 Great article, thanks for posting. Also, like your site design.

RinkuY January 3, 2015

0 enable mod_rewrite :

Find "AllowOverride None" in /etc/httpd/conf/httpd.conf near line 125

and replace with

AllowOverride All

ThomasTom December 6, 2015

0 No, you should leave "AllowOverride None" alone and just add the content in the Wordpress .htaccess file into the main apache
configuration file:

http://haydenjames.io/disable-htaccess-wordpress-performance/

RinkuY January 3, 2015

0 Here i found many mistakes in this tut.

WP create his self these files : wp-config.php, uploads, .htaccess etc.

And I can not find, How to enable .htaccess working in config file.

Need to update this tut.


Crater February 10, 2015

0 To those of you who are having issues with mod_rewrite:

RinkuY suggested to change line 125 however you may notice this will not allow you to create permalinks. Instead, make the
change to line 151 which will take effect for /var/www/html as opposed to /vat/www.

Make sure you restart apache after doing so. Let's go over it one more time:

**Find "AllowOverride None" in /etc/httpd/conf/httpd.conf near line 151

and replace it with

AllowOverride All**

I hope this helps some of you.

ThomasTom December 6, 2015

0 No, you should not turn on "AllowOverride All". You should leave set to "AllowOverride None" and just copy the information in
the WordPress .htaccess file to the main apache configuration file:

http://haydenjames.io/disable-htaccess-wordpress-performance/

CertDepot March 5, 2015

1 If you've got SELinux enable and are not a SELinux expert, apply this command:

setsebool -P httpd_unified 1
This command should solve some of the problems displayed in the previous comments.

fahadsnafee May 7, 2016

0 Mate! you saved me! thank you

edeichman May 12, 2015

0 I'm not a Linux security expert, but making Apache the owner of the WordPress directory looks like a security risk.

jbreawpb May 22, 2015

0 TENGO UN PROBLEMON
1-QUIERO DARTE LAS GRASIAS POR LOS COMANDOS Y POR EL TOTORIAL PERO MI PREGUTA ES ESTA ,

2- YO LO INALE TODO LO CONFIGURE TODO PERO CUANDO BOY A PONER EN LA WEB EL NOMBRE ME SALE LA
PAGINA DONDE YO COMPRE EL DOMINIO ME PODRIAS ALLUDAR CON ESO
I HAVE A big problem
1-I want to thank BY COMMANDS AND THE totorial BUT THIS IS MY preguta,
2- I WILL SET ALL INALE EVERYTHING BUT WHEN BOY TO PUT NAME ON THE WEB PAGE ME OUT WHERE I COULD BUY
DOMAIN ME WITH THAT tonics

alvanet August 3, 2015

0 I have AWS server on CentOS 7 and all worked great from command line. The only thing I had to do to see the page, was too use
"setenenforce 0" this disables SElinux till a reboot or enable it again and then i could install the files.

Thanks!
satadru August 19, 2015

0 After installing the wordpress, it still showing the default Apache Page. I have cleared cookies and opened a new browser session,
still not solved

lolnoobhax October 17, 2015

0 Been using your guides (firewalld, wordpress and openSSL) for our task for school...

We have to setup a LAMP-stack with wordpress, of course by using batch scripts so it has been some improvising and stuffs.
Anyway, it's bugging me less people are having it done with "yum install wordpress"... For our task we have to do it with yum (big
bummer, because I had everything up and running perfectly with wget & tarring, so now I had to rewrite my script and do it the
other way around)

Anyway... So doing it with yum, i'm now at the finishing stage (wordpress is pretty much the ending) but I keep getting "Forbidden"
page... the apache page is up and working, but we also need to access the page from http://virtual-machine.ip/wordpress ...

I'm aware that, when you install wordpress through yum, wordpress will be installed to /usr/share/wordpress, and has its own
config file for httpd/Apache where it has an "Alias /wordpress /usr/share/wordpress" So I think it should just work like this? (You go
to http://vm.ip/wordpress and it aliases through to /usr/share/wordpress, its an alias afterall)

Anyway, this makes it hard for me to know what is causing this... Theres also (on the guides where they do it with wget/tar) all
different rights people give up for their wordpress folder, even though I wonder how it can be safe if you 755 that folder while it has
A config file with mysql-password in it... (with Yum it uses some "red"-file that forwards to another one, but thats not my point right
now) And even trying that on the /usr/share/wordpress folder does not change the Forbidden error...

I've been busy with this obstacke since last night and have not yet found the solution, hoping someone could be my hero of the
week.. I guess my teacher is currently getting wasted, wich is understandable due to the weekend ;)

The only thing after this that I need to find the google therms for is how to open a web browser with the page on it with the shell
script (well, I don't even know what I google for this matter) but that's for later ^^

lolnoobhax October 17, 2015

0 You can just ignore this, the problem was in the wordpress.conf afterall.. But still why no yum-guide? ;)

Load More Comments

This work is licensed under a Creative


Commons Attribution-NonCommercial-
ShareAlike 4.0 International License.


Copyright 2017 DigitalOcean Inc.

Community Tutorials Questions Projects Tags Newsletter RSS


Distros & One-Click Apps Terms, Privacy, & Copyright Security Report a Bug Get Paid to Write Shop

S-ar putea să vă placă și