WordPress is an extremely popular open source software for making websites and blogs on the internet today. In this tutorials we will show you how to install and configure it in latest free operation system ubuntu 20.04. Example name used here are “mysite.com, dbname, wp-user and wp-pass”, please change to your own in your config files.
- Make sure all packages are up to date, and configure 1G swap memory (optional)
sudo apt update && sudo apt upgrade
swap:
sudo fallocate -l 1G /swapfile
sudo dd if=/dev/zero of=/swapfile bs=1024 count=1048576
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
echo "/swapfile swap swap defaults 0 0" | sudo tee -a /etc/fstab
2. Install LAMP Stack (Linux Apache Mysql PHP)
sudo apt -y install tasksel sudo tasksel install lamp-server sudo apt -y install php-curl php-gd php-mbstring php-xml php-xmlrpc
3. Switch to root user, configure mysql
sudo -i
$mysql -u root mysql>CREATE DATABASE dbname; mysql>CREATE USER 'wp-user' IDENTIFIED BY 'wp-pass'; mysql>GRANT ALL ON dbname.* TO 'wp-user'; mysql>quit;
$mysql_secure_installation
4. As root user, configure Apache
cd /etc/apache2/sites-available/ cp 000-default.conf mysite.com.conf vi mysite.com.conf
to add section:
AllowOverride All Options Indexes FollowSymLinks AllowOverride All Require all granted
and update site name:
ServerName mysite.com ServerAlias www.mysite.com ServerAdmin webmaster@localhost #DocumentRoot /var/www/html DocumentRoot /var/www/mysite.com
5. install wordpress
mkdir -p /var/www/mysite.com cd /var/www/mysite.com wget https://wordpress.org/latest.tar.gz tar -xzvf latest.tar.gz mv wordpress wp-5.5 ln -s wp-5.5 wp cd /var/www/mystie.com/wp cp wp-config-sample.php wp-config.php
vi wp-config.php
update as below(use dbname, wp-user, wp-apss as example). Also update secret/salt section:
define( 'DB_NAME', 'dbname' ); /** MySQL database username */ define( 'DB_USER', 'wp-user' ); /** MySQL database password */ define( 'DB_PASSWORD', 'wp-pass' );
vi /var/www/mysite.com/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$
RewriteCond %{REQUEST_URI} !^/wp/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /wp/$1
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$
RewriteRule ^(/)?$ wp/index.php [L]
</IfModule>
Change owner and r/w permission
chown -R www-data:www-data /var/www/mysite.com
sudo find /var/www/mysite.com/ -type d -exec chmod 750 {} \;
sudo find /var/www/mysite.com/ -type f -exec chmod 640 {} \;
Enable site
a2enmod rewrite
systemctl restart apache2
a2dissite 000-default.conf
a2ensite mysite.com.conf
systemctl reload apache2
6. That’s it! You can access to you wordpress site using your registered domain name now. Example here is http://www.mysite.com. Please see my previous post for how to make it HTTPS available.