PHP Simplification Complete summary (Linux/laravel article)

Source: Internet
Author: User
Tags array definition fpm php download phpinfo subdomain

PHP official website:http://www.php.net
PHP Version:

View: Php-version
Description: None-thread safe is non-thread safe and does not perform thread security checks at execution time, thread safe is threaded, thread safety is performed at execution time to prevent new threads from being started with CGI The execution method exhausts the system resources.
Let's look at two ways of executing PHP: ISAPI and fastcgi. FastCGI execution is performed in a single thread, so there is no need for thread security checks, and removing thread security checks can improve execution efficiency, so if PHP is executed in FastCGI (whether with IIS 6 or IIS 7), it is recommended to download, execute Non-thread Safe php (PHP binary files are packaged in two ways: MSI, zip, download zip kit). Thread safety checks are prepared for the ISAPI way of PHP, because there are many PHP modules that are not thread-safe, so you need to use the thread safe PHP.

PHP Download:

http://www.php.net/downloads.php;http://windows.php.net/download#php-7.1

Common Extensions for PHP:

Php-redis: Download Urlhttps://pecl.php.net/package/redis

1. Installing Redis
Download: https://github.com/nicolasff/phpredis/archive/2.2.4.tar.gz
Upload phpredis-2.2.4.tar.gz to/usr/local/src directory

CD/USR/LOCAL/SRC #进入软件包存放目录
Tar zxvf phpredis-2.2.4.tar.gz #解压
CD phpredis-2.2.4 #进入安装目录
/usr/local/php/bin/phpize #用phpize生成configure配置文件
./configure–with-php-config=/usr/local/php/bin/php-config #配置
Make #编译
Make install #安装
After the installation is complete, the following installation path appears
/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/
2. Configure PHP Support

Vi/usr/local/php/etc/php.ini #编辑配置文件, add the following on the last line
Add to

extension= "Redis.so"

: wq! #保存退出
3 Restart Service

sudo service nginx restart
SUDO/ETC/INIT.D/PHP-FPM restart

PHP Configuration:
PHP.ini, in many of the installation environment, PHP also load back the configuration files in the PHP.D, usually that is the PHP extension file.

How to upgrade PHP:

Download the new version, back up the old PHP version of the directory, with the new version of the entire directory overwrite the old version of the directory, while keeping the old version of the directory PHP configuration file (php.cnf,php.ini), test run your site;

PHP variable definition:

$a;//define variable $ A

$a = "Hello world!"; /define variables and assign values

Array variables

$arr 1=["A", "B", "C", "C"];//array definitions

$arr 1[0]= "S";

$arr 2=array ("A", "B", "C", "C"])//Array definition

Array of key values

