Wordpress Ubuntu 1
Wordpress Ubuntu 1
Wordpress Ubuntu 1
Introduction
At this time, WordPress is the most popular CMS (content management system) on the internet. It allows you to easily set
up flexible blogs and websites on top of a MySQL backend with PHP processing. WordPress has seen incredible adoption
and is a great choice for getting a website up and running quickly.
In this guide, we'll focus on getting a WordPress instance set up with an Apache web server on Ubuntu 14.04.
Prerequisites
Before you begin this guide, there are some important steps that you need to complete on your server.
We will be proceeding through these steps as a non-root user with sudo privileges, so you will need to have one
available. You can find out how to create a user with sudo privileges by following steps 1-4 in our Ubuntu 14.04 initial
server setup guide.
Additionally, you'll need to have a LAMP (Linux, Apache, MySQL, and PHP) stack installed on your VPS instance. If you
don't have these components already installed and configured, you can use this guide to learn how to install LAMP on
Ubuntu 14.04.
When you are finished with these steps, you can continue with this guide.
We have MySQL installed, 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 the MySQL root (administrative) account by issuing this command:
mysql -u root -p
You will be prompted for the password you set for the MySQL root account when you installed the software. You will then
be given a MySQL command prompt.
First, we can create a separate database that WordPress can control. You can call this whatever you would like, but I will
be calling it wordpress because it is descriptive and simple. Enter this command to create the database:
Every MySQL statement must end in a semi-colon (;), so check to make sure this is present if you are running into any
issues.
Next, we are going to create a separate MySQL user account that we will use exclusively to operate on our new database.
Creating one-function databases and accounts is a good idea from a management and security standpoint.
I am going to call the new account that I'm making wordpressuser and will assign it a password of password . You
should definitely change the password for your installation and can name the user whatever you'd like. This is the
command you need to create the user:
At this point, you have a database and a user account, each made specifically for WordPress. However, these two
components have no relationship yet. The user has no access to the database.
Let's fix that by granting our user account access to our database with this command:
Now the user has access to the database. We need to flush the privileges so that the current instance of MySQL knows
about the recent privilege changes we've made:
FLUSH PRIVILEGES;
We're all set now. We can exit out of the MySQL prompt by typing:
exit
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 file that contains the archived directory contents of the WordPress files to our home
directory.
We can extract the files to rebuild the WordPress directory we need by typing:
While we are downloading things, we should also get a few more packages that we need. We can get these directly from
Ubuntu's default repositories after we update our local package index:
This will allow you to work with images and will also allow you to install plugins and update portions of your site using
your SSH login credentials.
Begin by moving into the WordPress directory that you just unpacked:
cd ~/wordpress
A sample configuration file that mostly matches the configuration we need is included by default. However, we need to
copy it to the default configuration file location to get WordPress to recognize the file. Do that now by typing:
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
As I said before, this file is almost entirely suitable for our needs already. The only modifications we need to make are to
the parameters that hold our database information.
We will need to find the settings for DB_NAME , DB_USER , and DB_PASSWORD in order for WordPress to correctly
connect and authenticate to the database we created.
Fill in the values of these parameters with the information for the database you created. It should look like this:
Fill in the values of these parameters with the information for the database 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');
One of the easiest and most reliable way of transferring files from directory to directory is with the rsync command. This
preserves permissions and has good data integrity features.
The location of the document root in the Ubuntu 14.04 LAMP guide is /var/www/html/ . We can transfer our WordPress
files there by typing:
This will safely copy all of the contents from the directory you unpacked to the document root.
We should now move into the document root to make some final permissions changes
cd /var/www/html
You will need to change the ownership of our files for increased security.
We want to give user ownership to the regular, non-root user (with sudo privileges) that you plan on using to interact with
your site. This can be your regular user if you wish, but some may suggest that you create an additional user for this
process. It is up to you which you choose.
For this guide, we will use the same account that we set up during the initial server setup guide, which we called demo .
This is the account I am performing all of the actions of this guide as.
The group ownership we will give to our web server process, which is www-data . This will allow Apache to interact with
the content as necessary.
This will set up the ownership properties that we are looking for.
While we are dealing with ownership and permissions, we should also look into assigning correct ownership on our
While we are dealing with ownership and permissions, we should also look into assigning correct ownership on our
uploads directory. This will allow us to upload images and other content to our site. Currently, the permissions are too
restrictive.
First, let's manually create the uploads directory beneath the wp-content directory at our document root. This will be
the parent directory of our content:
mkdir /var/www/html/wp-content/uploads
We have a directory now to house uploaded files, however the permissions are still too restrictive. We need to allow the
web server itself to write to this directory. We can do this by assigning group ownership of this directory to our web
server, like this:
This will allow the web server to create files and directories under this directory, which will permit us to upload content to
the server.
In your web browser, navigate to your server's domain name or public IP address:
http://server_domain_name_or_IP
You will see the WordPress initial configuration page, where you will create an initial administrator account:
Fill out the information for the site and the administrative account you wish to make. When you are finished, click on the
install button at the bottom.
WordPress will confirm the installation, and then ask you to log in with the account you just created:
Hit the button at the bottom and then fill out your account information:
You will be presented with the WordPress interface:
http://server_domain_name_or_IP/?p=1
This isn't exactly the most useful interface for visitors or search engines, so most users want to modify this. WordPress has
the ability to create "pretty" permalinks which will clean up the URL into a more human-friendly format.
There are a few things we need to do to get this to work with Apache on Ubuntu 14.04.
By default, this is 000-default.conf , but your file might be different if you created another configuration file:
Inside of this file, we want to set up a few things. We should set the ServerName and create a directory section where
we allow overrides. This should look something like this:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ServerName server_domain_name_or_IP
<Directory /var/www/html/>
AllowOverride All
</Directory>
...
Next, we need to enable the rewrite module, which allows you to modify URLs. You can do this by typing:
sudo a2enmod rewrite
You need to place this file in your document root. Type this to create an empty file:
touch /var/www/html/.htaccess
This will be created with your username and user group. We need the web server to be the group owner though, so we
should adjust the ownership by typing:
We may need to adjust the permissions however. This depends on how you prefer to work. WordPress will generate the
necessary rewrite rules for you. If it has write permissions to this file, it can implement the rules automatically. If it does not,
you will have to manually edit this file to add the correct rules.
Which configuration you choose depends on how much you value convenience over security. Allowing the web server
write access to this file will definitely be more convenient, but some say that it is an unnecessary security risk.
If you want WordPress to automatically update this file with rewrite rules, you can ensure that it has the correct
permissions to do so by typing:
If you want to update this file manually for the sake of a small security gain, you can allow the web server only read
privileges by typing:
On the left-hand side, under the Settings menu, you can select Permalinks :
You can choose any of the preconfigured settings to organize URLs, or you can create your own.
When you have made your selection, click "Save Changes" to generate the rewrite rules.
If you allowed the web server write access to your .htaccess file, you should see a message like this:
If you did not allow the web server write access to your .htaccess file, you will be provided with the rewrite rules you
need to add to the file manually.
Copy the lines that WordPress gives you and then edit file on your server:
nano /var/www/html/.htaccess
Conclusion
You should now have a WordPress instance up and running on your Ubuntu 14.04 VPS. There are many avenues you can
take from here. Below we've listed some options:
Related Tutorials
How To Set Up Multiple WordPress Sites Using Multisite
How To Install Wordpress and PhpMyAdmin with Docker Compose on Ubuntu 14.04
138 Comments
Log In to Comment
0 Sure no reason you cannot. It is generally suggested that you don't use a userid that hackers can guess - you'll find that they
are relentless in their attempts to hack and if you use "admin", "root", etc. they will be pounding on your installation 365x24x7
until they break in or you block their IP address and you'll be blocking a LOT of them.
0 ichityx: You sure can. If that helps you remember the correct details, go ahead!
0 So would installing your custom theme just be a matter of going into the wp-contents/theme directory and just uploading
your theme. And what if the theme already has content, would it just be a matter of downloading the db and then
importing it through phpmyadmin?
Thanks.
0 Hi,
I followed your instructions to the T but unfortunately I cannot EDIT any themes. I managed to get this working once on the
default theme but not on newly installed ones.
Could you check the permissions are definitely correct? I know this is permissions related and I cannot figure out how to
get it working. The one time I managed to edit the default theme, WordPress kept prompting for my FTP username and
password to install anything so I know this is permissions related.
Please help.
0 Curious, are you using Wordpress to download the themes or are you downloading manually?
If the latter you might need to do chmod on the permissions of the theme folder to match the other theme folders. HTH
fak3email May 20, 2014
0 To elaborate, I have tried adding the "direct" input method to the wp-config file, I've checked the permissions and
ownership and groups for wp-content (me/www-data with Create and Delete) and nothing is working.
0 @fak3email: Make sure the www-data can access the themes folder:
0 Hi, thank you but I've already done that, all permissions have been checked.
After this step, I have create and delete for myself as the owner and also Create and Delete for the group www-data.
However, at the step before when assigning the owner and group, www-data only has "Access" rights on all folders. Are
these permissions correct? Shouldn't www-data have Create and Delete access to wp-content? These instructions I
followed only gave Access to www-data on wp-content.
Additionally, the HTML folder originally had root:root but since following these instructions it is now Me:Me
Even when I change the permissions on all folders manually, I still cannot edit themes directly within WordPress.
0 Any guides for installing Wordpress on LEMP instead? Search seems unwilling to produce evidence thereof, but I'm really
really hoping. I've been doing every step manually rather push-click-image to learn some things, but in no way qualified to
set-up each step securely without guides (and further research and refinements later).
0 Nvmd, I just boneheaded rather than doing the right thing from the start, https://www.google.com/search?
q=digital+ocean+wordpress+ubuntu+14.04+lemp
asb MOD June 5, 2014
We should have some site improvements rolling out soon that will improve search greatly.
WordPress is the most popular CMS (content management system) in the world. It can be used to get your site or blog off
the ground quickly and it provides a nice interface for adding content and modifying the site's design. In this guide, we'll
walk through how to install WordPress on Ubuntu 14.04 with an Nginx web server.
0 Dang wish I knew about this. I really LOVE nginx (aka engine-x) and tried installing wp on there with disastrous results but will
try again. nginx is supposed to have AMAZING performance.
0 I wrote an install script based on this tutorial. Should I post the link here or is that violation of intergalactic law?
0 I get prompted for a username and password which I do not know, can someone help me out?
0 @Mike: Do you have DNS records pointing your domain to your IP? You'll also want to set ServerName to:
ServerName www.example.com
0 I'm having an issue I'm hoping someone can help with. I followed these instructions and got Wordpress running with no
problems. First off, thanks for the comprehensive guide - it's especially useful to first-timers like me! Now, I wanted to
access my Wordpress site over the internet, so I set up port forwarding on my router (I've done this tons of times for
security cameras I've installed). I can get to the site, however it looks like crap when I come from the outside. Almost like
style sheets aren't being applied or something. Also, if I click on any link (like to view the first entry) it hangs for while and
then says page not found. Is this a permissions issue, or perhaps something in how my router is forwarding/replying to
requests? Any help is appreciated!
0 Prolly a way late reply but hopefully it helps others in your situation (and I don't know if you'll get this... seems digitalocean... as
much as I love their tutorials... are trying to get me to pay for an account to comment)... but what you need to do is log in to your
wordpress account and from dashboard > settings you need to change the wordpress address (URL)... and maybe even the site
address (URL) from the domain to your IP address (ie http://192.168.0.123). At least this worked for me when I was running
wordpress on my local LAMP server... it has to do with the way wordpress links to directories. Make sure that if you're trying to
access internally to use your internal IP... externally use your external IP. Hope this helps, took me a day and probably added a
few gray hairs to figure this out.
0 This tutorial's great for learning Linux basics on a dev server. If you're looking to run a live WordPress site or multiple on the same
server, it's better to use <a href="https://serverpilot.io">ServerPilot</a> to configure and manage the server.
0 Serverpilot charges you to install ssl $10/m - they take some of the folders out from the Digital Ocean installation to prevent you
from installing your ssl without purchasing their license.
0 I got it working. I just needed to go into settings and change the ip address to my public IP address instead of the internal one that
was there. Now everything is working well.
Copyright 2017 DigitalOcean Inc.
Distros & One-Click Apps Terms, Privacy, & Copyright Security Report a Bug Get Paid to Write Shop