I'm afraid I will never write any more-LAMP basics or-lamp Basics-PHP tutorials.

Source: Internet
Author: User
Tags php mysql
If I don't write any more, I'm afraid I will never write any more-LAMP basics or-lamp basics. If I don't write any more, I'm afraid I will never write any more-LAMP basics, or-lamp Basics-hi has gone through the four-day shopping spree, and the whole person is thinking about it... There was no reason to be lazy yesterday. In short, I did not write any more. I was afraid I would never write any more-LAMP basics, or-lamp basics.

Hi

After four days of baptism, the whole person had reached smecta... There was no reason to be lazy yesterday. In short, I should have mentioned it.

1. LAMP configuration in Ubuntu

----- Basic Ubuntu knowledge -----

---- Administrator privilege

For security purposes, Ubuntu does not recommend using the root account for remote logon-force other common accounts

Because normal accounts do not have super administrator permissions, by default, they cannot use the root account to log on (remotely). Therefore, these two commands are required.

Su (Switch User) switches to Super Administrator

Sudo (Switch User and DO) is executed as a super administrator

There is a fundamental difference between the two-the former is the "boss" (root), and the root password must be used to exit until exit; the latter is the "younger brother" and requests the boss to give permission, it is a temporary permission, and the password only needs to be normal.

---- Prerequisites

Liang @ liang-andy :~ $

Username @ host name: Current Directory user type mark

$ Indicates a common user, and # indicates a super administrator.

---

Liang @ liang-andy :~ $ Pwd
/Home/liang
~ Indicates that it is in the current user's personal folder. the pwd command can provide the actual directory.

---

The following two commands are used to modify the root password:

Liang @ liang-andy :~ $ Sudo passwd root
[Sudo] password for liang:
Enter a new UNIX password:
Re-enter the new UNIX password:
Passwd: The password is successfully updated.
Liang @ liang-andy :~ $
Then su

Liang @ liang-andy :~ $ Su
Password:
Root @ liang-andy:/home/liang #
Note that the directory path has changed #

---- Apt-get software installation tool

The main function is to obtain the software list apt-get update and software installation apt-get install

---- Other necessary command learning

Http://itlab.idcquan.com/linux/special/linuxcom/

---

Name: ls
  
Permission: all users
  
Usage: ls [-alrtAFR] [name...]
  
Description: displays the contents of a specified working directory (list files and subdirectories contained in the current working directory ).
  
Parameters:
  
-A: displays all files and directories. (if the file name or directory name starts with "." is specified in ls, it is regarded as a hidden file and will not be listed)
-L in addition to the file name, the file type, permission, owner, and file size are also listed in detail.
-R: Display files in reverse order (originally in alphabetical order)
-T list archives in the order of creation time
-A is the same as-a, but does not list "." (Current Directory) and ".." (parent directory)
-F add a symbol after the name of the file to be listed. for example, add "*" to the executable file and add "/" to the directory "/"
-R if the directory contains files, the following files are listed in sequence.
  
Example:
List all files whose names start with "s" in the current working directory:
Ls-ltr s *
  
List all the following directories and file details in the/bin directory:
Ls-lR/bin
  
List all files and directories under the current working directory. add "/" After the directory name, and add "*" after the executable file name "*":
Ls-AF

---

Ll will list all file information under this file, including hidden files, while ls-l will only list explicit files, which means these two commands are still different!

---

Command name: ln
  
Permission: all users
  
Usage: ln [options] source dist, where the option format is:
  
[-BdfinsvF] [-S backup-suffix] [-V {numbered, existing, simple}]
[-- Help] [-- version] [--]
Note: There is a so-called link in the Linux/Unix file system. we can regard it as the alias of the file, and the link can be divided into two types: hard link) symbolic link indicates that a file can have multiple names, while a soft link generates a special file, the content of this file points to another file. Hard links exist in the same file system, but soft links can span different file systems.
Ln source dist is used to generate a connection (dist) to the source. As for hard link or soft link, it is determined by the parameter.
  
No matter whether it is a hard link or soft link, it will not copy the original file, it will only occupy a very small amount of disk space.
  
Parameters:
  
