Peter Pollock

Articles From Peter Pollock

5 results
5 results
Editing Files with Vi

Article / Updated 11-04-2021

Linux has a couple of very useful built-in file editors, and vi is one of them. It originated as a mode of a file editor called ex, which was a line editor that grew with the changes in technology until it had a visual mode that users activated with the command vi. Vi then became an editor itself, and you can call it directly from the command line. In Normal mode, a typed letter i is regarded as a command that puts vi into Insert mode. After vi is in Insert mode, though, a typed letter i (or any letter, for that matter) is not seen as a command; it is a request to make i the next letter in the file. There are dozens of different commands you can use in Normal mode, so the following is a quick example of how to edit a file. You can edit the file, move to the offending text, go into Insert mode, delete the bad text, type the correct letters, and then save and quit the file. Here are the steps: Select the file by typing vi index.php at the command line. This allows you to choose which file you need to edit. Use the arrow keys to move the cursor to the part of the file you want to change. The gray block (shown circled below) is the cursor. Move it with the arrow keys. Use the i command to enter Insert mode. As shown above, after pressing ; , -- INSERT -- appears to show you are in Insert mode. In this mode, anything you type becomes a part of the file. Use the Delete key and the letters on the keyboard to make the correction. The edits you make show live on the screen, as shown above. Once you have finished, you need to return to Normal mode. Press the Esc key to get back to Normal mode. You have to press the Esc key to switch from Insert mode to Normal mode. Type a colon (:) to move the cursor to the bottom of the screen. This is where final commands can be made. Type wq. wq is two individual commands: w for Write (or Save) and q for Quit. This command combination returns you to the command line.

View Article
How to Edit Files with vi

Step by Step / Updated 11-03-2021

Linux has a couple of very useful built-in file editors. Vi is a very useful one. It originated as a mode of a file editor called ex, which was a line editor that grew with the changes in technology until it had a visual mode that users activated with the command vi. vi then became an editor itself, and you can call it directly from the command line. In Normal mode, a typed letter i is regarded as a command that puts vi into Insert mode. After vi is in Insert mode, though, a typed letter i (or any letter, for that matter) is not seen as a command; it is a request to make i the next letter in the file. There are dozens of different commands you can use in Normal mode, so the following is a quick example of how to edit a file. You can edit the file, move to the offending text, go into Insert mode, delete the bad text, type the correct letters, and then save and quit the file. Here are the steps:

View Step by Step
How to Create a URL Redirect

Article / Updated 03-26-2016

Sometimes you might want to get a little creative with your web hosting and set up a specific URL to redirect somewhere. It doesn’t take long to do and can make the URL shorter, more memorable, or easier to spell. The following steps explain how to get more creative with redirects using cPanel: Log into cPanel using the details your host gave you when you first signed up. Scroll to the Domains section and click Redirects. Choose the type of redirect you want. Redirect choices are 301 and 302. These are standard numbers that the server uses to inform your browser of the redirect and give it more information so it knows what to do. A 301 redirect is a permanent redirect. This means that, as far as you know, this redirect will never change. Your browser then knows that it should update any bookmarks you have to the original URL. A 302 redirect is only a temporary redirect, which means you’re purposefully redirecting for a short time and this may be due to some maintenance or for a short-term project. The browser knows not to update its bookmarks because it needs to check every time you use the URL whether the redirect is still in place. Choose the domain name you want to redirect from the drop-down box. The drop-down box includes your primary domain and any add-on or parked domains under the account. Type the rest of the path to the file or folder you want to redirect. In the Redirects To box, type the full URL of the site, file, or page that you want to redirect to. You also need to include the protocol for the URL, which will normally be http://. Select what type of www. redirection you require. Normally this will be redirect with or without www. www. is normally simply the default hostname in your URL and your browser treats no hostname and www. as the same thing. It is possible to configure this differently, though, so that www. is a different page on your site. If that is the case on your site, you may need to choose one of the other www. redirection options. Select the Wildcard Redirect option, if desired. Wildcard redirects can be useful in certain circumstances, but are not always necessary. A wildcard redirect redirects to the same filename in the destination directory. This is useful if you change your domain name, but otherwise have your directory structure the same. For example, you might have a contact form for which your old URL was yourdomain.com/contact.htm and the correct new URL might be yournewdomain.com/contact.htm. The file structure is the same; only the domain name differs. In this case, if you do not use a wildcard redirect when somebody clicks a link or types into the browser yourdomain.com/contact.htm, instead of being redirected to the contact form on your new domain, that person would be redirected to the main page on your new domain (yournewdomain.com). If you do select wildcard redirect, though, the visitor will be redirected straight to the new contact form. This will not work if the filenames have changed. Click Add. Your redirect appears at the bottom of the screen. You cannot edit redirects; instead, you have to delete and re-create them. Redirects are done using commands placed in the .htaccess file in the document root of the main domain. When you create the redirects, they are automatically entered for you by the system at the end of that file. If redirects are not working, check the .htaccess file because other software may have placed commands before them that are overriding the new redirects. For example, when you install WordPress, it creates a redirect that ensures that visitors can find the main page of the site. If this is the case, you should move your new redirects to be at the beginning of the .htaccess file because commands in that file are acted on in the order in which they are read. You can create redirects for any path or filename within any domain you have added on or parked, and you can add and delete them any time you want. This means that you can easily redirect users for a short time when necessary and can also make shorter URLs to share with potential visitors that redirect to less memorable URLs on your website.

