Home  >  Article  >  Backend Development  >  If I don’t write it, I’m afraid I’ll never write it again -LAMP basics, nor -lamp basics_PHP tutorial

If I don’t write it, I’m afraid I’ll never write it again -LAMP basics, nor -lamp basics_PHP tutorial

WBOY
WBOYOriginal
2016-07-12 09:04:18959browse

If I don’t write, I’m afraid I’ll never write again -LAMP basics, nor -lamp basics

 hi

After four days of feasting, I feel like I’m feeling refreshed. . . Yesterday's laziness was laziness for no reason. Anyway, it's time to pick up the pen. Dear

1. LAMP configuration under Ubuntu

-----Ubuntu Basics-----

----Administrator permissions

For security reasons, Ubuntu does not recommend using the root account to log in remotely - forcing the use of other ordinary accounts

Since ordinary accounts do not have super administrator rights, and you cannot use the root account to log in (remotely, etc.) by default, you need to use these two commands

su (Switch User) switches to super administrator

sudo (Switch User and DO) execute as super administrator

There is an essential difference between the two - the former is the "boss" (root) who takes action and must use the root password and will not exit until exit; the latter is the "little brother" asking the boss for permission, and it is a temporary permission , just use a normal password

----Preliminary knowledge

liang@liang-andy:~               $

Username@Hostname: current directory User type tag

Among them, $ represents an ordinary user and # represents a super administrator

---

liang@liang-andy:~$ pwd
/home/liang
~ means it is now in the current user’s personal folder. The pwd command can give the actual directory

---

These two commands are demonstrated below: Change root password

liang@liang-andy:~$ sudo passwd root
[sudo] password for liang:
Enter new UNIX password:
Re-enter the new UNIX password:
passwd: Password updated successfully
liang@liang-andy:~$
Then su

liang@liang-andy:~$ su
Password:
root@liang-andy:/home/liang#
Note that the directory path has changed, and #

----apt-get software installation tool

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

----Learn other necessary commands

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

---

Name: ls

Usage permission: All users

Usage method: ls [-alrtAFR] [name...]

Description: Display Specify the contents of the working directory (list the files and subdirectories contained in the current working directory).
 
 Parameters:
 
 -a Display all files and directories (ls defaults to treating file names or directory names starting with "." as hidden files and will not list them)
 - l In addition to the file name, the file type, permissions, owner, file size and other information are also listed in detail
-r Display the files in reverse order (originally in English alphabetical order)
-t List in order of creation time
-A Same as -a, but do not list "." (current directory) and ".." (parent directory)
-F Add after the listed file names A symbol; for example, add "*" for executable files and "/" for directories
-R If there are files in the directory, the following files will also be listed in sequence

Example:
List all files in the current working directory whose names begin with s, with the newer ones following:
ls -ltr s*

List all directories and file details under the /bin directory:
  ls -lR /bin
 
List all files and directories in the current working directory; add "/" after the name of the directory, and add "*" after the name of the executable file:
  ls -AF

---

ll will list all file information under the file, including hidden files, while ls -l only lists explicit files, indicating that the two commands are not equivalent!

---

Command name: ln

Usage permissions: All users

Usage method: ln [options] source dist, where the option format is:

[-bdfinsvF] [-S backup-suffix] [-V {numbered,existing,simple}]
 [--help] [--version] [--]
Explanation: In the Linux/Unix file system, there are so-called links, which we can regard as aliases for files, and links can be divided into two types: hard links link) and soft link (symbolic) link), a hard link means that a file can have multiple names, while a soft link generates a special file whose content points to the location of another file. Hard links exist in the same file file system, but soft links can span different file systems.
 ln source dist generates a link (dist) to the source. Whether to use a hard link or a soft link is determined by the parameters.
 
No matter it is a hard link or a soft link, it will not copy the original file and will only occupy a very small amount of disk space.
 
 Parameters:
 
