Here at PNL we had a problem with the sites ads.txt file recently. My ad vendor was telling me that it was being corrupted and my host was adding links that looked like I was behind a Barracuda. As I build the server from the ground up I knew this NOT to be the case.
Solution: Ads.txt Broken
The first thing I did was check the file I uploaded (from my LAPTOP before it was uploaded) and…
Which was exactly the same as when I checked the online version. So I was pretty sure I’d uploaded a broken one, I asked for a ‘known good working one‘ When the Engineer on the call said “Sometimes when these files are send via email a Barracuda will alter them”.
Penny Dropped
When I checked, I’d replied from my work email and the good folk at Newormedia had replied to that address, and indeed my coporate email address is behind a Baracuda. I asked them to send the file to my personal address, and hey presto!
Here’s a before and after for clarity
Related Articles, References, Credits, or External Links
Way back in 2004 when PeteNetLive started, I didn’t even consider monetisation of the site, it was simply a place for me to store my personal scribblings about problems I’d faced in support. But as it grew and it had to move from a second hand PC under my desk, to a dedicated server, then a rented VPS. The cost began to raise.
Back then there were a few ‘ad agencies’ but unless you were getting a LOT of traffic, they would not even let you though the door, but ANYONE could use Adsense, it was (and still is) the Advertising platform that Google provide.
How does Adsense Work: Simply you put some code in your web pages, then decide what ‘size’ you want those ads to be, you place the provided code where you want the ads to appear. Then once they’ve generated enough income (clicks) Google will send you the calculated profit for those.
Have we ever used any other Ad ‘Providers’? Yes, we’ve advertised directly for Vendors (Veeam was a great partner for many years, and it was only because I felt we ‘outgrew’ the relationship that we discontinued it this year). We also use ‘BuySellAds‘ who are also an alternative but take a larger slice of revenue for themselves and getting your money out of them is a manual process, that can take a few days. We have used MediaNet who just seemed to resell Adsense, and take a middleman cut, or put video adverts in, that adversely affected my site speed and performance.
Why Look at an to Adsense Alternative?
Well for me there were two reasons. My web traffic has gone up dramatically, but my income from the site hasn’t got up at the same speed, so I can only deduce Google are taking larger and larger slices, and doing not a great deal more to justify that commission. And secondly they are effectively the worlds biggest ad agency and they cant even sort out ad code compliance without expecting me to fix it for them. (If they’ve fixed that in the interim great, but it was the straw that broke the camels back for me.)
Newor Media (The best Adsense Alternative)
In Autumn of 2020, I got an email from Newor Media, asking if I’d be interested in using them, I get a massive amount of emails from ad networks, SEO experts, people wanting consultancy, etc. Ninety Nine percent of them just get ‘speed read’ and deleted, and so did the one from Newor Media, but they politely followed up and I replied.
Why Use Newor Media?
Well they differ from other ad networks, insofar as they exist to get the best revenue for your ad space. They do this by auctioning ad units to potential advertisers, (including Adsense) and other advertisers who are not using Adsense/Adwords. Plus when I have a query or a problem I can email a ‘person’ who responds and is helpful, (Kudos to Katie!), and can escalate things, and get support directly. If you use Adsense your only helpline is usually ‘Other users of Adsense’ which is frustratingly terrible! So I agreed to give them a trial run.
Whats Involved / How Difficult Is It To Setup?
To be accepted, you need to meet certain traffic levels (those being, 30k unique users per month, with the large majority of those being English speaking e.g. en-us, en-gb etc). Once accepted they sent you an Insertion Order (If you’ve hosted ads with other companies this will be routine,) for the uninitiated its the legal agreement between you the site host and the supplier (Newor) so READ IT, then sign, date, and return it).
From there on, it’s pretty much the same as for Adsense, you add some code you your sites HEAD section, and they (Newor Media) will send you a small code ‘snippet’ to post into where you want the Ad to appear. (In my case thats a mixture of WordPress’Widgets’, and for the main content wherever I tell ‘Ad Inserter’ to put them! You will also need to maintain an ads.txt file on the root of your website (this is simply a text file that periodically you have to update (copy and paste) some text into).
How Much More Than Adsense Will You Make?
The 64 thousand dollar question 🙂 Well Adsense rules dictate you are not allowed to disclose what you are earning, so I can’t give you a direct comparison BUT what I can do, is demonstrate how much more you would be making with Newor Media.
The graph above shows a comparison of BLUE Newor Media (Oct 20 to Mar 21) and GREY Adsense (Oct 19 to Mar 20). Bear in mind my YouTube earnings are included in the Adsense figures also!
Adsense Alternative: OK I’m sold, Where Do I Sign Up?
Providing you meet the 30k unique visitors a month (primarily English speaking) threshold. Note: You can get this information from Google Analytics: (Audience > Active Users > 28 Day Active Users) and (Audience > Geo > Language). Then you can apply (Click the link below and tell them PeteNetLive sent you!)
Related Articles, References, Credits, or External Links
Back when I did the website in Dreamweaver, this was a simple task, there was an ‘insert anchor’ button*. If you have a long webpages and you want your readers to be able to ‘navigate’ around it using hyperlinks, then ‘anchors’ are for you.
*In WordPress there is still a GUI option, on the insert menu, so you can still ‘insert anchor’ (see below).
What’s an anchor? Its simply a piece of code in a webpage that lets you ‘jump to / hyperlink’ to it, so you can get there from within the same web page, or straight to a specific part of a page, from another webpage. (like this)
Solution: Insert Anchor
Here I’m simply placing the anchor and nothing will be visible. If you are linking to a specific price of text you can use that as the anchor also;
Examples;
[box]Anchor with no text: <a id=”{anchor-name}”></a>
From the ‘insert menu’ choose ‘Anchor’ and supply a name.
How To Hyperlink to an ‘Anchor’
Normally when writing web pages/articles you will hyperlink to the URL of a web page, when linking to an anchor, the procedure is the same, but you supply the anchor on the ‘end’ of the URL and you specify it with a ‘#’ symbol. e.g. http://domain/page#anchor, but in WordPress you simply need to enter the anchor name and WordPress will understand that the link is within the same page.
like so;
Note: If the anchor is in ‘another’ web page, you will need to enter the full URL including the anchor text.
Related Articles, References, Credits, or External Links
Quite a few times after I rebuilt my server, (and WordPress site), I saw the following when uploading images etc.
HTTP Error
Solution
I was quite sure everything was setup OK, I had set the max file upload limits set, but it turns out I needed to add a ‘memory limit’ in my wp-config.php file before the error ceased. For completeness I’ll include the other usual suspects, in case yours is setup a little differently from mine.
Edit Your php.ini File
Note: If you are running an earlier version of php, your path may be different.
A few weeks ago I did a series on setting up a new WordPress site, shortly after I had some problems uploading my caching plugin (wp-rocket). This was the error I got;
413 Request Entity Too Large
nginx/1.10.3 (Ubuntu)
Anyway, I fixed the error, and a few days later I got an email from someone with the same problem, so I thought this time I would document the fix.
Solution
Note: I’m going to raise the limits to 100Mb this might be far to large for you, 20 or 50Mb might be more sensible for most sites.
Firstly you need to make an entry in the nginx.conf file
[box]sudo nano /etc/nginx/nginx.conf[/box]
If you’re unused to working in these config files, you are looking for the http section, just before this sections ends (i.e. before the end curly bracket ‘}’), insert the following text.
[box]client_max_body_size 100M;[/box]
Exit and Save the file (ctrl+x, then ‘y’ {Enter}.
Restart nginx.
[box]sudo service nginx restart[/box]
You will also need to enter the new values in the php.ini file.
[box]sudo nano /etc/php/7.0/fpm/php.ini[/box]
Change the following values, like so;
upload_max_filesize = 100M
post_max_size = 100M
Exit and save the file, then restart PHP.
[box]sudo service php7.0-fpm restart[/box]
Related Articles, References, Credits, or External Links
So you want your own web server running WordPress? Previously in Parts One and Two, we setup a new Linux box, and got all the prerequisites installed. Now it’s time to deploy WordPress.
Solution
There are a few extra bits we need to add to the PHP installation before we setup WordPress, to get those installed run the following command;
We are going to use the /tmp directory and download wordpress into that, you don’t need to worry about what version to download because the good folk at WordPress use the same URL for the latest version and keep it updated.
[box]
cd /tmp
curl -O https://wordpress.org/latest.tar.gz
[/box]
If you didn’t already guess from the file extension, the WordPress files are compressed, we need to ‘extract’ them.
[box]tar xzvf latest.tar.gz[/box]
WordPress has a file called wp-config.php in the root of the website that we will be editing in a while, so we are going to create that file by using the ‘sample’ file provided.
And, to save you hassle, (in future) we will pre-create the folder that WordPress will need when you eventually come to upgrade it, it will also, (after we have moved it in a minute), have the correct permissions.
Now we have all the files, but they are in the WRONG PLACE, they are all sat in the /tmp directory, but we want them in the root of your website, i.e. the /var/www/html directory. So to copy them (in bulk).
[box]sudo cp -a /tmp/wordpress/. /var/www/html[/box]
You won’t see anything happen, but if you have a look in your /var/www/html directory, the files will be there.
To set the correct permissions, execute the following commands;
COPY THAT TEXT TO THE CLIPBOARD (Yours will look different to the one above!)
Now edit the wp-config.php file, when its open go the the section that ‘looks like’ the text you copied above and paste your text over the top.
[box]nano /var/www/html/wp-config.php[/box]
While you are still in the file, you need to enter the database settings you setup in Part One. Near the top of the file you will see there’s a space for database name, username and password.
Enter your settings;
Save and close the file.
Now if you browse to your website, you should see the WordPress language selection, select your language and enter the settings and logon details for your website.
You will be logged into your sites admin panel (http://your-site/wp-admin). From here you can install new themes, add new plugins, and create new posts. Your website will now be ‘live’.
You may want to consider raising the maximum upload limit before proceeding;
Now the test if the web server is up and running, get the IP address (ifconfig), and browse to the IP address and you should see the nginx welcome page.
Note: If you get a 403 error, issue a ‘cp index.nginx-debian.html index.html‘ command and try again.
sudo systemctl start php7.0-fpm
systemctl status php7.0-fpm
[/box]
Now to enable nginx to pass information to the FastCGI server (allows php scripts to be executed outside the web server). Your nginx install should be taking its settings from a configuration file ‘/etc/nginx/sites-enabled/default’. To make sure execute an ‘nginx -t’ command. We need to edit that file.
Note: Below you will want to change the values in red to match your server, and the values in blue are optional. You can remove all the contents of the existing file and paste in the following.
# Default server configuration
server {
listen 80 default_server;
listen [::]:80 default_server;
# Set The Root Directory for the Entire Website
root /var/www/html/;
# Adding index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
# Add The Server IP Address or FQDN
server_name 123.123.123.12;
# Auto Remove and re-write .htm from requests (to maintain old back-links)
rewrite ^(/.*)\.htm(\?.*)?$ $1$2 permanent;
# The following does the WordPress Rewrites for the permalinks
location / {
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?$args;
}
# Allow the user to Cache Static files for 1 year
location ~* .(jpg|jpeg|png|gif|ico|css|js)$ {
expires 365d;
}
# pass PHP scripts to FastCGI server
location ~ \.php$ {
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
include snippets/fastcgi-php.conf;
}
}
[/box]
Now save and exit the file, make sure its ok by running;
[box]nginx -t[/box]
Providing it says ‘successful’ restart nginx.
[box]sudo systemctl reload nginx[/box]
Testing PHP7 Works
Make sure we are up and running on version 7.
[box]php –version[/box]
Now just to be sure we are going to create a test page, put in some PHP and make sure it works.
Create a file;
[box]sudo nano /var/www/html/test.php[/box]
Pete in the following;
[box]<?php phpinfo(); ?>[/box]
Save and exit the file, then browse to http://{ip-address}/test.php it should look something like the image below.
It’s considered bad practice to have that file on the server, so lets delete it with the following command;
[box]sudo rm /var/www/html/test.php[/box]
That’s us with a fully functioning nginx web server thats processing PHP, in part three we will install WordPress, connect it to the database we made easier, and then you will be ready to start posting.
Related Articles, References, Credits, or External Links
At the time of writing this site is running on CentOS7 LAMP (Linux Apache MySQL and PHP). Well I’m actually using MariaDB not MySQL as it’s ‘supposed’ to be a little faster, but they are similar enough to be accepted. I’m planning to migrate to Ubuntu 17 LEMP (Linux ‘EnginX’ MySQL and PHP) again with MariaDB. As the site is getting more traffic I want to utilise the better performance of nginx (I know I called it EnginX above but LNMP stack doesn’t sound so good, and nginx is ‘pronounced ‘engine x’).
So the following series of articles will be how to install nginx, MariaDB, PHP and WordPress.
Solution
Installing Linux
You have essentially two choices, do what most people do and go to a hosting company and rent a VPS, (virtual private server) for a monthly fee. Then when you set it up you can select what flavour of Linux you require, press go, and by the time you have had a coffee, they will have emailed you the IP and logon details, and Linux is already installed for you. You can of course install linux on your own server, and as long as you can make it publicly available use that.
The main difference is, if your hosting company build it for you, the root user will be enabled and you will connect with the root user and password. If you build your own server you will connect with user account and root will be disabled. If you know nothing about Linux that means to execute any system level commands you need to prefix them with ‘sudo’ (or type su and enter the root password). If you are logged in as root and use sudo it does not make any difference so I will prefix all the commands I use below with sudo to make things easier, just remember the first time you use sudo it will ask for your password again.
Why Ubuntu? Well I use CentOS presently, but while doing research there was little information on getting nginx and PHP7 running on CentOS, but there was for Ubuntu that’s the only reason I’m switching OS.
Update The Server
It might have been built from an image, but that does not mean that the image was up to date, thankfully that’s simple to do, run the following command to see if there’s any updates.
[box]sudo apt update[/box]
In my example theres two updates, I can upgrade to them with the following command, (you may be asked to answer ‘y’ for yes);
[box]sudo apt upgrade[/box]
Change the Linux SSH Port
Note: If you built the server, you may need to install openssh server.
[box]sudo apt-get install openssh-server[/box]
I’ve had servers compromised in the past so let’s start with some basic security, I always change the default SSH port, in this example I’ll use 2223 (instead of the default SSH port of 22).
Edit the SSH config file;
[box]sudo nano /etc/ssh/sshd_config[/box]
Uncomment and change the Port number to something other than 22, (make it above 1024 to be on the safe side, I’m using 2223).
Note: If you built your own server, and you are allowing root access to SSH you may want to see the following article;
Traditionally Linux uses iptables, (or FirewallD for CentOS.) I like iptables, because like all things Linux I worked out how to set it up, and wrote it down. Ubuntu has a ‘front-end’ to iptables thats still command driven, it’s called UFW (uncomplicated firewall). Which I didn’t want to learn about because I use iptables! But in all honestly UFW is so simple it’s painfully easy.
I want to allow TCP 80 (http), TCP 443 (https), and TCP 2223 (for my SSH server). And that’s it, block everything else incoming, allow the server to speak out, and secure the server.
Note: If it looks like it’s frozen, press Ctrl+C to get the cursor back
Set MariaDB to start when the server restarts;
[box]systemctl enable mariadb[/box]
Secure MariaDB: At the moment MariaDB will have a blank root password, (it has its own root user). So to secure it you simply run;
[box]sudo mysql_secure_installation[/box]
Note: It immediately asks for a password, (it will be blank so hit (Enter},) answer ‘Y’ to set a root password, set a fresh one (you will need it in a minute, so remember what it is!) Then accept all the defaults by just pressing {Enter}.
Create Your WordPress Database
WordPress needs a database, to get WordPress talking to MariaDB (or MySQL) you need three things;
A database name.
A username to access the database.
A password for that user.
So in the following example I will use;
Database Name: PETESDATABASE
Username: petesuser
Password: P@ssword12345
Execute the following commands one by one;
[box]
sudo mysql -u root -p
{Enter the root password you just set for MariaDB}
CREATE DATABASE PETESDATABASE;
CREATE USER 'petesuser'@'localhost' IDENTIFIED BY 'P@ssword12345';
GRANT ALL ON PETESDATABASE.* TO 'petesuser'@'localhost' IDENTIFIED BY 'P@ssword12345';
FLUSH PRIVILEGES;
exit
I have to say before I start, that most of the credit for this article lies with Allen White from www.techieshelp.com. Who gave me the three most important pieces of information that you need to migrate your WordPress site.
Three Things You Need;
The contents of your wp-content directory.
The contents of the root of your site.
A backup of your database, (this is a lot easier than you think).
Now there may be a couple of exceptions, for example, if your site runs https you might also need a copy of your certificates, and if you have any sub-folders in your site you will also need a copy of those folders as well.
Would it be easier to get an application or plugin to do this for me? Well I use UpdraftPlus and I also use BackWPup (both of which are free). But to be honest you just need access to the site from an FTP/SFTP client (I prefer FileZilla, again because it’s free), or you can simply use WinSCP, (again free).
Solution
Before You start: You need a WordPress server setup with a blank install of WordPress ready to accept your data. I’m not covering that in this article. This article is primarily to cover migrating your site contents. (Though watch this space, I’m going to post a full, WordPress install on LEMP article soon).
To make things simple, set the new database with the same name, username, and password, (get these from your live sites wp-config.php file).
I would also update your live site to the latest version of WordPress before you migrate, Or when you connect you may see a dialog about updating the database and have a bit of downtime.
Backup Your WordPress Data
First connect to your live website and download a copy of your ‘wp-content’ folder;
Note: The more eagle eyed among you will notice I’ve got an ‘extra’ folder in my site, called ‘KB’ that folder will also need downloading.
Now download ALL the files in the root of your website.
Now to get a copy of your database, you will need to know what it’s called, if you have forgotten, open your wp-config.php file (it’s in the root of your website,) with a text editor, and look for the following;
[box]
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'NAME-OF-YOUR-DATABASE');
[/box]
You will also need the root password for your SQL installation, it will be blank unless you have changed it when you installed MySQL or MariaDB, (by running ‘sudo mysql_secure_installation‘).
Connect to your server via SSH or log directly onto it’s console; and run the following command;
Supply the password and a backup of the database will appear in the folder you are in, (download that also).
I don’t know the SQL Root Password? You can get the username and password that the SQL user uses, (again from the wp-config.php file, and use (mysqldump -u {username} -p {password} {database name} > data-dump.sql).
Restoring Your WordPress Data
Database
Now connect to your new WordPress site with your FTP/SFTP client, and upload the data-dump.sql file.
Connect to your site via SSH, and navigate to the directory you have just uploaded the data-dump.sql file to. You can import the data into your new database with the following command;
Note: The command is the same as above, but note this time you use the ‘less than’ symbol.
Supply the root password for the destination SQL server.
Data
Restore the contents of your wp-content folder that you backed up earlier directly over the top of the wp-content directory on the new server.
Repeat for any other folders BUT NOTwp-admin or wp-includes.
What this does;
Restores your theme(s) and CSS files.
Restores your plugins.
Restores your WordPress users, and passwords
Restores all your posts/pages and media
Restores all comments.
Finally restore the files that are in the root of your website, (except the wp-config.php file, as I’m assuming the new site already has a new wp-config.php file with all the right settings in it).
Can this be done any quicker? Yes if you use the BackWPup plugin, you can get it to do a backup of SQL for you, and backup all the files and folders in your site. I back these up to DropBox automatically, so every day they are already on my laptop, this saves me having to download everything. It also means I can rebuild my website if my web server breaks.
Related Articles, References, Credits, or External Links
I’m in the process of migrating the site back to its original VPS now that the site re-write and redesign has been completed. I used a plugin (UpdraftPlus) to backup the site, and its database, and then restored it to the new server. After the restore I connected to the new server and there was the site in all its glory 🙂
However, every single link I clicked gave me a;
Not Found
The requested URL {Path} was not found on this server
Solution
I struggled with this for a long time, internet searches all said, this is common, it’s because WordPress needs to update its ‘permalinks’, and it needs to write some code to the .htaccess file to do this.
WordPress will add the lines it needs, if you go to Settings > Permalinks, enter your setting, and click save. If it can’t write to the .htaccess file, then it will tell you and show you the code that needs adding, if that happens you have a permissions problem and WordPress has not got the rights to update the .htaccess file.
After much trial and error I deduced permissions were ok, and so was the .htaccess file and the permalink settings.
My problem was the mod_rewite module was not enabled for my website, and even though I’d got WordPress set up correctly Apache web server wasn’t letting the rewrite happen.
On my web server (CentOS7) I needed to edit the http.conf file. (I’m using nano, substitute vi for nano, if you don’t have it installed).
[box]
nano /etc/httpd/conf/httpd.conf
[/box]
Locate the section, that is for the directory /var/www/html, and edit the AllowOveride so that it is changed from None to All.
(WARNING: there will be a few AllowOverrides, change the correct one).
Save and exit the config file, then restart Apache
[box]
/sbin/service httpd restart
[/box]
Related Articles, References, Credits, or External Links