PHP简介:
PHP即“超文本预处理器”,是一种通用开源脚本语言。PHP是在服务器端执行的脚本语言,与C语言类似,是常用的网站编程语言。PHP独特的语法混合了C、Java、Perl以及 PHP 自创的语法。利于学习,使用广泛,主要适用于Web开发领域。
PHP原始为Personal Home Page的缩写,已经正式更名为 "PHP: Hypertext Preprocessor"。自20世纪90年代国内互联网开始发展到现在,互联网信息几乎覆盖了我们日常活动所有知识范畴,并逐渐成为我们生活、学习、工作中必不可少的一部分。据统计,从2003 年开始,我国的网页规模基本保持了翻番的增长速度,并且呈上升趋势。PHP 语言作为当今最热门的网站程序开发语言,它具有成本低、速度快、可移植性好、 内置丰富的函数库等优点,因此被越来越多的企业应用于网站开发中。但随着互联网的不断更新换代,PHP语言也出现了不少问题。
根据动态网站要求,PHP语言作为一种语言程序,其专用性逐渐在应用过程中显现,其技术水平的优劣与否将直接影响网站的运行效率。其特点是具有公开的源代码, 在程序设计上与通用型语言,如C语言相似性较高,因此在操作过程中简单易懂,可操作性强。同时,PHP语言具有较高的数据传送处理水平和输出水平,可以广泛应用在Windows系统及各类Web服务器中。如果数据量较大,PHP语言还可以拓宽链接面,与各种数据库相连,缓解数据存储、检索及维护压力。随着技术的发展,PHP 语言搜索引擎还可以量体裁衣,实行个性化服务,如根据客户的喜好进行分类收集储存,极大提高了数据运行效率。
---------------------------《来自·百度百科》
正式安装开始:
# rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
开始安装PHP7
# yum install php70w.x86_64 php70w-cli.x86_64 php70w-common.x86_64 php70w-gd.x86_64 php70w-ldap.x86_64 php70w-mbstring.x86_64 php70w-mcrypt.x86_64 php70w-mysql.x86_64 php70w-pdo.x86_64
安装php-fpm
# yum install php70w-fpm php70w-opcache
查看php版本
# php -v
启动php-fpm
# systemctl start php-fpm
查看PHP是否启动成功
# ps -ef|grep php
开机启动设置
# systemctl enable php-fpm
# systemctl daemon-reload
php其他命令
# php -v 查看当前php的版本
# whereis php-fpm 查看php-fpm的位置
# Systemctl start php-fpm.service 启动
# Systemctl Stop php-fpm.service 停止
# Systemctl Restart php-fpm.service 重启
# Systemctl reload php-fpm.service 重启修改配置
配置 nginx与PHP互通
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
root /usr/share/nginx/html;
index index.html index.htm index.php;
}
location ~ \.php$ {
#root html;
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
Nginx访问PHP文件的File not found错误处理,两种情况
这个错误很常见,原有有下面两种几种
php-fpm找不到SCRIPT_FILENAME里执行的php文件
php-fpm不能访问所执行的php,也就是权限问题
第一种情况
更改配置文件nginx.conf
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
替换成下面
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
然后重新加载nginx配置文件
/etc/init.d/nginx reload
第二种情况
两种解决方法:
第一种,就是把你root文件夹设为其他用户允许
第二种,找到你的php-fpm的配置文件,找到下面这段,把apache替换成你要的用户组
; RPM: apache Choosed to be able to access some dir as httpd
user = www
; RPM: Keep a group allowed to write in log dir.
group = www