View Article
How to Use Subdomains for Your Web Host

Article / Updated 03-26-2016

The DNS Zone File held by the Authoritative Nameserver for a domain is actually quite extensive, and you can manipulate it somewhat using subdomains Consider the side of the Internet visible to web users and show you how subdomains work(and can improve your website. Get creative with subdomains for your DNS An FQDN requires a hostname as well as a domain name. This means that any domain name can actually be split into multiple subdomains. Picture it like an apartment building — not just any old apartment building either, but a fairly swanky apartment building. The first floor of the apartment building has an open space that has plenty of comfortable seating and refreshments available. It’s a common area that can be used by all residents of and visitors to the apartments. If somebody told you she lived at 123 Example Street, Exampleton, then you would assume that when you arrived you simply needed to go through the front door to find her. However, in this swanky apartment building that would only get you to the communal area on the first floor. To find the actual apartment, you would need to know the specific apartment number. So the complete address would be Apartment 45, 123 Example Street, Exampleton. After you have this correct, full address you can navigate straight to the apartment. This is also true of websites. If you give somebody your website address with no hostname at the beginning, it is like providing your apartment address without your apartment number. That’s okay if you live in a house rather than an apartment (or, in website terms, you only require a site to have the default hostname). However, the flexibility of the DNS means that at any time you can create a subdomain by creating a new hostname, you can have a second, third, and fourth (and so on) website all underneath one domain name. For example, you may convert the upstairs of your house into an apartment for your mother-in-law to live in. Your mother-in-law can then get her own mail and give out her own address as Apartment A, 456 Sample Street, Exampleton. Likewise, say you’re running a website for your local football team, examplefootballteam.com, and the coach decides he wants to have his own blog. You can create a subdomain with its own hostname of coach, which will give him his own unique address to make his own site, still under the umbrella of examplefootballteam.com. In this example, the FQDN of the coach’s blog would be coach.examplefootballteam.com. Both coach.examplefootballteam.com and www.examplefootballteam.com are FQDNs, meaning they are both unique and can therefore point to different places online. In theory, you can have as many subdomains as you need under your domain, but some of the cheaper web hosts may limit the maximum number they allow you to create. You can get as creative as you like with your subdomains and are limited only by your imagination and your requirements. Some people never require a subdomain, whereas others create a seemingly endless stream of them. Just to get your creative juices flowing, the following list includes a few ideas of how you might want to use subdomains: You may have purchased the domain yourfamilyname.com and created a personal website there. You may then want to give your children the opportunity to have their own websites and so you create a subdomain for each of them — for example, Sandra.yourfamilyname.com, Philip.yourfamilyname.com, and Alex.yourfamilyname.com. Your company’s website may be yourawesomebusiness.com, and you may want to create another site where you give support for your products, which you could call support.yourawesomebusiness.com. You may wish to create another site where you have a forum for your customers to talk about how awesome your products are, called forum.yourawesomebusiness.com. Say your name is Gemma and you spend all your spare time doing arts and crafts and have built a website called gemmasartsandcrafts.com to show people some of your beautiful items. Only after you started building the site did you realize that the papier-mâché models you create are really of little interest to the people interested in needlework or oil painting. You can create separate sites for each type of craft, each with its own subdomain, such as oilpainting.gemmasartsandcrafts.com and needlework.gemmasartsandcrafts.com as well as having your main site at gemmasartsandcrafts.com. How to create a new DNS subdomain Most control panels provide you with a simple way to create new subdomains. The process for setting up a subdomain is essentially the same for most control panels. As an example, here’s how you do it in cPanel: Log in to cPanel with the details your host provided when you opened the account. Scroll to the Domains section and click Subdomains. Type the name of the new subdomain you want to create in the box. Select the domain for which you want to create a subdomain. Any add-on or parked domains you have set up will be available in the drop-down box. If you want to, type the path to the document root of the domain. By default, the system selects /public_html/TheSubdomainYouTyped, but you can change it if you need to. Do not change the document root unless you are certain you know what you are doing. Changing the document root can make the setup very confusing. Click Create. The subdomain shows up in the list at the bottom of the page. You can remove it by clicking Remove or, if you need to, you can redirect it. If you need to redirect a subdomain for a domain, it must first be set up as a subdomain, either through the automatic process or manually. Otherwise the DNS does not know of its existence and the redirect does not work.

View Article
How to Connect to Your Web Host Server

Article / Updated 03-26-2016

The first thing you need to do to be able to connect your web host server is to set your server up to allow SSH connections. How you log in depends on whether you are using a username/password combination or a username/key system. It also depends on which operating system you are using on your computer. How to connect to your server with Windows If you are using a username/password combination, connect like this: Double-click on the Putty.exe file you downloaded. Type the hostname of your server (normally your primary domain name) or its IP address into the first box. Click Open. Type your username and press Enter. Type your password and press Enter. If you have configured your server correctly and entered the correct username and password, you should be logged in and have a command prompt with your username, your server name, and a # sign. During the login process, the server may give you warnings about not logging in if you’re not allowed to do so and might even tell you that it has notified the administrator that you’ve tried. You don’t need to worry about this unless you’re trying to break into someone else’s server! If you are using a username/key combination, you first have to save the key in PuTTY. This is a little complicated, but it’s easy enough if you follow these steps carefully: Create a public/private key on your server and download the private part as a ppk key. Double-click on the Putty.exe file. Type the hostname of your server (usually your primary domain name) or its IP address into the first box. In the Saved Sessions box, type a name for this connection and then click Save. In the category menu at the left of PuTTY, click SSH and then Auth. Click Browse and then browse to and select the ppk file you downloaded from your server. Click Connection in the Category list and then click Data. Type your username in the Auto-login username box. Click Session and save the session again. Click Open and PuTTY opens a connection to the server and attempts to log in using the username and key you provided. Every time you want to log in, you simply have to open PuTTY, select your saved session, and click Load. Click Open and PuTTY logs you back in. How to connect to your server with Mac or Linux Open the Terminal program. Type ssh username@Server IP Address. Make sure to use your actual username and the IP address of your server. Terminal attempts to connect to the server and, if it is successful, prompts you for the password for the account. You can also connect using the command username:password@Server IP Address (replace username, password, and Server IP Address with your actual details) and Terminal sends both pieces of data to the server automatically. Either way should be secure because the secure session is created before any login details are sent. Make sure you type your password correctly because too many incorrect attempts cause your server to lock you out.

View Article