WordPress VPS Permalinks 404 error

I recently moved my blog off Godaddy because i was having a whole bunch of issues when writing posts. I believe Godaddy sets a block on how many times you can publish. Perhaps their servers takes a hit from all the publishers writing content. If they are like me they save every 2 minutes! What happens is that after a few saves on your post, you begin to get server internal errors(504 Gateway Timeout Error). Go daddy claims it was my ISP but reading complaints on other forums i found out that many bloggers had this issue. So it wasn’t an ISP issue. I took action right away. I decided to host my own WordPress (and boy was it a nightmare). Found a VPS solution and installed WordPress from a backup i have made when i was using Godaddy. The only problem i had was my posts now had urls that were not so friendly. Updating permalinks to use the postname format wasn’t working. I would get a 404 error. I decided to document the steps i took to resolve this issue. Hope it works for you (worth a try if you have having similar issues). If you are using a VPS and want to install or reinstall WordPress, here are some steps that might help you. I will talk about reinstallation as well at the end of the post. I assume you are comfortable with the CLI (of course if you are using a VPS solution, that is the only way).

SSH into your VPS… and run these commands one by one

1) wget http://wordpress.org/latest.tar.gz (this will download the latest version of WordPress).

2) tar -xvf latest.tar.gz (this will unzip the WordPress file)

3) mysql -u root -p (log into mysql)

4) CREATE DATABASE wordpress; (create a database called wordpress. you can name it whatever you want)

5) CREATE USER myusername@localhost; ( create a database user in wordpress)

6) SET PASSWORD FOR myusername@localhost=PASSWORD(“MYPASSWORD”); (set a password for this user)

7) GRANT ALL PRIVILEGES ON wordpress.* TO myusername@localhost IDENTIFIED BY ‘MYPASSWORD’; (grant the user elevated access)

8) FLUSH PRIVILEGES; (flush permissions)

9) exit (exit mysql)

10) mv ~/wordpress/wp-config-sample.php ~/wordpress/wp-config.php (rename wp-config-sample.php to wp-config.php)

11) vi ~/wordpress/wp-config.php (go into this file and change the database, username and password as you created in mysql)

define(‘DB_NAME’, ‘wordpress’);
define(‘DB_USER’, ‘myusername’);
define(‘DB_PASSWORD’, ‘MYPASSWORD’);

12) Next, ensure that you have the following folder structure created on VPS server
sudo mkdir /var/www/html/example.com/

13) Set permission on www folder
sudo chown -R apache:apache /var/www/

14) Depending on folder structure on VPS, do either step A or B:
a) mv ~/wordpress /var/www/html/example.com/ OR
b) mv ~/wordpress /var/www/example.com/ (note there is no html folder in this server instance)

15) cd to /var/www/scriptonitejs.com/. Rename wordpress folder to public_html. If you Already have a public_html then copy the contents in wordpress into that folder. sudo mv ~/wordpress/* ../public_html/

16) Set permission on public_html folder
sudo chown -R apache:apache /var/www/html/example.com/public_html

17) This final step is very important! ensure that mod_rewrite is enabled:
Run this command: sudo a2enmod rewrite

If it fails or you get a command not found you have to modify the apache conf
Run this: vi /etc/httpd/conf/httpd.conf

Find the <Directory /var/www/> and <Directory “/var/www/html”> tags and
update the AllowOverride None to AllowOverride All. Update it in both tags

Then restart Apache:
sudo /sbin/service httpd restart

That should be all you need. If you are thinking about reinstalling WordPress (and already have content on your site), i highly suggest that you backup your WordPress site first. The same applies if you are thinking of moving your blog somewhere else. Having a backup is crucial. The best one i found was “UpdraftPlus Backup/Restore” for wordpress. You can easily find this. Install it and backup your data. You can store your data on a plethora of cloud solutions. Once your backup is ready you are safe to delete your WordPress folder and install a fresh one. You may also have to delete the WordPress database and user created initially. You can use phpmyadmin for that. Once installed edit the config

<RequireAny>
Require ip 127.0.0.1
Require ip ::1
Require all granted
</RequireAny>

The “require all granted” is needed to be able to access phpmyadmin in the browser. You should remove this change after you are done using the tool so others cannot access it (security reasons). You can also limit the access based on IP address.

Ok thats what i did. I hope this helps someone out there someday. Lets get back to writing our javascript posts. I am so excited i have my blog back!

2 Comments

  1. Gracias amigo eres un crack !!

    thank you friend are you the best! Greetings from Ecuador

    1. scriptonian

      You are welcome Jaime!!!

Leave a Reply

Your email address will not be published. Required fields are marked *