Hosting Your Own WordPress


 

I’ve found a lot of information out there on how to host WordPress through a third party, but very little on how to do it yourself.  There is some info out there, but most of it is in pieces and assumes that you already have some things in place.  With that in mind, I though I would give a quick and simple, yet comprehensive, explanation for others (and my own future reference!) on how to host your own WordPress Blog from start to finish.

Materials Needed:

  1. A computer, internet, and a brain (lol)
  2. a server,either
    •  a local server (one that you physically own) or
    • a virtual (such as one hosted by a cloud server provider like Digital Ocean.)

NOTE: For the sake of this explanation, I will assume that you have a cloud server and you are using Ubuntu 14.04 x64.


 

Step One: Setup a LAMP Server (Linux, Apache, MySQL, PHP)

 

An easy to follow step by step guide for setting this up can be found here.

 

Step Two: Download WordPress

The quickest way to download the latest version of WordPress is right from your terminal with a wget command:

cd
wget http://wordpress.org/latest.tar.gz
tar -xzvf latest.tar.gz

This will download, and unzip the file into your home directory.

 

Step Three: Prep the MySQL database for WordPress

To start, we need to login to MySQL on your server and add a user for WordPress to use.

mysql -u root -p

Then enter your root password. Next, create the wordpress user.

NOTE:  You MUST change the green text to your own unique information.

create database wpdatabase;

create user 'wp_user'@'localhost' identified by 'unique_passwd';

grant all privileges on wpdatabase.* to 'wp_user'@'%';

flush privileges;

 

Step Four: Prep the WordPress Config File

You will want to exit the <mysql> prompt by typing exit.  then enter:
cp ~/wordpress/wp-config-sample.php ~/wordpress/wp-config.php

and then:
sudo nano ~/wordpress/wp-config.php

 

This will open the nano editor so that you can modify the wp-config.php file.

You will need to change the ‘database_name_here’, the ‘username_here’, and the ‘password_here’ entries to match what you entered in the previous step.
Once finished, press Ctrl+x, y to close and save and then enter the following command.

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

the location ‘/var/www/html’ is the most likely default location, but it needs to be where ever your apache server is looking for your web files.

 

Step Five: Login and Setup WordPress

Assuming your apache server is up and running, and the info has been entered correctly, you should now be able to log into the admin console of WP.  Enter:
curl http://icanhazip.com

This will give you your server’s IP.  Go to your browser and enter the IP you just got from the previous command.  For example, if you ip is 123.456.789.10, then you would enter:

http://123.456.789.10/wp-admin/install.php

 

From here, follow the single page of setup on the web browser and your WordPress Blog will be ready to customize!

 

WAIT!!  I can’t upload stuff or add new themes- now what?!

I ran into this myself, none of the examples online that I found online explicitly explain how to get this working on your own hosted server.  The next steps are specifically for getting these two issues resolved.

 

First- the uploading pictures permissions issue.  This is a REALLY easy one to solve.  if you enter

sudo chmod 0777 /var/www/html/wp-content/ -R

it sets the perms on the upload folder to allow uploads online.  Problem solved!

 

Next, the FTP demon needed in order to install/update plugins and themes.  This is a bit more tricky, but still no big deal.

 

to start we will need an FTP demon.  I recommend vsftpd (Very Simple FTP demon)

sudo apt-get install vsftpd
the next thing is to make a back up of the original config file:

sudo cp /etc/vsftpd.conf /etc/vsftpd.conf.orig

 

Next access the conf file and make some changes. Delete everything and paste:

listen=YES
anonymous_enable=NO
local_enable=YES
virtual_use_local_privs=YES
write_enable=YES
connect_from_port_20=YES
secure_chroot_dir=/var/run/vsftpd
pam_service_name=vsftpd
guest_enable=YES
ftp_username=webadmin
chmod_enable=YES
chown_uploads=YES
chown_username=webadmin
guest_username=webadmin
force_dot_files=YES
pasv_enable=YES
pasv_promiscuous=YES
pasv_min_port=1024
pasv_max_port=65535
max_clients=10
max_per_ip=10
port_promiscuous=YES
port_enable=YES
listen_port=21
ftp_data_port=20
user_sub_token=$USER
hide_ids=YES
user_config_dir=/etc/vsftpd
chroot_local_user=YES
allow_writeable_chroot=YES

 

Now we need to make a unix user (if you aren’t using a pre-existing one)

sudo adduser webadmin

follow the steps to create a password.  This will be the ftp user and password that you will need on the wordpress site in order to get uploads/updates to work.

Not done yet-  next we need to create a file:

sudo mkdir /etc/vsftpd && sudo nano /etc/vsftpd/webadmin

this will open the new file you create to edit it.  paste:

local_root=/var/www/html/  <-again this is the default, but it needs to be where ever the website files are located

 

finally:

sudo chown webadmin:www-data /var/www/html/ -R

 

Then reset vsftpd and you should be good to go!

sudo service vsftpd restart

 

I’d rather not use FTP, is there another way?

Yup!  This is, arguably, the easier way- though It does require setting the perms a little differently and can cause some minor issues for advanced users trying to edit the php content of the themes. Not a big enough problem that it can’t be worked around, but something to note.

This method involves setting the owner of the site files to the apache user.   The use is “www-data” if you’re on Debian/Ubuntu using Apache2.  If you’re on centos, the user is “apache” on httpd.

sudo chown www-data:webadmin /var/www/html -R

sudo chmod 775 /var/www/html -R

This allow WordPress to modify its files, and makes updates and loads easier.  This is certainly the more user friendly way of doing things!