60.[PHP]PHP简介及LNMP环境搭建(CentOS 7环境)
2016-12-04 14:40
579 查看
PHP
PHP常见使用场景
服务器端脚本
命令行脚本
桌面应用程序
搭建LNMP环境
安装Nginx
安装mysql用MariaDB
安装PHP
关闭SELinux
配置Nginx
验证安装
转载请注明原始链接:http://blog.csdn.net/a464057216/article/details/53454214
1.做为Web服务器的模块。
2.通过Web服务器将PHP文件请求转发给PHP CGI处理程序。
PHP最常见的使用场景是作为Web服务器端脚本语言,下面介绍在Cent OS 7上搭建PHP基础开发环境的步骤。
PHP常见使用场景
服务器端脚本
命令行脚本
桌面应用程序
搭建LNMP环境
安装Nginx
安装mysql用MariaDB
安装PHP
关闭SELinux
配置Nginx
验证安装
转载请注明原始链接:http://blog.csdn.net/a464057216/article/details/53454214
PHP
Hypertext Preprocessor超文本预处理器,开源脚本语言。PHP常见使用场景
服务器端脚本
PHP使用方式:1.做为Web服务器的模块。
2.通过Web服务器将PHP文件请求转发给PHP CGI处理程序。
命令行脚本
需要命令行可执行程序,不需要服务器和浏览器。桌面应用程序
使用PHP-GTK扩展来编写桌面图形界面应用程序。PHP最常见的使用场景是作为Web服务器端脚本语言,下面介绍在Cent OS 7上搭建PHP基础开发环境的步骤。
搭建LNMP环境
安装Nginx
添加centos yum源:sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm[/code]
安装nginx:sudo yum install nginx
启动nginx:sudo systemctl start nginx.service
浏览器访问服务器ip地址,出现Nginx欢迎页面说明nginx安装正常。
设置开机自动启动Nginx:sudo systemctl enable nginx.service安装mysql(用MariaDB)
安装MariaDB:sudo yum install mariadb-server mariadb
启动MariaDB:sudo systemctl start mariadb
在成功启动 MariaDB服务后,执行安全安装脚本为数据库服务器进行一些安全强化措施,如设置(非空)的 root 密码、删除匿名用户、锁定远程访问。sudo mysql_secure_installation
按照提示设置mysql用户名和密码及进行其他设置即可。
设置开机自动重启mysql:sudo systemctl enable mariadb.service安装PHP
安装PHP 和PHP 扩展sudo yum install php php-mysql php-fpm php-mbstring php-gd php-pear php-mcrypt php-mhash php-eaccelerator php-cli php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mssql php-snmp php-soap php-tidy php-common php-devel php-pecl-xdebug -y
编辑php配置文件/etc/php.ini设置cgi.fix_pathinfo=0(防止当文件不存在时,Nginx将请求发送到PHP-FPM,避免恶意脚本注入攻击)。
设置php-fpm配置文件(/etc/php-fpm.d/www.conf):listen = /var/run/php-fpm/php-fpm.sock security.limit_extensions = .php .php3 .php4 .php5 .html #设置PHP-FPM处理HTML及php文件
启动php-fpm:sudo systemctl start php-fpm
设置开机自动重启php-fpm:sudo systemctl enable php-fpm.service
关于php-fpm的介绍可以参考我的下一篇博客:PHP程序的运行方式。关闭SELinux
修改/etc/selinux/config中的SELINUX=disabled,重启系统后使用sestatus命令确认SELinux已经关闭:配置Nginx
Nginx配置文件/etc/nginx/conf.d/default.conf:server { listen 80; server_name localhost; root /home/lmz/website; index index.php index.html; location / { try_files $uri $uri/ =404; } error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } location ~ \.php$|\.html$ { #Nginx将html、PHP文件转发给PHP解释器执行 try_files $uri =404; fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
/home/lmz/website目录用户及用户组都是lmz,nginx的worker进程启动用户是nginx,所以/home、/lmz、/website三级目录都应该有o=r,o=x权限,其中的文件有o=r权限。
重启nginx:sudo systemctl restart nginx验证安装
在/home/lmz/website目下index.html内容如下:<html> <head> <title>Example</title> </head> <body> <?php echo "Hello World!"; ?> </body> </html>
浏览器访问服务器主机IP后出现如下界面表示PHP基础开发环境配置正常:
也可以在root目录新建一个info.php文件内容如下:<?php phpinfo(); ?>
浏览器访问http://localhost/info.php后显示如下信息:
如果觉得我的文章对您有帮助,欢迎关注我(CSDN:Mars Loo的博客)或者为这篇文章点赞,谢谢!
相关文章推荐
- centos7.2环境yum方式快速搭建lnmp环境nginx+mariadb+php-fpm
- centos LNMP第一部分环境搭建 LAMP LNMP安装先后顺序 php安装 安装nginx 编写nginx启动脚本 懒汉模式 mv /usr/php/{p.conf.default,p.conf} php运行方式SAPI介绍 第二十三节课
- LNMP环境搭建(centos6.9+mysql5.7+php7.1+nginx1.10)
- 在CentOS 7 64位操作系统环境下搭建LNMP(Linux+Nginx+MySQL+PHP)来运行Zabbix监控程序
- CentOS5.5安装Nginx、PHP(FastCGI)、MySQL --搭建LNMP环境安装wordpress
- centos6.5下使用yum完美搭建LNMP环境(php5.6)
- centos6.5下使用yum完美搭建LNMP环境(php5.6,mysql5.5,nginx1.10)
- 搭建LNMP环境(CentOS 6.8 + nginx1.10 + mysql5.6 + php5.6 )
- centos6.5下使用yum完美搭建LNMP环境(php5.6)
- 在CentOS上搭建PHP服务器环境(lamp、lnmp)
- centos linux 下LNMP 环境快速yum搭建(nginx+mysql+memcached+iptables+php)
- centos6.5下使用yum完美搭建LNMP环境(php5.6)
- CentOS 7 配置 Nginx + php + mysql 搭建 lnmp 环境过程全纪录
- centos6.7、centos6.5下yum方式搭建lnmp环境,php5.4/mysql5.5
- LNMP linux+nginx+mysql+php 环境搭建(基于centos)
- centos7.2+php7.0.10+mysql5.7.14+nginx1.10.1搭建LNMP环境
- CentOS 5.5安装Nginx、PHP(FastCGI)、MySQL --搭建LNMP环境安装Wordpress、Discuz
- LNMP ( CentOS Nginx MySQL PHP ) 环境搭建
- centos6.5下使用yum完美搭建LNMP环境(php5.6)
- centos6.5下使用yum完美搭建LNMP环境(php5.6)