-f: Delete files with the same file name as dist first when linking -d: Allow system administrators to hard link their own directories -i: After deleting files with dist Query first when there are files with the same file name -n: Treat dist as a normal file when making a soft link -s: Make a soft link (symbolic link) -v: Display the file name before linking -b: Back up the files that will be overwritten or deleted when linking -S SUFFIX: Add the suffix SUFFIX to the backed up files -V METHOD: Specify the backup method --help: Display auxiliary instructions --version: Display version
Example:
Generate a symbolic link from file yy: zz
ln -s yy zz

Generate a hard link from file yy: zz
  ln yy xx

---

Name: cd

Usage permission: All users

Usage: cd [dirName]

Description: Change the working directory to dirName. where dirName representation can be an absolute path or a relative path. If the directory name is omitted, it will change to the user's home directory (that is, the directory where the user was just logged in).
 
In addition, "~" also means home directory, "." means the current directory, and ".." means the directory above the current directory.
 
 Example: Jump to /usr/bin/:
 cd /usr/bin
 
  Jump to your own home directory:
  cd ~
 
  Jump to Two levels above the current directory:
cd ../..

cd - Return to the directory before entering the current directory

Name: cp

Usage permissions: All users

Usage:

cp [options] source dest
cp [options] source ... directory
 
  Description: Copy one file to another file, or copy several files to another directory. (copy)
 
 Parameters:
 
 -a Copy the file status, permissions and other information as much as possible.
  -r If source contains a directory name, all files in the directory will also be copied to the destination in sequence.
  -f If a file with the same file name already exists at the destination, 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

Usage permissions: All users

Usage:

mv [options] source dest
mv [options] source ... directory
 Description: Move one file to another file, or move several files to another directory.
Parameter: -i If the destination already has a file with the same name, it will first ask whether to overwrite the old file.

Example:

Rename the file aaa to bbb:
mv aaa bbb

Move all C language programs to the Finished subdirectory:
mv -i *.c

---

Name: rm

Usage permissions: All users

Usage method: rm [options] name...

Description: Delete files and directories .
 
 Parameters:
 
 -i Ask for confirmation one by one before deleting.
 -f Even if the original file attribute is set to read-only, it will be deleted directly without confirming one by one.
 -r will also delete the files in the directory and below one by one.
Example:
Delete all C language program files; ask for confirmation one by one before deleting:
rm -i *.c

Delete all files in the Finished subdirectory and subdirectories:
rm -r Finished

---

Name: mkdir

Usage permissions: All users with appropriate permissions in the current directory

Usage method: mkdir [-p] dirName

Description : Create a subdirectory named dirName.
 
 Parameter: -p Make sure the directory name exists. If it does not exist, create one.

Example:

In the working directory, create a subdirectory named AAA:
mkdir AAA

In the BBB directory in the working directory, create a A subdirectory named Test. If the BBB directory does not exist originally, create one. (Note: If -p is not added in this example, and the original BBB directory does not exist, an error will occur.)
  mkdir -p BBB/Test

---

Name: rmdir

Usage permissions: All users with appropriate permissions in the current directory

Usage method: rmdir [-p] dirName

Description : Delete empty directories.
 
 Parameter: -p is to delete the subdirectory as well when it becomes an empty directory after it is deleted.

Example:

Delete the subdirectory named AAA in the working directory:
rmdir AAA

In the BBB directory in the working directory, delete the subdirectory named AAA Test subdirectory. If the BBB directory becomes an empty directory after Test is deleted, BBB will also be deleted.
rmdir -p BBB/Test

---

