How To Install WordPress On Apache-based CentOS Server
| |Download and Install WordPress on VPS or Dedicated CentOS server running Apache. So you have installed and setup necessary “things” to build a CentOS server to host your websites in it. And what I mean with the “things” here are: Apache, MySQL server and of course PHP5. Why you gonna need this guide? If you are familiar enough with cPanel, its File Manager feature and especially its one-click script installer, the way you gonna deal in an unmanaged server is pretty much different. Unlike in cPanel which you can do every thing via your browser, this method will be done via bash command using your favorite SSH client which for me I use Putty. The process is basically painless but for some newbies this could be new stuff to learn. Read and follow the whole steps but do not hesitate to drop a comment asking the part you don’t understand. I’ll be happy to answer it (if I can).
Prerequisite
- A working CentOS server. In this guide I am using CentOS 6.3 x32 (see my playground server)
- Windows users should download Putty while Mac and Linux users can simply use Terminal
- You’ll also need a basic skill to use Putty and to navigate through SSH. Read: Most common Unix commands used to SSH.
- Your server should already has necessary software to host a website. In this case are: Apache, PHP5, and MySQL, Postfix and Cyrus.
- Read and follow my previous guide about how to add and setup new site in Apache on CentOS server.
- About 15 minutes of your time and a cup of coffee if you like.
How To Download WordPress
Step 1 – Login to your server and follow my previous guide about Basic setup for CentOS before you build a live web server. You may and may not follow that tutorial but if you followed, it will give you some basic security tweak to your server.
Before you proceed to the next steps, it is better to explain that all commands in this tutorial are written without the “sudo” prefix. However if you disabled root login and you logged in using another username with root privilege, you can add the “sudo” prefix all by your self. Alternatively you can simply type su, hit Enter and type in your password twice to switch login as root.
You may also need to type this command to go to the root directory:
cd ~
Step 2 – Now go to your sites root directory and that’s can be “/var/www/domain.com/public_html” or “/var/www/domain.com/htdocs”. The root directory can be defined following my previous guide (see point 5 in Prerequisite section above). use this command to navigate to that folder
cd /var/www/domain.com/public_html
Once again, always replace “domain.com” with your actual site’s domain name.
Step 3 – Use wget command to download WordPress into your server. Here it is the command syntax to be issued:
wget http://wordpress.org/latest.tar.gz
It should be done within few seconds:
Step 4 – Extract WordPress package file. Issue following command:
tar --strip-components=1 -xvf latest.tar.gz
You can review all the files extracted using the ls command:
Next, you can simply delete the “latest.tar.gz” file unless if you still need it:
rm latest.tar.gz
How to install WordPress
This section tells you all necessary commands you have to issue to get WordPress installed:
Step 1 – First thing first, you have to create new MySQL database and user then grant all privileges for that user to the database. I’ve posted some basic and most common MySQL commands but in this tutorial I’ll repeat some of those commands so you can simply follow the steps straight forward.
Login to main MySQL screen at first. In this case I use root:
mysql -u root -p
Type in the password.
Step 2 – Once you are in MySQL screen, here you can create new database for your blog. Use this command:
CREATE DATABASE databasename;
**change databasename with your own database name. You better not use space in the name. In this example I use “myblog”:
If you wish to use space you can use underscore e.g: wp_456.
Step 3 – So you have created new database. Next, you have to create new MySQL username and grant full access to that new database. This is considered safer than using your root login. Use this command:
GRANT ALL ON databasename.* TO sqluser@localhost IDENTIFIED BY 'password';
**change databasename, sqluser and password with your own. For example:
GRANT ALL ON myblog.* TO sawiyatidb@localhost IDENTIFIED BY 'pass1234';
In that example I create “sawiyatidb” as my user for database named “myblog” while pass1234 is the password for user sawiyatidb.
That’s it. You must remember: database name, database username and its password. Once done, exit MySQL screen by typing “\q“.
Step 4 – Now edit the “wp-config-sample.php” using either vi or Nano. Assuming you are already in the root directory of your site, you can issue this command:
nano wp-config-sample.php
Or if you are still in very root directory of your server, you can use this command:
nano /var/www/domain.com.com/public_html/wp-config-sample.php
Then edit following lines:
Please replace:
- database_name_here with your newly created database (step 2 above)
- username_here with your newly created MySQL user (step 3 above)
- password_here with the password of that user.
- You can leave “localhost” as it is in MySQL hostname section, unless you are using remote database.
It looks like this in my server:
OPTIONAL BUT RECOMMENDED: You can also define following lines:
Visit https://api.wordpress.org/secret-key/1.1/salt/ to generate each value. Here it will look like:
Once done, hit Control+O to save and Control+X to exit nano editor.
Step 5 – Rename that sample file then change its permissions:
Command to rename:
mv wp-config-sample.php wp-config.php
Command to change its permissions to 644:
chmod 644 wp-config.php
Step 6 – Launch WordPress installation wizard in your browser. In this case I use Firefox. Type in your domain name then hit Enter. Now you’ll see the first page of its Installation Wizard which looks like following:
Next, scroll down the page a little bit and you’ll see several fields under “Information Needed” section you have to fill in:
Once done, simply hit the “Install WordPress” button in the bottom part.
That’s it. Now you can simply login to your newly installed blog at:
http://domain.com/wp-admin/
Optional but you may need it: Also create .htaccess file:
nano .htaccess
Once Nano editor appears, you can simply enter following lines there:
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule>
Now hit Control+O to save then Control+X to exit. Entering those lines in your .htaccess file allows you to change your blog’s permalink to domain.com/year/month/post-title.
Next, change its permissions to 777:
chmod 777 .htaccess
You can then change it to another permalink structure via your Admin Dashboard. Do not forget to change its permissions back to 644 once done edition.
Congratulation, you are now installed your newly WordPress blog. Once login you can download your favorite SEO plugins freely. Do not hesitate to drop a comment below.
Hi Mom,
Can you also write a guide on how to install Joomla and Drupal on CentOS servers?
Thanks!
Step 4: nano /var/www/domain.com/public_html/wp-config-sample.php is the correct file path.
Everything was just fine. But I am unable to upload any media.
Getting this error. Any ideas?
Unable to create directory wp-content/uploads/2014/01. Is its parent directory writable by the server?
Upload directory was not there by default. I created it.
You have three options:
1. CHMOD wp-content/uploads/ folder to 777 (not recommended, bad security practice)
2. CHOWN wp-content/uploads/ folder to httpd (chown -R httpd:httpd /path/to/directory/)
3. Or you may try this one and tell me if it works
add these lines to wp-config.php
define( 'FS_METHOD', 'direct' );
define( 'FS_CHMOD_DIR', 0777 );
define( 'FS_CHMOD_FILE', 0777 );
🙂
I am following the instructions on how to make a centos server. I was just wondering how you would get a www in from of the url for a wordpress website. I have everything running, but want to get it to look like “www.example.com” instead of “example.com”
Thanks!
Austin
That’s super easy. Simply go to your WP Admin Dashboard > Settings > General then put www in your WordPress Address (URL) and and Site Address (URL).
Ok. That did it! Thanks. I remember doing this before and I broke my website, but that was before I added a CNAME and it was propagated throughout!.
Thanks also for the tutorials! It has helped me in so many ways!
I have followed your step but it seems error when i opened mydomain.com/wp-admin
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, support@virald.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
Apache/2.2.26 (Unix) mod_ssl/2.2.26 OpenSSL/1.0.1e-fips mod_bwlimited/1.4 Server at http://www.virald.com Port 80
Could you help me?
from the configuration , you use sawiyatidb instead sawiyati mysqlusr, but why when defining DB_User in wp-config-sample you used sawiyati ?
For newbies like me: you first need to install wget, command: yum install wget
This is a very good blog for me a newbie. Please i followed your instruction to the point where i loaded my site on firefox but what am getting is the following:
The connection has timed out
The server at aftahost.com is taking too long to respond.
The site could be temporarily unavailable or too busy. Try again in a few moments.
If you are unable to load any pages, check your computer’s network connection.
If your computer or network is protected by a firewall or proxy, make sure that Firefox is permitted to access the Web
Please could it be a fault from my dns setting or what?
have you tried using vpn to access it? Or make sure your connection is established correctly
Hi…
First of all hats off to you mom 🙂
Your tutorials are really awesome.. I have fully installed kloxo on my CentOs-6 x86_64 server successfully..
now, the problem is, that i was hosting my wordpress site on a Shared hosting.. now, i have configured everything.. Server, Domain etc.. I have Transferred all my WP site’s Data , Uploaded on server , v.i.e. file manager of kloxo.. created new mySQL DB & imported the old (Backed up DB) to it.. updated the wp-config.php file as well.. but , after doing all this now i’m getting an Error 500 page… I Don’t know where is the fault stand ??
Kindly read this request, and guide me properly for that..
Regards ‘Adil’
try double check all files and folders permissions. Or you may also try chown -R your web directory to corresponding user
Well thanks for the help… Actually my server was not permitting the user to use ‘php’… now, i have allowed all php functions for user, from admin panel.. (i.e. from ‘server configuration’)..
Site is running the PHP Successfully.. 🙂