Install Ubuntu + Nginx + MySql + PHP on Mac for your WordPress site.
Addition to that, we will install Postfix and SSL.
– First thing first, you need to get a droplet from DigitalOcean and set it up with Ubuntu. It will be a click through process on DigitalOceans dashboard.
For more info,
– In order to connect to your droplet securely, you need to set up SSH key.
By doing this process, you will have `id_rsa` and `id_rsa.pub` files in your local machine and `authorized_keys` on your droplet.
– It is recommended to create another user beside ‘root’ user. This tutorial will show you how to create new user that you will be using for most of time.
You will end up with new users directory with new authorized_keys file. ‘e.g. home/YOUR_NEW_USERNAME/.ssh/authorized_keys’.
Now you have a new username with SSH key which will allow you to login to your droplet without password.
by typing `ssh YOUR_NEW_USERNAME@YOUR_IP_ADDRESS` in your terminal.
– Recommended setting for Ubuntu 14.04 server
The fun part begins here.
Let’s install Linux, nginx, MySQL, PHP (LEMP) stack on your Ubuntu 14.04!
If you completed above steps, you can jump right into installing Nginx web server on this article.
This article will walk you through installing Nginx, MySql and PHP in your Ubuntu web server and how to configure it to work together.
Now you have your Ubuntu configured and installed LEMP stack! Ready to go with WordPress install!
You will need to do
- Create a MySQL Database and User for WordPress
- Download WordPress to your Server
- Configure WordPress
- Copy the Files to the Document Root (from your user folder to document root)
- Modify Nginx Server Blocks
- Open up your site on web browser and finish installation
This article will walk you through all those steps.
** At this point, you have a fresh WordPress website running on your Ubuntu Server.
Try running your site on Google pageload speed tool or https://loader.io/ to see what performance you get. You can compare this result with the result you will get after you applying your theme and activating some plugins you might need and migrating DB if you are moving your site.
Allow WordPress to download/update themes/plugins.
If you have trouble downloading/updating themes or plugins from admin panel, run below command to change permission.
`chown -Rf www-data.www-data /var/www/html/`
Having trouble uploading files from FTP(FileZilla)?
- add user “demo” to group “www-data” (Replace demo with your username) `sudo usermod -a -G www-data demo`
- set permissions for user group www-data `sudo chgrp -R www-data /var/www/html`
- Run `sudo chmod -R g+w /var/www/html`
Optimize Nginx Configuration for better performance
** Postfix and SSL
If you want your WordPress to send out email such as account validation or any notice email by wp_mail() or mail() functions, you need to install Postfix or Sendmail.
As far as I researched, Postfix has more popularity over Sendmail and known to be perform better.
– Install and set up Postfix on your server
– Create an SSL Certificate on Nginx for Ubuntu 14.04
Also check out WordPress migrate plugins if you are moving your site to DigitalOcean. It will make your work easier.
After moving your WordPress site, check your new WordPress site’s performance.
Setting up the Web server by yourself seems very intimidating and it still does to me. According to DigitalOcean, completing these steps will get you a decent web server for your WordPress site. However, you just have to look & play around with it to understand how things are working (at least I feel like it).
There are some scripts you can use to automate all these steps. If you like that approach, check out https://easyengine.io/. I wanted to learn and understand what is going on with my server so I will have ability to set up better server as I go on which made me to take me the long way and hoping one day I will get all this 🙂
List of things to go through
- Create backup folder (Need for the first time only)
- MySql backup
- WordPress folder backup (including theme and upload folder)
- Download files to desktop
- Remove backup files on remote server
- Create backup folder in remote server for sql files
- Run `mysqldump` command
mysqldump -uUSERNAME -hlocalhost -pPASSWORD DB_NAME | gzip -9 > /backup/mysql/BACKUP_FILE_NAME-`date +\%m\%d\%y`.sql.gz
- Check backup file is generated in `/backup/mysql` folder
This will backup all php files and media files in entire WordPress folder.
- Create backup folder in remote server for WordPress
- Get to the directory where you see the directory you want to archive and gzip (this will keep the backup file clean)
- Run command to archive, gzip and move the file to target location
tar czvfz /backup/wordpress/BACKUP_FILE_NAME-`date +\%m\%d\%y`.tar.gz NAME_OF_DIRECTORY_YOU_WANT_TO_ZIP
Try run this with `sudo` if you are getting error message of tar: Exiting with failure status due to previous errors
- Check backup file is generated in `/backup/wordpress` folder
rsync -a username@remote_host:/backup LOCAL_MACHINE_LOCATION
scp -r username@remote_host:/backup .
to download current location in local machine.
Remove backup files on remote server to save space
If you have enough space, feel free to keep your files in the server.