Start-up guide: Setting up a website

A public website is a must have for a start-up company. The easiest way to set this up is to use WordPress. WordPress is a free platform with offers website templates (themes) and hundreds of plug-ins that can be configured using a intuitive web interface.

What this implies: well, first of all you would need a machine (physical or virtual) running an operating systems, Ubuntu is preferred because it’s free and supports everything. What else ? … a web server installed on Ubuntu. The mostly used web servers out there are Apache and Nginx. We will go with Apache this time, I’ll explain later on why.

Let’s get started. You need to install the latest version on Ubuntu on your machine: see the blog post showing you how to install it. Next, update the package repositories and upgrade the packages to the latest versions. Install Apache, start it and set it up to automatically start when you reset your machine:

sudo apt-get install -y apache2
sudo systemctl start apache2
sudo systemctl enable apache2

Next, we need to prepare the machine for WordPress. We need MySQL, PHP and the latest WordPress bits. Run the following commands in the /var/www/html directory:

cd /var/www/html/
sudo apt-get install -y mysql-server 
sudo systemctl start mysql 
sudo systemctl enable mysql 
sudo apt-get install -y php libapache2-mod-php php-mysql php-curl php-mbstring php-gd php-xml php-xmlrpc php-intl php-soap php-zip 
sudo systemctl restart apache2 
sudo wget -c http://wordpress.org/latest.tar.gz 
sudo tar -xzvf latest.tar.gz 
sudo chown -R www-data:www-data /var/www/html/wordpress 

Ok, now we need to create the WordPress database in MySQL:

sudo mysql -u root -p
CREATE DATABASE wordpress_db; 
GRANT ALL PRIVILEGES ON wordpress_db.* TO 'wordpress_user'@'localhost'IDENTIFIED BY 'password'; 
FLUSH PRIVILEGES;
exit; 

Change the password in the above command like you see fit. Take a note on the database name, user name and password, we need them later on. Go to the WordPress root directory and edit the wp-config.php file:

cd /var/www/html/wordpress/ 
sudo mv wp-config-sample.php wp-config.php 
sudo nano wp-config.php

In the WordPress configuration template, change the database name, user name and password to match the ones you set in the previous step. Save it, restart Apache and MySQL:

sudo systemctl restart apache2
sudo systemctl restart mysql

The last thing is to configure Apache so it will point out to the WordPress root directory when we navigate to the external url. For this, we need a new configuration file in Apache’s sites-available directory:

cd /etc/apache2/sites-available/ 
sudo nano example.com.conf 

A configuration sample is the following:

<VirtualHost *:80>
	ServerName example.com
	ServerAlias www.example.com
	DocumentRoot /var/www/html/wordpress
	<Directory /var/www/html/wordpress>
		AllowOverride All
	</Directory>
	ErrorLog ${APACHE_LOG_DIR}/example.com.ro_error.log
	CustomLog ${APACHE_LOG_DIR}/example.com.ro_access.log combined
	RewriteEngine on
	RewriteCond %{SERVER_NAME} =example.com [OR]
	RewriteCond %{SERVER_NAME} =www.example.com
	RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

Enable your site and restart Apache:

sudo a2ensite example.com.conf
sudo systemctl restart apache2 

What else ? Oh yes … you might need SSL to make your site trust-able. To do this, you need some SSL certificates, you can get them with certbot:

sudo apt-get install -y python-certbot-apache
sudo certbot --apache -m first.last@example.com -d example.com -d www.example.com

You need to agree with the email sharing and select redirect to https. Then edit the wp-config.php file in your WordPress root directory and change/add the following lines:

//Use HTTPS for WordPress
define('WP_HOME','https://www.example.com');
define('WP_SITEURL','https://www.example.com');
define('FORCE_SSL_ADMIN', true);

The certificate expires after 30 days, so make sure you renew it in time. More info here:

Have fun!

You may also like...

Popular Posts

Leave a Reply