Ubuntu 14 and LAMP can’t access WordPress website

Posted on

Problem :

I’ve installed LAMP under Ubuntu 14, placed a copy of my WordPress folder files under the /lampstack-5.6.30-0/apache2/htdocs/wordpress/ folder, started LAMP Apache, MySQL…yet each time I try to reach localhost/wordpress/ I get routed automatically to localhost:8888/wordpress/ and get error message

This site can’t be reached
localhost refused to connect.

I’ve tried many times to go to localhost:8080/wordpress or localhost/wordpress but I get routed back to localhost:8888/wordpress and see the error message shown above. Can someone please tell me what I might be missing here/ doing wrong? Thanks

Update 1:

Results of sudo netstat -lntp

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.0.1:2015          0.0.0.0:*               LISTEN      1348/expressvpnd
tcp        0      0 127.0.0.1:27017         0.0.0.0:*               LISTEN      1205/mongod     
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      4117/mysqld.bin 
tcp        0      0 127.0.0.1:28017         0.0.0.0:*               LISTEN      1205/mongod     
tcp        0      0 127.0.1.1:53            0.0.0.0:*               LISTEN      1924/dnsmasq    
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      2095/cupsd      
tcp6       0      0 :::8080                 :::*                    LISTEN      4277/httpd.bin  
tcp6       0      0 ::1:631                 :::*                    LISTEN      2095/cupsd      
tcp6       0      0 :::8443                 :::*                    LISTEN      4277/httpd.bin  

Solution :

Please try using 127.0.0.1:8080/wordpress instead and it should work. I’ve tried it here on my machine and I can access LAMP websites using the URL 127.0.0.1

Alright so this has driven me mad for weeks, but I’ve finally figured it out.

Mysql does not have permission to read and write unless you add it to the www-data group. When I tested this, I just made an html file called index.html and pointed apache to it, which worked fine, but once i used wordpress (or joomla), it died, so the problem had to be either in php or Mysql.

When mysql is installed, it is given the username mysql. This needs to be given some permissions over the wordpress files itself. PHP on the other hand is given a username, so if you select your own username, this will have to be added to the group as well.

When you set permissions on your wordpress folder, you give ownership and group permissions to www-data. Personally I changed mine to have the owner as my username on the machine, and www-data as the group. Now the problem is, www-data is an empty group.

You need to add both mysql and www-data (the username) to www-data (the group).
You can do that with the command
sudo adduser mysql www-data
sudo adduser www-data www-data
sudo adduser (yourusername) www-data

Now, assuming you gave permissions to the folders earlier, you should now be able to access this site externally. If not, try either
sudo chmod -R 775 /var/www/(folder) *or
sudo chmod -R 755 /var/www/(folder)

Leave a Reply

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