How To Setup WordPress In CENTOS 6.X

There are many “how to’s” out there for setting up WordPress on your own CentOS server.  I will throw mine into the fray.  When I was researching on how to do this, I had to go through many websites to understand the nuances of WordPress, its dependencies, CentOS and other Linux Distro and how they relate to each other.  From the ashes, I have created what I hope is a comprehensive, secure yet simple set-up that most anyone can understand.  When following along, please be aware of the directory location that I’m working in (blue text).  Also you have to be root (type su, enter, then your root password) for this.  This is based on the LAMP model.  The “L” or Linux is your CentOS and “AMP” (Apache MySQL PHP) is installed at STEP 1.

Here we go…

STEP 1:  Prep your CentOS server for WordPress by installing, MySQL, PHP, PHP-MySQL and Apache

  • [root@linuxbox ~]# yum update
  • [root@linuxbox ~]#  yum install mysql-server httpd php php-mysql

STEP 2:  Have MySQL automatically start up each time your CentOS reboots

  • [root@linuxbox ~]# chkconfig –levels 235 mysqld on

STEP 3: Start MySQL for the first time

  • [root@linuxbox ~]# /etc/init.d/mysqld start

STEP 4: Have httpd (Apache server) start each time your CentOS server reboots.

  • [root@linuxbox ~]# chkconfig –levels 235 httpd on

STEP 5: Start your Apache server for the first time

  • [root@linuxbox ~]# /etc/init.d/httpd start

*Alternatively, following commands will also start and stop MySQL and Apache:
# service mysqld start
# service httpd start

NOW WE ARE GOING TO SECURE MySQL

  • [root@linuxbox ~]# mysql_secure_installation
    In order to log into MySQL to secure it, we’ll need the current
    password for the root user.  If you’ve just installed MySQL, and
    you haven’t set the root password yet, the password will be blank,
    so you should just press enter here.

    Enter current password for root (enter for none):    ←————- Just press “enter” key

    STEP 2:
    Set root password? [Y/n]   ←——————————————–Just press “enter” key for yes

    STEP 3:
    New password:    ←——————————————————Create a  password

    Re-enter new password:    ←——————————————–Re-enter your password

    Password updated successfully!
    Reloading privilege tables..
    … Success!

    STEP 4:
    By default, a MySQL installation has an anonymous user, allowing anyone
    to log into MySQL 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]   ←——————————Press “enter” key for yes
    then following message appears…

    … Success!

    Step 5:

    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]     ←——————————-Press “enter” key for yes.

    STEP 6:

    By default, MySQL 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]   ←————-Press “enter” key for yes.

    … Success!

    STEP 7:

    Reloading the privilege tables will ensure that all changes made so far
    will take effect immediately.

    Reload privilege tables now? [Y/n]     ←—————————Press “enter” key

    /usr/bin/mysql_secure_installation: line 58: .mysql.4122: Read-only file system
    … Success!

    Cleaning up…
    All done!  If you’ve completed all of the above steps, your MySQL
    installation should now be secure.

    Thanks for using MySQL!

    [root@linuxbox ~]#

    Securing of MySQL from hackers has been completed!

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    Now We Are Going To Create WordPress Database In MySQL

STEP: 1   Log in to MySQL by issuing the following command below:

[root@linuxbox ~]# mysql -u root -p

    • Enter password:     ←———————————Enter MySQL password that you created from STEP: 3 (above).
    • STEP 2:
      mysql> CREATE DATABASE wordpress;
    • Query OK, 1 row affected (0.00 sec)
    • STEP 3:
      mysql> CREATE USER billybass@localhost;
    • Query OK, 0 rows affected (0.00 sec)
    • STEP 4:
      mysql> SET PASSWORD FOR billybass@localhost= PASSWORD(“yourpassword”);
    • Query OK, 0 rows affected (0.00 sec)
    • STEP 5:
      mysql> GRANT ALL PRIVILEGES ON wordpress.* TO billybass@localhost IDENTIFIED BY ‘yourpassword’;
    • Query OK, 0 rows affected (0.00 sec)
    • STEP 6:
      mysql> FLUSH PRIVILEGES;
    • Query OK, 0 rows affected (0.00 sec)STEP 7:
      mysql> exit

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Next We Are Going To Download/Install/Configure WordPress 

    • STEP 2:  [root@linuxbox html]# tar -zxvf latest.tar.gz
    • STEP 3:  [root@linuxbox html]# mv wordpress/* /var/www/html
    • STEP 4:  [root@linuxbox html]# cp wp-config-sample.php wp-config.php
    • STEP 5: [root@linuxbox html]# nano wp-config.php 
       
    • STEP 6: Previous command (step 5) opened wp-config.php file for editing.
      Find and edit the following within this file: database name, username and password created from previous step when you created account for MySQL:
      define(‘DB_NAME’, ‘wordpress‘);
      define(‘DB_USER’, ‘billybass‘);
      define(‘DB_PASSWORD’, ‘yourpassword‘);
    • wp-config
    • STEP 7:  With wp-config.php file still open from STEP 6:
      go to, https://api.wordpress.org/secret-key/1.1/salt/ and obtain, “Authentication Unique Keys and Salts” (each time you visit this site, it generates different Keys and Salts.)  Then copy and replace it with existing keys within this wp-config file (towards the bottom).Then save the newly edited, wp-config file.  If you are using nano text editor, save by doing following 3 steps:

      1. hold down ctrl + X key
      2. type letter Y
      3. Then press “enter” key
    • STEP 8:  [root@linuxbox html]# rmdir wordpress/
    • STEP 9:  [root@linuxbox html]# mkdir wp-content/uploads wp-content/cache
    • STEP 10: [root@linuxbox html]# chown -R apache:apache wp-content/uploads wp-content/cache ./
    • STEP 11: Configure wp-content
      From browser, type “localhost” OR server’s IP address and it will load the page like one shown below.
    • Outcome… 1
    • Login 2

3 Comments (+add yours?)

  1. dale
    May 30, 2013 @ 14:20:22

    nevermind, i found the error, in your “html” directory that you were working from, i didnt realize you were in the html folder in the var/www directory. so i had made one at the root level.

    Reply

  2. dale
    May 30, 2013 @ 14:16:47

    high thanks for the how-to, but at: STEP 4: [root@linuxbox html]# cp wp-config-sample.php wp-config.php

    i get the output:

    [root@WEBHOST html]# cp wp-config-sample.php wp-config.php
    cp: cannot stat `wp-config-sample.php’: No such file or directory

    any idea why?

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: