I upgraded my server from Ubuntu 12.04 LTE to 14.04 LTE. But after that, I cannot access my wordpress site any more. This gave a headache for a whole night. After trying tons of methods, finally I figured it out how to resolve it. But still not sure what happened though. So my issue is I keep getting “cannot connect to database” error.
First of all, I tried to check if mysql is installed correctly, and see if I can log in mysql using root. The answer is yes. But strangely I cannot log in using the user name and password wordpress is using. I also checked mysql wp_* tables, and they are all there. So it must be something with user name and password. I basically tried all method on http://www.wpbeginner.com/wp-tutorials/how-to-fix-the-error-establishing-a-database-connection-in-wordpress/. But no matter I access www.ycshao.com or www.ycshao.com/wp-admin or http://www.ycshao.com/wp-admin/maint/repair.php, I always get “cannot connect to database”.
I know it’s something wrong with my wp-config.php, but I couldn’t figure out why. So I tried following solution which worked eventually for me.
I backed up old wp-config.php, and it will let you generate new wp-config.php.
$mv wp-config.php wp-config.php.back
When I accessed www.ycshao.com, the initial setup screen showed up! I tried to setup database name, user name, password, database host and table prefix according to DB_NAME, DB_USER, DB_PASSWORD, DB_HOST and table_prefix variables in wp-config.php. But no luck, I still could not connect to database.
It works perfectly on dev version of my django site. But when I deploy it to production (served by apache), I realized that css is missing for admin pages. Then I digged a little deeper to see what I could do to solve this issue. It actually quite simple. There are two files you need to modify.
# create 'static' folder in your app if you haven't done so,
# which will be in the same level of your settings.py file.
here STATIC_ROOT will be the folder where django will copy all admin static files. STATIC_URL will corresponding to the alias name in your apache config file. Don’t worry, keep reading and it will be clear to you.
Go to your django site directory and run
This will copy all static files including admin css, image, js files into your STATIC_ROOT. Now check your “static” folder, you should see “admin” folder which has “css”, “img” and “js” sub-folders.
Modify corresponding apache config files under /etc/apache2/sites-available/ folder.
where “/static/” is your STATIC_URL and “/dir/to/your/static/” will be the location of your “static” folder which is your STATIC_ROOT.
You are all set! Restart your apache and checkout your admin page.