Set up server

Recently I have been working on a project to set up a customized Wiki with MediaWiki. It is a new challenge for me because it is the first time that I am building a dynamic website that requires the setup of a server.

The end goal is to host it on Azure, but there have been some challenges in using either a web app or a virtual machine. So I decided to localize the issue and first set up the website on a local machine. This will separate problems of cloud computing from setting up website and server and setting up locally will also provide me a few GUI tools to easily experiment with.

The biggest problem faced today is the set-up of MySQL server. The LAMP on my computer was installed more than half a year ago for me to test Shiny app installation. Because those were not properly documented (lesson learned!), I have forgotten most of the set-up. The importance of documentation cannot be stressed further, especially when adjusting system settings that I am not familiar with. This is because when I set those configurations, I mostly just follow the instructions online and not documenting what has been done can result in problems from incompatibility (bugs) to security issues.

  1. MySQL The first issue occurs when trying to log in to MySQL server. mysql -u root -p
  • First error:
Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2 "No such file or directory")

Resolved by this document.

sudo service mysql stop
sudo service mysql start
  • Second error (same command):
mysql "ERROR 1524 (HY000): Plugin 'unix_socket' is not loaded"

Resolved by a combination of this and this solution. 1.

sudo su
/etc/init.d/mysql stop
  1. sudo nano /etc/mysql/my.cnf

  2. Add the following lines at the end:

  3. sudo service mysql restart

  4. mysql -u root

  5. use mysql

  6. select * from mysql.user where user = 'root'; - Look at the top to determine whether the password column is called password or authentication_string

In my case it is called Password.

  1. UPDATE mysql.user set *password_field from above* = PASSWORD('your_new_password') where user = 'root' and host = 'localhost'; - Use the proper password column from above

UPDATE mysql.user set Password = PASSWORD('your_new_password') where user = 'root' and host = 'localhost';

  1. exit

  2. sudo nano /etc/mysql/my.cnf

  3. Remove the lines added in step 2 if you want to keep your security standards.

/etc/init.d/mysql stop
kill -9 $(pgrep mysql)
/etc/init.d/mysql start

For more info on kill -9, see here. The command actually returned format error but I think that is because all processes with $(pgrep mysql) have been closed.

  1. exit

Update on 20200511

The LAMP server is finally set up on the remote ubuntu computer today. The overall process should not have been so challenging, because I could set it up quite easily on my personal ubuntu PC. However, the difficulty is that the remote computer had a different version of ubuntu installed, and the online tutorials did not help because of the recent updates on MySQL server that prohibits login using root unless the user is in the root mode

Instruction-wise, follow this documentation to install lamp and phpmyadmin. I set up a database and password when installing phpmyadmin. Use that password and username phpmyadmin to log in either localhost/phpmyadmin or mysql -u phpmyadmin -p (in normal user). This should set up the server properly. If not, keep reading.

So I had a big trouble because I installed the whole LAMP under another user (the default root user) one year ago and I unknowingly installed another layer of LAMP under the current user (another normal user with sudo authority). The whole server was broken in at least two ways. First, it cannot render .php code. Second, log in to mysql is difficult (as explained before the updates today) and never really worked properly. It was resolved by

  1. stop the service. sudo kill $(pgrep mysql)
  2. purge the software. There are many solutions on various websites, and according to the comments and votes some worked and some did not. So I think the key here is really to follow the lessons below. Read each solution carefully, adapt the solutions if needed (e.g. to your specfic version) and always look at multiple solutions and comments before you decide which one to use. Always document. Resources at the bottom contain solutions that I have trialed and erorred but they may not work again as things are updated. One quick example on adaptation, say you want to uninstall php, sometimes you may have to try php, php7, php7.*. Things can get even more complicated for mysql since there are both server and client packages.
  3. delete the folders, according to an old, potentially outdated documentation
  4. (optional) adjust permission. It might only be an isolated problem but if there is any error similar to this appearing, try the soltuion.

Overall, I think I have learned a few lessons from this whole experience.

When looking at any existing solutions, 1. always check official documentation first 1. check that the problem is the same. 1. check that the version of software is the same. 1. learn the general principles, for example, usergroup and permission in this case, under all circumstances and understand specific code if possible. 1. know how to revert the action action befor eyou do it. Linux does not have a redo button and cannot easily remove packages with one uninstall button in Windows. 1. document. This cannot be stressed enough and there must be a better way than my current practice 1. check the results of the code run - always look for errors 1. most importantly, learn to live with bugs. There will still always be bugs even if you follow all the above steps, so you got to live with them and follow the above steps when trying to solve them so you do not create new bugs as a result.


Apparently there are some issues now (20200511) with vscode. When I tried to install mysql plugin it first said it failed beacuse Permission denied. It could not load ~/.vscode/extensions/.obsolete. I suspect that could be a user permission issue and checked. I found that all files but two - a python exnteision that I installed just to check the permission, and failed and .obsolete files belong to root:root. So I use chown username:user_group file to change the permission. Now it can be installed successfuly but loading again is an issue. I suppose it is not really an urgent issue to be resolved now, but I will document it for future reference.


Personalizing medicine