$arr =["key1″=>" Value1″, "key2″=>" value2 "];

The uncorrupted set calendar, the fastest of the foreach:
$urls = Array (' AAA ', ' BBB ', ' CCC ', ' ddd ');
foreach ($urls as $url) {
echo "This Site URL is $url! <br/> ";
}
Key value Array Traversal:
foreach ($arr as$key=> $val) {

echo $key. " = ". $val;
}

Variable null value check:

In summary php, "null" and "NULL" are 2 concepts.

Isset is used primarily to determine if a variable has been initialized.
Empty can evaluate to true for variables with a value of false, NULL, 0″, NULL, uninitialized
Is_null only variables with a value of "null" are judged as true
var = = null evaluates to "false", "null", "0″", "null" for variables that are true
var = = NULL only evaluates a variable with a value of "null" to True

So when we judge whether a variable is really "NULL", we mostly use Is_null to avoid "false", "0″ equivalent interference."

View of variables:

Var_dump (variable);p rint_r (variable) can print out the values of complex type variables (such as arrays, objects)

PHP's Operating environment:
Generally have Apache and nginx, we recommend using Nginx

Examples of nginx configuration in PHP:

######################## default ############################
server {
Listen 80;
server_name _;
Access_log/data/wwwlogs/access_nginx.log combined;
Root/data/wwwroot/default;
Index index.html index.htm index.php;
Location/nginx_status {
Stub_status on;
Access_log off;
Allow 127.0.0.1;
Deny all;
}
Location ~ [^/]\.php (/|$) {
#fastcgi_pass remote_php_ip:9000;
Fastcgi_pass Unix:/dev/shm/php-cgi.sock;
Fastcgi_index index.php;
Include fastcgi.conf;
}
Location ~. *\. (Gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico) $ {
Expires 30d;
Access_log off;
}
Location ~. *\. (JS|CSS)? $ {
Expires 7d;
Access_log off;
}
Location ~/\.ht {
Deny all;
}
}

#################### Vhost #############################

Example of Nginx configuration for CI framework:

Listen 80;
server_name www.xxx.com;
root/disk2/home/www;
Index index.html index.php;
Access_log/disk2/log/www.log;

Location/{
Index index.html index.php;
Try_files $uri $uri//index.php?uri&args;
}

Location ~/.well-known {
Allow all;
}

Location ~* \. (INI|DOCX|DOC|PEM) $ {
Deny all;
}

Location/phpfpm_status {
# Fastcgi_pass 127.0.0.1:9000;
Fastcgi_pass Unix:/dev/shm/php-cgi.sock;
Include Fastcgi_params;
Fastcgi_param script_filename $fastcgi _script_name;
}

Location ~. *\. (PHP|PHP5)? $ {
#fastcgi_pass 127.0.0.1:9002; #windows

# Fastcgi_pass Unix:/dev/shm/php-fpm-index.sock;
# Fastcgi_index index.php;
Fastcgi_pass Unix:/dev/shm/php-cgi.sock;
Fastcgi_index index.php;
Include fastcgi.conf;
# Fastcgi_param Document_root/home/wwwroot/index$subdomain;
# Fastcgi_param Script_filename/home/wwwroot/index$subdomain$fastcgi_script_name;
# include Fastcgi_params
Fastcgi_split_path_info ^ (. +\.php) (. *) $;
Fastcgi_param path_info $fastcgi _path_info;
Fastcgi_param Path-tarnslated/disk2/home/www$fastcgi_path_info;
Fastcgi_param Script_filename/disk2/home/www$fastcgi_script_name;
Include Fastcgi_params;
}

Web development Framework for PHP:
Yii,ci (CodeIgniter), laravel,symfony,thinkphp
Recommended to choose Laravel.

PHP Information to view:
Create phpinfo.php at the root of your site:
<?php
Echo phpinfo ();//Output PHP
?>

PHP's $_get,$_post,$_session,$_cookie

Composer Package Manager:
Linux installation composer
1, download Composer.phar to project
use Curl-ss https:// Getcomposer.org/installer | PHP download Composer binary file, is a PHAR package (PHP archive)
2, you can specify the Composer installation directory via the –INSTALL-DIR option (it can be an absolute or relative path): Curl-ss https:// Getcomposer.org/installer | Php-–install-dir=lumen
3, if you put Composer.phar in the PATH directory of the system, you can access the Composer.phar globally. In Unix-like systems, you can even use PHP without a prefix. You can execute these commands to allow composer to make a global call to your system:
#mv Composer.phar/usr/local/bin/composer
Now only needs to run composer command to use composer Without having to enter PHP Composer.phar.
4, check whether Composer is working properly, only need to execute phar:php through PHP Composer.phar This will return you an executable list of commands

Laravel installation under Linux:
Composer global require "Laravel/installer"
or composer Create-project Laravel/laravel–prefer-dist yourprojectname
By the Useradd, you cannot execute this command with the root user, you will have to create a new user, then log in with this user and execute this command!
Hint, this installation does not react at first, you are waiting patiently ... Keep the network of installed computers unblocked and know the installation is complete;
After the installation is complete, use ls-a ~/, that is, actually generate the hidden folder under the user root directory: such as Home/webuser/.config/composer/vendor/bin (WebUser is the current user);
Adding environment variables
Vim/etc/profile

Add the following content
Path= $PATH: ~/.config/composer/vendor/bin
Path= $PATH: ~/.composer/vendor/bin
Save Esc key, enter wq!
Make file effective: Source/etc/profile
Before you create a project with Laravel, modify the php.ini configuration:
Find "Disable_functions" in php.ini, remove Proc_get_status,proc_open

To create a project with Laravel:
Command:
Laravel New WEB3
Wait for the download installation to complete!
The generated WEB3 project file under Path ~/.config/composer/vendor/laravel/, note that "~/" is the user's root directory, if you do not log in with the user account installed Laravel, it is "/home/[laravel Install user name ]/”,
Copy it to/HOME/WEB/WEB3.
Then configure the NGINX.CONF sample:

server {
Listen 8011;
server_name 192.168.0.10;
Set $root _path '/home/web/web3/public ';
Root $root _path;
Index index.php index.html index.htm;

Access_log Logs/web3-access.log Main;
Error_log Logs/web3-error.log;

Try_files $uri $uri/@rewrite;

# location @rewrite {
# rewrite ^/(. *) $/index.php?_url=/$1;
# }

Location ~ \.php {

# Fastcgi_pass 127.0.0.1:9000;
Fastcgi_pass Unix:/dev/shm/php-fpm-index.sock;
fastcgi_index/index.php;

Fastcgi_split_path_info ^ (. +\.php) (. *) $;
Fastcgi_param path_info $fastcgi _path_info;
Fastcgi_param path-tarnslated $root _path$fastcgi_path_info;
Fastcgi_param script_filename $root _path$fastcgi_script_name;
#配置下面信息 to enable the Web site to access the response directory to prevent "Open_basedir" related errors
Fastcgi_param php_admin_value open_basedir= $document _root/: $root _path:/home/web/web3/;
Include Fastcgi_params;

}

Location ~* ^/(css|img|js|flv|swf|download)/(. +) $ {
Root $root _path;
Location ~/\.ht {
Deny all;
}
}
}

Write a welcome page with laravel5.4:
First create the route:/routes/web.php Add the following code:
Route::get ('/welcome ', ' [email protected] ');
Create router: PHP artisan make:controller Welcomecontroller
Then modify:/app/http/controllers/welcomecontroller.php

Public Function Index ()
{

$str = "Hello, this is luxing first laravel page! welcome! ";//front-end display
# echo $str;
Return view (' Welcome.index ', compact (' str '));

}
Then create the view,/resources/views/welcome/index.blade.php, content:

<!doctype html>
<title>welcome</title>
<body>

<p style= "width:100%;height:100%; Text-align:center; padding-top:150px; " >
This is the STR from controller:
<br/>
{{$STR}}
<p>
</body>

PHP Simplification Complete summary (Linux/laravel article)

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.