パン屑の轍

ボドゲとかプログラミングとかゲームとか

Howto: Launch WordPress on localhost

Howto: Launch WordPress on localhost

Environment

$ uname -r
4.4.0-17763-Microsoft
$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.6 LTS"
  • Generally, a wordpress server will be built on a remote server, but here, we will build our wordpress servers on our local machines.

  • Generally, when install wordpress, people use tarball, but here, we use the debian package and apt.

Procedure

When you're make what to do unclear, see here and /usr/share/doc/wordpress/README.debian (after step 2).

  1. install wordpress
$ sudo apt install php
$ sudo apt install wordpress
  1. install mysql
$ sudo apt install mysql-client
$ sudo apt install mysql-server
  1. start mysql
$ sudo service mysql start
  • Option: add the user to group mysql
$ sudo sudo chmod g+rw /var/lib/mysql*
$ sudo usermod -aG mysql <your user>
$ groups <your user>
  1. create mysql db and user
$ mysql -u root -p
#<input your password set when install mysql-server>
mysql> CREATE DATABASE wordpress;
Query OK, 1 row affected (0.00 sec)
mysql> GRANT ALL PRIVILEGES ON wordpress.* TO "wordpress"@"localhost"
-> IDENTIFIED BY "<your password>";
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql> EXIT
Bye
define('AUTH_KEY',         'z|p-x{ohxM>.!AfHI....');
define('SECURE_AUTH_KEY',  'tTN....');
define('LOGGED_IN_KEY',    'ikH....');
define('NONCE_KEY',        '|Hn626m)afI....');
define('AUTH_SALT',        '--a{](M[k]...');
define('SECURE_AUTH_SALT', 'Erp*_5@t}e:uoV/j79<IDT;$`*3{`gF...');
define('LOGGED_IN_SALT',   'q^x...');
define('NONCE_SALT',       'T]6K2,]...');
  1. . Edit configuration file
$ sudo cp /usr/share/wordpress/wp-config-sample.php /etc/wordpress/config-<host e.g. localhost>.php
$ sudo vim /etc/wordpress/config-<host>.php
# Edit like below
## Before
/** The name of the database for WordPress */
define('DB_NAME', 'database_name_here');

/** MySQL database username */
define('DB_USER', 'username_here');

/** MySQL database password */
define('DB_PASSWORD', 'password_here');

/** MySQL hostname */
define('DB_HOST', 'localhost');

/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');

/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', '');
## After
/** The name of the database for WordPress */
define('DB_NAME', 'wordpress');

/** MySQL database username */
define('DB_USER', 'wordpress');

/** MySQL database password */
define('DB_PASSWORD', '<your password>');

/** MySQL hostname */
define('DB_HOST', 'localhost');

/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');

/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', '');

you should use your ip addr for config-<host>.php.

Here, we use config-localhost.php.

  1. Install and Run server

    • install server

    Here, we use nginx as a server. Please see also http://wiki.nginx.org/WordPress

$ sudo apt install nginx fcgiwrap php-fpm
  • configure server

Please see /usr/share/doc/wordpress/examples/nginx-wordpress.conf

$ sudo vim /etc/nginx/conf.d/default.conf
server {
       listen 80;
       server_name wordpress.local;
       root /usr/share/wordpress;
       index index.php;

       localton = /favicon.ico {
               log_not_found   off;
               access_log      off;
       }

       location = /robots.txt {
               allow           all;
               log_not_found   off;
               access_log      off;
       }

       location / {
               try_files $uri $uri/ /index.php?$args;
       }

       location ~ \.php$ {
               include /etc/nginx/fastcgi_params;
               fastcgi_param            SCRIPT_FILENAME         $request_filename;
               fastcgi_index            index.php;
               fastcgi_intercept_errors on;
               fastcgi_pass             unix:/var/run/php-fpm.sock;
       }

       location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
               expires                  max;
               log_not_found            off;
       }
}
$ sudo sudo cp /etc/nginx/sites-available/default  /etc/nginx/sites-available/__default #keep original file
$ sudo cp /etc/nginx/conf.d/default.conf /etc/nginx/sites-available/default
  • check the configuration file
$ sudo service nginx configtest
* Testing nginx configuration   [ OK ]
  • configure php-fpm
$ sudo vim /etc/php/7.0/fpm/pool.d/www.conf
# Edit like below
## Before
listen = /run/php/php7.0-fpm.sock

## After
;listen = /run/php/php7.0-fpm.sock
listen = /var/run/php-fpm.sock

$ sudo vim /etc/php/7.0/fpm/php-fpm.conf
# Edit like below
## Before
pid = /run/php/php7.0-fpm.pid

## After
;pid = /run/php/php7.0-fpm.pid
pid = /var/run/php-fpm.pid
  • run server
$ sudo service nginx start
* Starting nginx nginx   [ OK ]
$ sudo php-fpm7.0
  1. access http://localhost/wp-admin/install.php with the web browser.

    • Configure the initial setting

      • Site Title

        • your site title
      • Username

        • your user name
      • Password

        • your password

          You should use the generated password.

      • Confirm use of weak password

        • here, we disable it. But, if you want to use wordpress in the internet, you should enable it.
      • Email

        • your email
      • Search Engine Visibility

        • yes
  2. Log in and configure your site!

Important files

  • /usr/share/wordpress
  • /usr/share/doc/wordpress
  • /etc/wordpress

    • config-$HOST.php: the configuration file used for each host
    • config-$DOMAIN.php: the configuration file used for each domain
    • config-defaults.php: the configuration file used by defaults
  • /etc/nginx/sites-available/default: the configuration file for nginx

  • /etc/php/7.0/fpm: the configuration files for php-fpm
    • pool.d/www.conf
    • php-fpm.conf

Reference