After installing LAMP on your VPS, you can now install WordPress to build your own website.
Setup MySQL
First, create database and user for wordpress. Login to MySQL.
sudo mysql -u root -p
Create a new database.
CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
Create a new user. Replace wpuser and passwd with your own.
CREATE USER wpuser@localhost IDENTIFIED BY 'passwd';
GRANT ALL PRIVILEGES ON wordpress.* TO wpuser@localhost;
Refresh privileges and quit.
FLUSH PRIVILEGES;
EXIT;
Setup WordPress
Download the latest version of WordPress.
cd ~
curl -O https://wordpress.org/latest.tar.gz
Create a WordPress configuration by copying the sample one.
cp -a wp-config-sample.php wp-config.php
nano wp-config.php
Replace DB_NAME, DB_USER, DB_PASSWORD with what you’ve used in last step
define( 'DB_NAME', 'wordpress' );
/** MySQL database username */
define( 'DB_USER', 'wpuser' );
/** MySQL database password */
define( 'DB_PASSWORD', 'passwd' );
Generate secret key from WordPress website.
curl -s https://api.wordpress.org/secret-key/1.1/salt/
You’ll get something like that.
define('AUTH_KEY', '8%Q})6%~Kjb|)s|24PF r1+5>&X<w{kJ3Kgq6|6cG4*AxX`&FcO/acj)<meN7dte');
define('SECURE_AUTH_KEY', 'n=h$|JPp,8}nmqM+B7d }(Pl{3Sj`LiPbh(ulTpm.p[*5rOj,ju$hclOioJC6`J7');
define('LOGGED_IN_KEY', '1<2!I<Y7Kj0G+|7+-]>+Cgc>1,xGK)HfLh3suL%a0|O9M{/~HFM0wf{pU{aU!qd&');
define('NONCE_KEY', '<6ZuCiM+C-9xjrb[[-[V_Wvk#LIj!] Uz{#sKB_~37LC=n|K7F6WNpide,(o;xJk');
define('AUTH_SALT', '5m0&wCfz(>{494-i>1sG9?oTBd]hD)g_##C7Q@%/21ZYK2%S>^`k#w&<X).8krbi');
define('SECURE_AUTH_SALT', '3)uP@J(|^#duOj+%Y1pCC)4MAR2XbJK.HzF{`gTrU kZruh1lp:=7bn<nfe6kDo~');
define('LOGGED_IN_SALT', '&,F+qx22+<oN$-|{AWko|HPp$t*DVc.Gylu[3|jYL96GPh]3%L$xjN7^|LJ$)b#O');
define('NONCE_SALT', 'mi;u+-:fp E!Qp5%uBAfZ|-.>R Jg]U&{miZa4#J*5EAIpJ0^xd+nj#0CXGL+`+-');
Replace the corresponding config in wp-config.php.
Add
define('FS_METHOD', 'direct');
to the end of the file.
Now copy all files to the website root.
sudo cp -a ~/wordpress/* /var/www/html
sudo chown -R www-data /var/www/html
Open your website in browser and follow the instruction. And now you are all set!
Trouble shooting
Some possible reasons that you cannot reach your website.
– Check your firewall
ufw status
If there is no Apache, you can add it by
sudo ufw allow apache
- Check iptable
Problem that I still haven’t fixed
After editing the Permalink Settings, I was unable to publish new post. From Chrome dev tool I find out that there’re several errors and all /wp-json could not be found. I’m still looking for the solution. So don’t change it unless you know how to fix the problem.
The next post is about Enable SSL