Showing posts with label ubuntu. Show all posts
Showing posts with label ubuntu. Show all posts

Tuesday, August 4, 2020

Move an Apache Web Root Directory to a New Location on Ubuntu

How To Move an Apache Web Root Directory to a New Location on Ubuntu 

From https://www.digitalocean.com/community/tutorials/how-to-move-an-apache-web-root-to-a-new-location-on-ubuntu-16-04

Prerequisites

To complete this guide, you will need:

  • An Ubuntu 16.04 server with a non-root user with sudo privileges. You can learn more about how to set up a user with these privileges in our Initial Server Setup with Ubuntu 16.04 guide.

  • An Apache2 web server: If you haven’t already set one up, the Apache section of the in-depth article, How To Install Linux, Apache, MySQL, PHP (LAMP) stack on Ubuntu 16.04, can guide you.

  • A new location for your document root: The new document root location is completely configurable based on your needs. If you are moving your document root to a different storage device, you will want to select a location under the device’s mount point.

In this example, we will use the /mnt/volume-nyc1-01 directory. If you are using Block Storage on DigitalOcean, this guide will show you how to mount your drive before continuing with this tutorial.

Step 1 — Copying files to the new location

On a fresh installation of Apache, the document root is located at /var/www/html. If you’re working with an existing server, however, you may have a significantly different setup including multiple document roots in corresponding VirtualHost directives.

You can search for the location of additional document roots using grep. We’ll search in the /etc/apache2/sites-enabled directory to limit our focus to active sites. The -R flag ensures that grep will print both the DocumentRoot and the filename in its output:

  • grep -R "DocumentRoot" /etc/apache2/sites-enabled

The result will look something like the output below, although the names and number of results are likely to be different on an existing installation:

Output
sites-enabled/000-default.conf DocumentRoot /var/www/html

Use the feedback from grep to make sure you’re moving the files that you want to move and updating their appropriate configuration files.

Now that we’ve confirmed the location of our document root, we’ll copy the files to their new location with rsync. Using the -a flag preserves the permissions and other directory properties, while-v provides verbose output so you can follow the progress.

Note: Be sure there is no trailing slash on the directory, which may be added if you use tab completion. When there’s a trailing slash, rsync will dump the contents of the directory into the mount point instead of transferring it into a containing html directory:

  • sudo rsync -av /var/www/html /mnt/volume-nyc1-01

Now we’re ready to update the configuration.

Step 2 — Updating the configuration files

Apache2 makes use of both global and site specific configuration files. For background about the hierarchy of configuration files, take a look at How To Configure the Apache Web Server on an Ubuntu or Debian VPS.

If you’re working with an existing installation, you should modify the virtual host files you found earlier with the grep command. For our example, we’re going to look at the two Virtual Host files that ship with Apache by default, 000-default.conf and default-ssl.conf.

We’ll start by editing the 000-default.conffile:

  • sudo nano /etc/apache2/sites-enabled/000-default.conf

Next we’ll find the line that begins with DocumentRoot and update it with the new location.

Note: You should look for other places the original path showed up, and change those to the new location as well. With a default installation, there’s the DocumentRoot and a Directory block you’ll need to change. On an existing installation, you may find things like aliases and rewrites that need updating, too. Wherever you see the original document root’s path in the output of grep, you’ll need to investigate.

/etc/apache2/sites-enabled/000-default.conf
<VirtualHost *:80>
        ServerAdmin webmaster@localhost
       DocumentRoot /mnt/volume-nyc1-01/html
        <Directory />
                Options FollowSymLinks
                AllowOverride None
       </Directory>
      <Directory /mnt/volume-nyc1-01/html/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Require all granted
        </Directory>

Step 3 — Restarting Apache

Once you’ve finished the configuration changes, you can make sure the syntax is right with configtest:

  • sudo apachectl configtest

You will get feedback from apachectl configtest with a fresh install:

Output
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message Syntax OK

As long as you get Syntax OK, restart the web server. Otherwise, track down and fix the problems it reported.

Use the following command to restart Apache:

  • sudo systemctl reload apache2

Wednesday, May 20, 2020

Install cuda 10.2

1. Uninstall existing nvidia driver

nvidia-installer --uninstall

or

The correct way to uninstall just cuda and keep your nvidia drivers would be:
sudo apt purge "libcublas*" "cuda-*" cuda
Possible, because they were installed as requirements, you can also purge,
sudo apt purge "nsight-*" nvidia-modprobe
After that you can, if you want, also remove the nvidia drivers with:
sudo apt purge "*nvidia*"
Of course, if you installed cuda using nvidia's .run file then this won't work; in that case you probably have some uninstall script.

2. Close X server
# To stop:
sudo init 3
# To resume:
sudo init 5
3. Download & install
wget http://developer.download.nvidia.com/compute/cuda/10.2/Prod/local_installers/cuda_10.2.89_440.33.01_linux.runsudo sh cuda_10.2.89_440.33.01_linux.run