chmod----change the access mode (mode) of one or more files chmod [options] mode files Only the file owner or privileged users can use this function to change the file access mode. mode can be in numeric form or expressed in the form of who opcode permission. who is optional, the default is a (all users). Only one opcode can be selected. Multiple modes can be specified, separated by commas. options: -c, --changes Only output information about changed files -f, --silent, --quiet Do not notify the user of the file when chmod cannot change the file mode --help Output help information. -R, --recursive Can recursively traverse subdirectories and apply modifications to all files and subdirectories in the directory --reference=filename Refer to the permissions of filename to set permissions -v, --verbose Regardless of whether the modification is successful or not, output the information of each file --version Output version information. who u User g Group o Others a All users (default) opcode Add permissions - Delete permission = Reassign permissions permission r Read w Write x Execute s Set the user (or group) ID number t Set the sticky bit to prevent files or directories from being deleted by non-owners u User’s current permissions g Current permissions for the group o Current permissions of other users As an alternative, we mostly use three-digit octal numbers to represent permissions. The first digit specifies the permissions of the owner, the second digit specifies the group permissions, and the third digit specifies the permissions of other users. Each digit passes 4 (read ), 2 (write), and 1 (execute) to determine the permissions. For example, 6(4 2) represents the permission to read and write, and 7(4 2 1) has the permission to read, write and execute. You can also set the fourth digit, which is located in front of the three-digit permission sequence. The value of the fourth digit is 4, 2, 1, which means the following: 4. Set the user ID when executing, which is used to authorize the process based on the file owner, not to the user who created the process. 2. Set the user group ID when executing, which is used to authorize processes based on the group where the file is located, rather than based on the user who created the process. 1, set the sticky bit. Example: $ chmod u $ chmod 751 file Assign read, write, and execute (7) permissions to the owner of the file, read and execute (5) permissions to the file's group, and execute (1) permissions to other users $ chmod u=rwx,g=rx,o=x file Another form of the above example $ chmod = R File allocate read permissions for all users $ chmod 444 file                                                                                                                                                                                                                                                 $ chmod a-wx,a r file    Same as the above example $ chmod -R u r directory Recursively assign read permissions to the owners of all files and subdirectories in the directory $ chmod 4755 Set ID to allocate read, write and execute permissions to the owner, and assign read and execute permissions to group and other users. -----Build a LAMP environment-----

----Install Apache MySQL PHP using apt-get

apt-get has a feature, that is, when installing something, it will install some related things together

---

liang@liang-andy:~$ sudo apt-get install apache2

Install apache, then enter the password (normal user) and y, enter the following command to indicate successful installation

liang@liang-andy:~$ apache2 -v

Server version: Apache/2.4.7 (Ubuntu )
Server built: Oct 14 2015 14:18:49
Then enter ifconfig to get the ip address

(I am here) 192.168.1.100 and got the It works page verification successfully
---

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 php5.load, the php module that implements the operation of apache2 (no matter why, just do this first)
liang@liang-andy:~$ cat / etc/apache2/mods-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 require verification of the version, but you must also check the PHP module for operating mysql

liang@liang-andy:~$ cat /etc/php5/mods-available/mysql.ini
cat: /etc/php5/conf.d/mysql.ini: No such file or directory

Note that the Ubuntu I am using here is the 14ls version, and the cat directory of 12 is different /etc/php5/conf.d/mysql.ini

Here, since PHP does not install the mysql extension by default, you need to install it manually

liang@liang-andy:~$ sudo apt-get install php5-mysql
liang@liang-andy:~$ cat /etc/php5/mods-available/mysql.ini
; configuration for php MySQL module
; priority=20
extension=mysql.so
That’s it, then restart mysql and apache2

liang@liang-andy:~$ sudo service mysql restart
liang@liang-andy:~$ sudo service apache2 restart
---

One-time installation: The above is a step-by-step process, and the next one gives a one-time installation

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

----Create phpinfo probe

Install vim first

sudo apt-get install vim

Then switch to the www folder of php and use the cd command

cd /var/www/html (version 14.4)

Then create a php file here

sudo vim info.php

Write php code

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

phpinfo();
Then esc key , enter: wq to save and exit

http://192.168.1.100/info.php Browser input verification result

Linux turns out to be like this but it hurts, so I won’t write about it anymore. See you tomorrow

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1074253.htmlTechArticleIf I don’t write anymore, I’m afraid I will never write again - LAMP basics, nor - lamp basics hi Experienced 4 The baptism of the heavenly feast made everyone feel Smecta. . . Yesterday's laziness was laziness for no reason, in short...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn