WordPress 4.1 on Ubuntu 14.10 How To

WordPress is the “de facto” standard when talking about blogs. Furthermore, WP is not restricted to the blog universe – WP is largely used as a CMS to create non-blog websites. 23% of the whole internet is built with WordPress. Sites like Time, TechCrunch, The New Yorker, Fortune, Variety, Sony, Reuters, GM, Best Buy, and so on. And most important: WP is the platform I choose to publish this blog :)

If you want to start a blog, the fastest way is to access the wordpress.com site and create a free account. But beware: wordpress.com is **NOT** “the” WordPress.

wordpress.com is just a hosting enterprise that uses WordPress. “The” WP is actually an open-source PHP software that you can download and install at your own server and that can be downloaded at wordpress.org.

Hosting at wordpress.com is okay, but your domain will be something like “my-blog.wordpress.com” and not just “my-blog.com” – not much professional.

If you want a personalized domain name, you pay them and they do all the process for you. It is an easy option, but I personally don’t like it. I like to have max control over my things, like a Stalin of software. I like to be free to change the code, install plugins, and so on. That’s why I decided to migrate from wordpress.com to my own server. And I recommend you to do the same (if you are like me).

The recipe:

1. Get a domain:

There are many domain name registrar providers. I chose Go Daddy to buy my awesome learnwithdaniel.com domain, and paid just US$ 0.99, but was a promotional discount, a bait – by now the prices are about US$ 13/year.

2. Get a cloud server:

There are many options of cloud servers to buy. I’m using a local provider (from my city, because I choose local due to superior moral reasons), but there are many options like AWS (you can have one machine for free, they use it as a bait, but you will need a credit card to create an account), or Digital Ocean (US$ 5/month). Or you can host at your home or at your company – if you have a fixed IP and a specific computer for that.

3. Download WordPress:

Go to wordpress.org and download it. I’m using the 4.1 version. It’s a small file (5.9 MB).

On your server:

mkdir -p ~/install
cd ~/install
wget http://wordpress.org/latest.tar.gz
tar -xf latest.tar.gz
cd wordpress

3. Have Apache + PHP 5 + MySQL installed:

I’m using Apache 2.4 and PHP 5.6. Check my tutorial of how to install Apache + PHP if you need. You need to check if your Apache + PHP is working before proceeding. Check the versions with: apache2 -v and php5 -v

For the database, I’m using the MySQL 5.5, installed via apt-get (check with mysql --version):

sudo apt-get install mysql-server-5.5 mysql-client-5.5 php5-mysql
Yeap, my PC is configured to the Portuguese language

mysql -u root -p

Provide the password you defined when installing the server. Once on the MySQL prompt, create a user and database for our blog. For our example, the user will be “wordpress_user“, the password “123456“, and the database “wordpress_db“.

CREATE DATABASE wordpress_db;
GRANT USAGE on wordpress_db.* to wordpress_user@localhost identified by '123456';
GRANT ALL privileges on wordpress_db.* to wordpress_user@localhost;

Exit (type quit and press Enter) and test the new user/database:

mysql -u wordpress_user -p
(out)Password: 123456

USE wordpress_db;

PS: To change the password (to ‘102030’, for example), type SET PASSWORD = PASSWORD('102030'); at MySQL prompt.

PS II: The best way to manage a MySQL server is with the Oracle’s MySQL Workbench, that you can install on your PC (not on the server). But in order to be possible to access a remote database, you need to change the MySQL server file /etc/mysql/my.cnf:

4. Create a PHP folder with the WP and create the Apache configuration:

Move WP to Apache folder (/var/www/):

sudo mkdir -p /var/www/learnwithdaniel
sudo mv ~/install/wordpress /var/www/learnwithdaniel/current

Set permissions:

cd /var/www/learnwithdaniel

chown www-data:www-data  -R * # Let Apache be owner
find . -type d -exec chmod 755 {} \; # Change directory permissions rwxr-xr-x
find . -type f -exec chmod 644 {} \;  # Change file permissions rw-r--r--

Create the Apache configuration:

sudo nano /etc/apache2/sites-available/learnwithdaniel.conf

You can name this ".conf" file to whatever you want, but NEVER forget the .conf extension!

Notice the *:80. Never use something like "<VirtualHost learnwithdaniel.com:80>". Always use "*:80" even if you have many virtual hosts. ServerName and the ServerAlias are the directives that tell Apache which VirtualHost to use. If you have multiple domain names pointing to this server, you can add multiple ServerAlias.

Also, notice that I prefer to have "current" sub-folder for the site itself. You can see this structure in many places, like on Engine Yard. The logs stay at the project root, without external access. For a staging installation, I like to put it on a "staging" sub-folder.

5. Enable the site, test, restart Apache:

sudo a2ensite learnwithdaniel
apachectl -t
(out)Syntax OK
$ sudo /etc/init.d/apache2 restart

6. Point your DNS to your Cloud Server:

Usually, your domain name registrar provider (GoDaddy, NameCheap, ...) have an interface to add DNS records. Add an "A" record with the IP of your cloud server, and an "A" "www" record also pointing to that IP.

7. Access your site on a browser and configure WP:

The process is quick and easy. Now, if you access your domain, you will see the blog.

PS: To access your Admin Settings, go to "/wp-admin/" (ex.: https://learnwithdaniel.com/wp-admin/).

PS 2: If you want pretty URLs like "https://learnwithdaniel.com/2015/01/how-to" instead of the ugly "https://learnwithdaniel.com/?p=12", you need to enable mod_rewrite (sudo a2enmod rewrite).

PS 3: If you want to force a "www" to your URL (or force a non-www), you need to configure the Admin > Settings > General > WordPress Address (URL) field and put a www (or remove it).


Now, you can look for a template on the internet or make your own!

Close Menu