Thursday, May 14, 2020

Screen permission denied


Problem
Cannot make directory '/var/run/screen': Permission denied
Solution
sudo /etc/init.d/screen-cleanup start

Thursday, March 5, 2020

Change ssh port for ubuntu

  1. Edit the file and set Port option

    Type the following command:
    $ sudo vi /etc/ssh/sshd_config
    Locate line that read as follows:
    Port 22
    OR
    #Port 22
    To set the port to 2222, enter:
    Port 2222
  2. Updating your firewall to accept the ssh port 2222 in Linux

    If you are using UFW on a Ubuntu/Debian Linux, type:
    $ sudo ufw allow 2222/tcp
    The syntax for iptables is as follows
    $ sudo /sbin/iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 2222 -j ACCEPT

  3. OR if you are using Ubuntu/Debian/Mint Linux:
    $ sudo service ssh restart
Test
ssh xxxx.xxxx.xxxx.xxxx -p 2222

Monday, September 16, 2019

Ubuntu boot to initramfs


Problem:
Ubuntu cannot boot normally but drop to initramfs. The reason is some part of filesystem is broken, so we need to fix.
BusyBox v1.18.5 (Ubuntu 1:1.18.5-1ubuntu4) built-in shell (ash)
Enter 'help' for a list of built-in commands.

(initramfs)

Solution write the command of fsck /dev/sdax like the below and give Y if the console ask for fixing something:
(initramfs) fsck /dev/sda1
or
(initramfs) fsck /dev/sdaX
X specifies mounted disk part number.
If you don't want to manually press 'y' every time it asks for a fix, you can also run the command with the -y option.
(initramfs) fsck /dev/sdaX -y

Monday, October 22, 2018

ISSUE: Failed to start reboot.target: Connection timed out

When rebooting

Failed to start reboot.target: Connection timed out
See system logs and 'systemctl status reboot.target' for details.

Solution
$ sudo systemctl --force --force reboot

Thursday, June 28, 2018

Ubuntu mount local network shared folder

Server end

  • Install Samba
    • sudo apt-get update
      sudo apt-get install samba
  • Set a password for your user in Samba
    • sudo smbpasswd -a <user_name>
      • Note: Samba uses a separate set of passwords than the standard Linux system accounts (stored in /etc/samba/smbpasswd), so you'll need to create a Samba password for yourself. This tutorial implies that you will use your own user and it does not cover situations involving other users passwords, groups, etc...
        Tip1: Use the password for your own user to facilitate.
        Tip2: Remember that your user must have permission to write and edit the folder you want to share.
        Eg.:
        sudo chown <user_name> /var/opt/blah/blahblah
        sudo chown :<user_name> /var/opt/blah/blahblah
        Tip3: If you're using another user than your own, it needs to exist in your system beforehand, you can create it without a shell access using the following command :
        sudo useradd USERNAME --shell /bin/false
        
        You can also hide the user on the login screen by adjusting lightdm's configuration, in /etc/lightdm/users.conf add the newly created user to the line :
        hidden-users=
  • Create a directory to be shared
    mkdir /home/<user_name>/<folder_name>
  • Make a safe backup copy of the original smb.conf file to your home folder, in case you make an error
    sudo cp /etc/samba/smb.conf ~
  • Edit the file "/etc/samba/smb.conf"
    sudo nano /etc/samba/smb.conf
    • Once "smb.conf" has loaded, add this to the very end of the file:
      
      [<folder_name>]
      path = /home/<user_name>/<folder_name>
      valid users = <user_name>
      read only = no
      Tip: There Should be in the spaces between the lines, and note que also there should be a single space both before and after each of the equal signs.
  • Restart the samba:
    sudo service smbd restart
  • Once Samba has restarted, use this command to check your smb.conf for any syntax errors
    testparmT

Client end

  •  access your network share
          sudo apt-get install smbclient
          # List all shares:
          smbclient -L //<HOST_IP_OR_NAME>/<folder_name> -U <user>
          # connect:
          smbclient //<HOST_IP_OR_NAME>/<folder_name> -U <user>
    To access your network share use your username (<user_name>) and password through the path "smb://<HOST_IP_OR_NAME>/<folder_name>/" (Linux users) or "\\<HOST_IP_OR_NAME>\<folder_name>\" (Windows users). Note that "<folder_name>" value is passed in "[<folder_name>]", in other words, the share name you entered in "/etc/samba/smb.conf".
    • Note: The default user group of samba is "WORKGROUP".
 2. mount 
sudo mount -o username=<> //172.29.32.184/sharename /media/Data/

for windows
sudo mount -t cifs -o username=<> //172.29.32.184/sharename /media/Data/
  • Note- If you receive the error: wrong fs type, bad option, bad superblock on... make sure you have cifs-utils installed, it may not be installed on your distro by default.
    sudo apt-get install cifs-utils