This Tutorial was written on Ubuntu 20.04.
Install
- Login as
root - Update and upgrade
apt-get update
apt-get dist-upgrade Install Apache
- Install, start and enable Apache2
apt-get install apache2
systemctl enable --now apache2 - Install requirenments and dependencies
apt-get install gnupg2 ca-certificates apt-transport-https software-properties-common Install PHP
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/php.list
wget -qO - https://packages.sury.org/php/apt.gpg | apt-key add - - Update and install
apt-get update -y
apt-get install php libapache2-mod-php php-pear php-cgi php-common php-mbstring php-zip php-net-socket php-gd php-xml-util php-gettext php-mysql php-bcmath unzip wget git Install MariaDB
- Install, start and enable mariadb
apt-get install mariadb-server mariadb-client
systemctl enable --now mariadb - Now do the installation wizard:
mysql_secure_installation Configure
Create WordPress Database
- Login to the mysql shell
mysql -u root -p - Create database and user. Replace
strongpasswordwith a random password, you are going to need it later.
CREATE DATABASE wordpressdb;
GRANT ALL PRIVILEGES ON wordpressdb.* to wordpressuser@localhost identified by 'strongpassword'; - Flush privileges and exit
FLUSH PRIVILEGES;
QUIT; Download WordPress
- Go to the Webserver Root directory
cd /var/www/html - Download and unzip the latest WordPress release
wget https://wordpress.org/latest.zip
unzip latest.zip Setup Site config
- Move the WordPress folder to a folder named like your domain (optional)
mv wordpress yourdomain.com - Copy sample config
cd yourdomain.com
cp wp-config-sample.php wp-config.php - Edit config
nano wp-config.php /** The name of the database for WordPress */
define( 'DB_NAME', 'wordpressdb' );
/** MySQL database username */
define( 'DB_USER', 'wordpressuser' );
/** MySQL database password */
define( 'DB_PASSWORD', 'strongpassword' );
/** MySQL hostname */
define( 'DB_HOST', 'localhost' );
define('FS_METHOD', 'direct'); - Change owner of wordpress content to www-data
chown -R www-data:www-data /var/www/html/yourdomain.com Apache Virtual Host
- Create and edit site config (change
yourdomain.confevery time)
nano /etc/apache2/sites-available/yourdomain.conf <VirtualHost *:80>
ServerAdmin user@yourdomain.com
ServerName yourdomain.com
DocumentRoot /var/www/html/yourdomain.com
<Directory "https://yourdomain.com/var/www/html/yourdomain.com">
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/yourdomain.error.log
CustomLog ${APACHE_LOG_DIR}/yourdomain.access.log combined
</VirtualHost> - Enable this config
a2ensite yourdomain
a2enmod rewrite
systemctl restart apache2 Install via WebGUI
- Now you can access the WordPress instance via the local IP Adress and do the initial setup.
- Then setup port-forwarding and open it up to the internet
Secure
Enable HTTPS with certbot
- Install Certbot
apt-get install certbot python3-certbot-apache -y - Download and activate cert (Replace
yourdomain.com)
certbot --apache --agree-tos --redirect --hsts --uir --staple-ocsp --email user@yourdomain.com -d yourdomain.com,www.yourdomain.com Automatic Cert renewal
- Open crontab
crontab -e - Add the following line at the bottom
@daily certbot renew --quiet && systemctl reload apache2 Update
- [ ] ToDo: ToDo