Choose Language

Mateusz Marchel

I'm doing PHP development since 2012. I'm passionate about new technologies and for couple years I like WordPress very much. If you think that I can help you, please send me an e-mail. I love new challenges!

Privately I have beautiful wife Edyta, I like good music and I play guitar in my free time.

Archives

Tag: WP-CLI

WordPress installation

In this part we install WordPress itself on our environment. I’ll use for this purpose WP-CLI. It’s very handy tool for managing WordPress from command line. If you haven’t hear about WP-CLI I recommend to do some research on it.

In this part I assume that you own domain name for your WordPress. You should change A record for your domain to reflect IP address of your instance. Remember that such change could be visible after couple of hours. If you have any doubts about this process, contact with your service provider.

Apache Virtual Host

We’ll start from writing another piece of configuration. For now our server is configured to serve files from /var/www/html for every request. We can change it with virtual host configuration. We can then route users which are comes to our machine to different places based on some predefined criteria. The most common way of segregating users is domain name which user types in address bar of his browser. We can then add new configuration for our WordPress website. I will use domain wordpress.marchel.it. Let’s create configuration file. You can name it anything you want but file should ends with “.conf”.

sudo nano /etc/apache2/sites-available/wordpress-marchel-it.conf

wordpress-marchel-it.conf

1

2

3

4

5

6

7

8

9

10

11

12

<VirtualHost *:80>

ServerName wordpress.marchel.it

ServerAlias www.wordpress.marchel.it

DocumentRoot /var/www/wordpress-marchel-it/public_html

<Directory /var/www/wordpress-marchel-it/public_html>

Options -Indexes +FollowSymLinks

AllowOverride All

Require all granted

</Directory>

</VirtualHost>

What is going on here?VirtualHost opens section where we’ll define all settings about our virtual host. Asterisk symbol means that we check for connections that are coming through any IP address that is attached to our server (in our case there’s only one public IP, but could be more). Colon i separator and number 80 is port number for HTTP service, where our server are pending connections.ServerName is used for identification that this is the host for which browser is asking. It should be just your domain name.ServerAlias gives us possibility of defining additional Server Names. In example above I’ve added www prefix so if someone will enter address with this prefix in his browser, server will know that following rules also applies here.DocumentRoot is used to define root directory for our site. I came up with /var/www/wordpress-marchel-it/public_html. This path of course should exists so let’s create it and give it appropriate permissions.

First two lines obviously creates directories. In third line we changed owner of public_html directory for www-data user. We also assigned this directory to www-data group. Owner of files should be user with which privileges all PHP scripts will be running. In our case this user is www-data. Without this settings we won’t be able for example to install plugins directly from dashboard.

Warning!
If you running more than one site on your server this kind of configuration can by dangerous! In this case you should consider creating user for every application which owns this application files and with which privileges application will be running.

In last line we changed permissions for public_html directory. It’s available for read, write and execute for owner and group.

Directory opens section where we can configure some options for provided path.Options give us ability to turn on or off some additional server features. In this case we turn off directory listing – if some folder doesn’t contain index file, it won’t be listed and instead of that error 403 will be returned – access forbidden. Additionally we set ability to follow symlinks which will be needed for pretty urls in WordPress.AllowOverride All give us ability to overwrite server settings with .htaccess files which WordPress use.Require All Granted permit anyone to have read access to folder which is obviously needed if we want to publish our website.

We can save this file and we’ll back to it in a while.

PHP-CLI and WP-CLI installation

Installed previously PHP version works only with Apache server. We can’t manually run PHP script from terminal. Because WP-CLI is written in PHP we should provide environment in which we can use it. This time there won’t be painful configuration. Just one line:

sudo apt-get install php5-cli

Great! Let’s download WP-CLI following instructions on project website. It’s worth to change directory to your home directory if you are somewhere else (you can do it by running command cd ~/).

Now it’s good to make WP-CLI globally accessible so we need to give it execution permission and move it to directory which is included in PATH variable.

1

2

chmod +x wp-cli.phar

sudo mv wp-cli.phar /usr/local/bin/wp

Now if you run command wp --info you should see the same result.

Creating new MySQL database.

Last step before WordPress installation is to create empty database where our blog will store all of it’s data. Let’s do this then. We should log in as root to our MySQL server. We can do this like this:

1

mysql -u root -p

This means that we are logging in as user root and we’ll be asked for password which we are previously defined during installation process.

First one creates database named db_name with utf8mb4 charset. You can find very good explanation of character encoding subject here.

Second grants all permissions to manage database called “db_name” to user called “user_name” which authenticates with password “password” . If this user doesn’t exists it will be created.

Third query reload privileges. Just for sure.

Next we exit MySQL console with simple command exit.

Time for WordPress

Finally we came to what this series is all about so to the WordPress installation. As I mention before we use WP-CLI for this purpose. We have already create directory where we want to install our blog, so change our working directory to this folder. In my case it will be:

1

cd /var/www/wordpress-marchel-it/public_html

Now we need to download WordPress files:

1

wp core download

If you want to look closer to some WP-CLI command you can add word help at the beginning, for example wp help core, or wp help core download. Above command will download newest version of WordPress with en_US language pack. If you want to download another language version (Polish for instance) you can add parameter –locale=pl_PL

Now we need to generate wp-config.php file, where among others database credentials will be stored. We should provide at least database name, database user and password. By default for all tables prefix wp_ will be used but we can of course change this by adding appropriate arguments.

In URL filed we should provide address where our blog will be publicly available. For me it’s wordpress.marchel.it.title is simply title of our site. If you have spaces in it you should enclose it with double quotes.admin_user is field where we can set name for our useradmin_password will set up password for our useradmin_email is email address which will be used for administrative purposes

During installation probably you’ve seen this information:

sh: 1: /usr/sbin/sendmail: not found

It means only that software used by WordPress to sending emails is not installed in our system. I won’t cover in this tutorial configuration of sendmail which is default transport for WordPress emails. Instead of that I suggest to use one of available plugins which enable WordPress to send emails through SMTP. I’m using Easy WP SMTP. Configuration of this plugin is very easy – you just need to provide login and password for your email account and SMTP server address along with encryption settings. You are doing exactly the same when you configure Outlook or Thunderbird.

So everything is ready. Now we should enable configuration we prepared in first section of this part and just visit our site. 🙂

1

2

sudo a2ensite wordpress-marchel-it.conf

sudo service apache2 reload

Perfect! We just launched our WordPress! In next part I’ll show you that however everything looks good, some features won’t work as it should. We also fix all of the problems of course.