Finally, How to make your WP site faster
You are reading this article probably because you are are not happy with how your Wordpress site is performing. Most of the time the trick is to get better server response and that means migration to a better place.
Web Hosting Recommendation
Many people have asked me about the hosting I am using. To be honest I tried different hosting accounts from shared, VPS and dedicated. In case you want some really affordable hosting I recommend Bluehost. I am also hosting some of my Laravel projects right there on this $3.95 shared account and it works great.
Continue …
The list goes on and on for those who are having problems with their Shared Hosting. Websites are being hacked because your websites depend on the security of other people’s scripts that share that same server as well as the other guy on your shared hosting is wasting too much of your resources.
Having being frustrated with HostGator #theWorstServiceEver and having my old Wordpress sites hacked by Turks, I decided it’s time for a change.
As I have been using Amazon Web Services for a long time now, mainly for Laravel, I was simply too lazy to change something that was working just fine (even though I have been paying about $150 to HostGator annually).
Now when you decide to go into this, you will come across many tutorials that simply don’t work. After all, you don’t set up servers every day so it is OK to forget things. Don’t be too harsh to yourself.
The end result for you will be much secure website and also much faster at the same time because your new server is working ONLY for you!
Now, there is an official AWS tutorial on how to do this, but I ran into mysql socket errors. This is with Amazon Linux AMI btw.
I decided to use what I like the most, Ubuntu. With Ubuntu you have so many choices when it comes to packages whereas Amazon Linux is quite limited. And we are only installing a simple server to support one Wordpress site, so Ubuntu will be just fine.
Creating EC2 Instance
First thing you need to do is to create an EC2 instance. There are plenty of tutorials around this. A couple of notes is to import your own public key and create the instance using that key. Also, make sure you create and allocate a new Elastic IP. You will need that. If you don’t do that, then the next time you restart your EC2, your IP will change.
Login into your new EC2 Ubuntu instance
With Ubuntu AMI, ubuntu is a default user so you will use:
ssh ubuntu@your-ec2-ip
I am assuming your are in your .ssh folder so your previously uploaded key (Importing AWS ssh keys) is in there and will be recognised.
Installing things
Before you can do anything, you need to install a web server, php and mysql server.
sudo apt-get install apache2 php7.2 libapache2-mod-php7.2 php7.2-mysql mysql-server phpmyadmin apache2-utils
Make sure you run sudo su
you can operate in sudo mode.
You will get a couple of popups for phpmyadmin
. The first one is to select apache2 and the second one is to set a password for default phpmyadmin user.
More setup
Then you have gone through all of that, you want to run mysql_secure_installation
. In these steps, you can answer everything with YES.
The next step is to make sure our index.php
file will load properly.
Run the following command:
sudo vim /etc/apache2/mods-enabled/dir.conf
and set index.php
to be the first one to load
<IfModule mod_dir.c>DirectoryIndex index.php index.cgi index.pl index.html index.xhtml index.htm</IfModule>
followed by:
sudo vim /etc/apache2/apache2.conf
and adding this
<Directory /var/www/html>Options Indexes FollowSymLinksAllowOverride AllRequire all granted</Directory>
Make sure to enable all the recent changes sudo a2enmod rewrite
So far so good.
Setting up DB
Then let’s spend some time setting up a new user for our WP site, along with the database itself.
While in your EC2, run mysql
and start typing one by one command:
CREATE DATABASE wp_site_db;CREATE USER wp_db_user@localhost IDENTIFIED BY 'my_super_hard_pw!!2018';GRANT ALL PRIVILEGES ON wp_site_db.* TO wp_db_user @localhost;FLUSH PRIVILEGES;
At this point you can load up http://YOUR-EC2-IP/phpmyadmin
and log into the database using credentials from above.
Finally, let’s download the latest Wordpress installation. Type cd /var/www
and then:
wget https://wordpress.org/latest.tar.gz
and let’s unzip it:
tar -xzf latest.tar.gz
At this moment you are in /var/www
and you can see:
html
wordpress
latest.tar.gz
What you want to do is to remove html
folder and rename the wordpress to html
.
Then you need to transfer the ownership to ubuntu
user you have so it can see and operate the files under the html
folder.
chown -Rf ubuntu html
Wordpress DB Credentials
All what we are left to do is to create that wp-config.php
file that is used to read the DB credentials.
mv wp-config-sample.php wp-config.php
And edit it:
sudo vim wp-config.php
Under different DB placeholders (db name, db user_name, db_password) copy and paste your previously created credentials.
Now run http://YOUR-IP/
and you should see your WP installation page.
Note:
In order to have the permalinks work properly, make sure to create your .htaccess
vim .htaccess
And type:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress