Programster's Blog

Tutorials focusing on Linux, programming, and open-source

Ubuntu 16.04 - Manually Deploy Wordpress

This tutorial is for manually deploying wordpress on an Ubuntu 16.04 server. Alternatively, you could deploy wordpress through docker.

Install mysql

sudo apt-get install mysql-server -y

Install apache and PHP

sudo apt-get install apache2 libapache2-mod-php7.0 \
php7.0-cli php7.0-mysql -y

Set Up The Database

mysql -u root -p
CREATE DATABASE `wordpress`;
GRANT ALL ON `wordpress`.* to wordpress_user identified by 'YOUR PASSWORD HERE';

Download wordpress

wget https://wordpress.org/latest.zip

Optional - Create Wordpress SSH User

I use SSH to update my wordpress instances, and wish to use a non-sudo user to do this. Thus I will create a wordpress user at this point.

sudo adduser wordpress

Install Wordpress

sudo apt-get install unzip -y
unzip latest.zip
sudo mkdir -p /var/www/wordpress
sudo mv wordpress /var/www/wordpress/public_html
sudo chown -R wordpress:www-data -R /var/www/wordpress
sudo chmod 750 -R /var/www/wordpress

Set Umask and Add to Group

Lets set the umask and add the www-data user to the wordpress group, so that if the wordpress user creates files, the apache server can still read them.

sudo adduser www-data wordpress
cd /var/www/wordpress
umask 027

Using umask of 027 means that new files will have 740 (-rwxr-----) permissions, but new directories will have 750 (-rwxr-x---).

Update Apache

sudo vim /etc/apache2/sites-available/000-default.conf

Replace it with:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost

    DocumentRoot /var/www/wordpress/public_html
    <Directory /var/www/wordpress/public_html/>
        Options Indexes FollowSymLinks
        AllowOverride All
        Order allow,deny
        allow from all
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

This assumes this webserver is dedicated to just serving up the wordpress site. E.g. a VPS.

Restart apache for the changes to take effect

sudo service apache2 restart

Optional - Enable URL Rewrite

Your more than likely to want this feature. If you're unsure, I would err on the side of enabling it.

sudo a2enmod rewrite
sudo service apache2 restart

Web Installation

Now go to your servers IP or hostname and perform the web based installation steps, before then going through the tutorial on securing wordpress.