-F: delete the file with the same name as dist before Link completion-d: allow system administrators to hard link their directories-I: when deleting an archive with the same name as dist, first ask-n: During soft link, dist will be treated as a general Archive-s: perform soft link (symbolic link)-v: display file name B before Link: back up the file that will be overwritten or deleted at link end-S SUFFIX: add the backup file to the end of SUFFIX-v method: specifies the backup METHOD -- help: displays the auxiliary instructions -- version: displays the version
Example:
Generate a symbolic link: zz
Ln-s yy zz
  
Generate a hard link: zz
Ln yy xx

---

Name: cd
  
Permission: all users
  
Usage: cd [dirName]
  
Note: change the working directory to dirName. DirName can be an absolute or relative path. If the directory name is omitted, it is changed to the user's home directory (that is, the directory where the login is located ).
  
In addition ,"~ "It also indicates the home directory," .. "indicates the current directory, and" .. "indicates the previous directory at the current directory location.
  
Example: Skip to/usr/bin /:
Cd/usr/bin
  
Jump to your home directory:
Cd ~
  
Jump to the top two layers of the current directory:
Cd ../..
  
Cd-return to the directory before entering the current directory

Name: cp
  
Permission: all users
  
Usage:
  
Cp [options] source dest
Cp [options] source... directory
  
Note: copy one file to another or copy several files to another directory. (Copy)
  
Parameters:
  
-A tries its best to copy the file status, permissions, and other information as they are.
-R if the source contains the directory name, the files under the Directory are also copied to the destination in sequence.
-F if the destination already has an archive with the same file name, delete it before copying.
Example:
Copy the file aaa (already exists) and name it bbb:
Cp aaa bbb

That is, sudo cp document_A document_ B
  
Copy all C language programs to the Finished subdirectory:
Cp *. c Finished

---

Name: mv
  
Permission: all users
  
Usage:
  
Mv [options] source dest
Mv [options] source... directory
Note: move one file to another or multiple files to another directory.
Parameter:-I if the destination already has a file of the same name, first ask whether to overwrite the old file.
  
Example:
  
Change the archive aaa to bbb:
Mv aaa bbb
  
Move all C language programs to the Finished subdirectory:
Mv-I *. c

---

Name: rm
  
Permission: all users
  
Usage: rm [options] name...
  
Delete files and directories.
  
Parameters:
  
-I ask for confirmation one by one before deletion.
-F the original file is deleted directly even if its attribute is set to "read-only". you do not need to confirm the attribute one by one.
-R also deletes directories and the following files one by one.
Example:
Delete all C language program files. ask for confirmation one by one before deletion:
Rm-I *. c
  
Delete all files in the Finished subdirectory and subdirectory:
Rm-r Finished

---

Name: mkdir
  
Permission: all users with the appropriate permissions in the current directory
  
Usage: mkdir [-p] dirName
  
Note: Create a subdirectory named dirName.
  
Parameter:-p: make sure that the directory name exists. if it does not exist, create one.
  
Example:
  
Create a subdirectory named AAA in the working directory:
Mkdir AAA
  
Create a subdirectory named Test in the BBB directory under the working directory. If the BBB directory does not exist, create one. (Note: In this example, if-p is not added and the BBB directory does not exist, an error is generated .)
Mkdir-p BBB/Test

---

Name: rmdir
  
Permission: all users with the appropriate permissions in the current directory
  
Usage: rmdir [-p] dirName
  
Delete an empty directory.
  
Parameter:-p is used to delete a subdirectory that becomes an empty directory.
  
Example:
  
Delete the sub-directory named AAA in the working directory:
Rmdir AAA
  
In the BBB directory under the working directory, delete the subdirectory named Test. If the BBB directory becomes empty after the Test is deleted, the BBB directory is also deleted.
Rmdir-p BBB/Test

---

