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.
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:
-
Stop the MySQL server with the command:
/etc/init.d/mysql stop
. -
Create a new directory. For example, create a new directory under
/data/mysql/
, and then execute:cp -a /usr/local/mysql/var/* /data/mysql/
. -
Change the ownership of the new directory by running:
chown mysql:mysql -R
. -
Modify the configuration file: Under
/data/mysql/
, edit/etc/my.cnf
, find the section[mysqld]
, and adddatadir = /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
.