Featured image of post Changing the Storage Locations for Websites and MySQL Under LNMP

Changing the Storage Locations for Websites and MySQL Under LNMP

There are primarily two scenarios for changing the storage locations: 1. If you haven't started installing LNMP yet and you are preparing in advance. In this case, it's relatively straightforward. Solution: Just…

The changes in storage locations primarily fall into two scenarios:

1. Preparing to Change Locations Before Installing LNMP. This is relatively simple. The solution is:

Simply modify the lnmp.conf configuration file in the LNMP installation package directory.

Changing Storage Locations for Websites and MySQL Under LNMP

Change MySQL_Data_Dir to your desired location, and Default_Website_Dir to the new website storage location.

2. Changing the Storage Directory for Websites and MySQL After LNMP Installation

Changing the Website Storage Directory: You only need to modify the configuration file of the relevant virtual host. Change the directory listed after root to the new directory. Then execute the following commands: cp -a old_directory new_directory, and chown www:www -R new_directory.
(For LNMP 1.2, you also need to modify the directory in the .user.ini file located in the website directory. Refer to the explanation at the end under “Other Matters” on https://lnmp.org/faq/lnmp-vhost-add-howto.)

Changing the MySQL Directory:

  1. Stop the MySQL server with the command: /etc/init.d/mysql stop.

  2. Create a new directory. For example, create a new directory under /data/mysql/, and then execute: cp -a /usr/local/mysql/var/* /data/mysql/.

  3. Change the ownership of the new directory by running: chown mysql:mysql -R.

  4. Modify the configuration file: Under /data/mysql/, edit /etc/my.cnf, find the section [mysqld], and add datadir = /data/mysql/. Save the changes.

If you have InnoDB enabled, you also need to update innodb_data_home_dir and innodb_log_group_home_dir to the new /data/mysql, and then restart MySQL.

Once these changes are complete, restart LNMP by executing the command: lnmp restart.

Licensed under CC BY-NC-SA 4.0