Chmod-change the access mode of one or more files. chmod [options] mode files can only be used by file owners or privileged users to change the file access mode. Mode can be in the digital format or in the who opcode permission format. Which is optional. the default value is a (all users ). Only one opcode can be selected ). You can specify multiple modes separated by commas. Options:-c, -- changes only outputs the information of the changed file-f, -- silent, -- quiet. when chmod cannot change the file mode, the user -- help of the file is not notified to output help information. -R, -- recursive recursively traverses sub-directories, and applies the modification to all files and sub-directories in the directory. -- reference = filename sets the permission by referring to the filename permission.-v, -- verbose outputs the version information of each file no matter whether the modification is successful or not. Who u User g Group o all other a users (default) opcode + add permission-delete permission = re-assign permission r read w write x execute s set user (or group) the ID number t is set to sticky bit to prevent files or directories from being deleted by a non-owner, most of us use three octal numbers to indicate permissions. The first one specifies the permissions of the owner, the second one specifies the group permissions, and the third one specifies the permissions of other users. each user passes 4 (read) the sum of 2 (write) and 1 (execution) values to determine permissions. For example, 6 (4 + 2) indicates that you have the read and write permissions, and 7 (4 + 2 + 1) indicates that you have the read, write, and execution permissions. You can also set the fourth digit, which is located before the three-digit permission sequence. The fourth digit is 4, 2, and 1, which indicates the following: 4. set the user ID during execution, used to authorize a process based on the file owner, rather than to the user who creates the process. 2. set the user group ID during execution to authorize the process based on the file group, instead of the user who creates the process. 1. set the adhesion position. Instance: $ chmod u + x file adds the execution permission to the file owner $ chmod 751 file assigns the read, write, and execute (7) permissions to the file owner, assign the read and execute (5) permissions to the group where the file is located, and assign the execution (1) permissions to other users $ chmod u = rwx, g = rx, o = another form of example on x file $ chmod = r file assigns read permissions to all users $ chmod 444 file Same as above $ chmod a-wx, a + r file is the same as the preceding example. $ chmod-R u + r directory recursively assigns read permissions to the owner of all files and subdirectories in the directory $ chmod 4755 sets the ID, assign read, write, and execution permissions to the owner, and assign read and execution permissions to the group and other users.

----- Build a LAMP environment -----

---- Use apt-get to install Apache MySQL PHP

Apt-get has a feature that installs related things together.

---

Liang @ liang-andy :~ $ Sudo apt-get install apache2

Install apache, enter the password (common user) and y, and enter the following command, indicating that the installation is successful.
Liang @ liang-andy :~ $ Apache2-v
Server version: Apache/2.4.7 (Ubuntu)
Server built: Oct 14 2015 14:18:49
Enter ifconfig to get the IP address.

(I am here) 192.168.1.100 is successfully verified on the It works page.
---

Install PHP

Liang @ liang-andy :~ $ Sudo apt-get install php5
Liang @ liang-andy :~ $ Php5-v
PHP 5.5.9-1ubuntu4. 14 (cli) (built: Oct 28 2015 01:32:13)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
With Zend OPcache v7.0.3, Copyright (c) 1999-2014, by Zend Technologies
Then load/check the php5.load php module that implements operations on apache2 (this is the only way to do this for whatever reason)
Liang @ liang-andy :~ $ Cat/etc/apache2/mod-enabled/php5.load
LoadModule php5_module/usr/lib/apache2/modules/libphp5.so
---

Install MySQL

Liang @ liang-andy :~ $ Sudo apt-get install mysql-server
This does not need to be verified, but it also needs to check the module for php to operate mysql.

Liang @ liang-andy :~ $ Cat/etc/php5/mod-available/mysql. ini
Cat:/etc/php5/conf. d/mysql. ini: the file or directory does not exist.

Note: Here I use Ubuntu 14ls, and the cat directory of 12 is different from/etc/php5/conf. d/mysql. ini.

Here, because mysql extension is not installed in php by default, you need to manually install

Liang @ liang-andy :~ $ Sudo apt-get install php5-mysql
Liang @ liang-andy :~ $ Cat/etc/php5/mod-available/mysql. ini
; Configuration for php MySQL module
; Priority = 20
Extension = mysql. so
Then, restart mysql and apache2.

Liang @ liang-andy :~ $ Sudo service mysql restart
Liang @ liang-andy :~ $ Sudo service apache2 restart
---

One-time installation: The above process is divided, and the following one provides one-time installation

Sudo apt-get install apache2 php5 mysql-server php5-mysql

---- Create a phpinfo probe

Install vim first

Sudo apt-get install vim

Switch to the php www folder and run the cd command.

Cd/var/www/html (version 14.4)

Create a php file

Sudo vim info. php

Write php code

Echo mysql_connect ('localhost', 'root', 'hanhan123 ')? 'Hoho': 'WTF ';

Phpinfo ();
Then press esc and enter: wq to save and exit.

Http: // 192.168.1.100/info. php enter the verification result

This is why Linux is so painful. I will see you tomorrow.

Zhihi experienced the baptism of four-day meals, and the whole person had reached smecta... There was no reason for laziness yesterday...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.