一般我们都是采用Apache 作为PHP的解析服务器,这次则是采用Nginx这个强大的反向代理服务器来搭建PHP服务器。下面就以Linux发行版Ubuntu为例搭建一个Nginx的PHP服务器。
首先下载安装Nginx
sudo apt-get install nginx
安装完成后,启动Nginx
sudo /etc/init.d/nginx start
这时候打开浏览器里输入http://localhost/就可以看到Welcome to nginx!的页面了,说明我们的Nginx服务器安装成功
接下来安装PHP5
sudo apt-get install php5-fpm
安装成功后,我们要修改Nginx的虚拟机配置,让浏览器请求的php文件可以被php cgi解析。编辑Nginx虚拟机配置文件/etc/nginx/sites-available/default
sudo vim /etc/nginx/sites-available/default
然后把里面的配置修改为如下配置内容:
# You may add here your
# server {
# ...
# }
# statements for each of your virtual hosts to this file
##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# http://wiki.nginx.org/Pitfalls
# http://wiki.nginx.org/QuickStart
# http://wiki.nginx.org/Configuration
#
# Generally, you will want to move this file somewhere, and start with a clean
# file but keep this around for reference. Or just disable in sites-enabled.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##
server {
listen 80; ## listen for ipv4; this line is default and implied
#listen [::]:80 default ipv6only=on; ## listen for ipv6
root /usr/share/nginx/www;
index index.html index.htm index.php;
# Make site accessible from http://localhost/
server_name localhost;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to index.html
try_files $uri $uri/ /index.html;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
location /doc/ {
alias /usr/share/doc/;
autoindex on;
allow 127.0.0.1;
deny all;
}
# Only for nginx-naxsi : process denied requests
#location /RequestDenied {
# For example, return an error code
#return 418;
#}
error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/www;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
# With php5-cgi alone:
fastcgi_pass 127.0.0.1:9000;
# With php5-fpm:
#fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# root html;
# index index.html index.htm;
#
# location / {
# try_files $uri $uri/ /index.html;
# }
#}
# HTTPS server
#
#server {
# listen 443;
# server_name localhost;
#
# root html;
# index index.html index.htm;
#
# ssl on;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
#
# ssl_session_timeout 5m;
#
# ssl_protocols SSLv3 TLSv1;
# ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv3:+EXP;
# ssl_prefer_server_ciphers on;
#
# location / {
# try_files $uri $uri/ /index.html;
# }
#}
重新加载我们刚刚更改的Nginx配置
sudo /etc/init.d/nginx reload
然后我们在/usr/share/nginx/www/目录下新建一个phpinfo.php文件,可以查看php的配置和环境信息
sudo vim /usr/share/nginx/www/phpinfo.php
在phpinfo.php中录入如下内容:
<?php
phpinfo();
?>
我们在浏览器里输入http://localhost/phpinfo.php就可以看到PHP的信息页了,有版本等信息。
PHP5还有很多支持的模块,如果需要的话可以选择安装,一般这些模块都是php5-开头,比如php5-mysql,在Ubuntu里安装他只需
sudo apt-get install php5-mysql
PHP的模块安装后别忘记重启PHP5哦,执行如下命令可以重启
sudo /etc/init.d/php5-fpm restart
相关推荐
纯手工搭建Linux Nginx MySQL PHP WEB服务器
centos7系统;使用docker的容器部署nginx和php,成功访问phpinfo
详细描述了如何在linux(rhel)下搭建nginx web服务器的过程,并附有如何开启php功能。对于初学者,是很不错的参考资料。
nginx 是一个轻量级服务器 他可以实现超过6万以上的并发数连接的web服务器 同时也支持PHP JSP 内置有群集模块 可以轻松搭建强大的轻量级web群集系统
本文档使用CentOS7、mariadb、nginx、PHP7搭建PHP服务器(LNMP)
包含 Nginx+PHP+MySQL 安装包,还有 OpenSSL 安装包和几个实用 bat 小脚本,涵盖了从搭建 Nginx,自签署 SSL 证书,配置 HTTPS ,部署和配置 Windows PHP 服务器环境,连接 MySQL 的全部所需软件。Linux 可能是搭建...
Nginx PHP MySQL服务器环境搭建技术实践.pdf
2. 安装Nginx服务器 2.1. 在windows上安装 2.2. 在Linux上安装 2.2.1. 写在前面 2.2.2. 准备使用yum安装nginx的运行环境 2.2.3. 安装pcre 2.2.4. 安装zlib库 2.2.5. 安装nginx 2.2.6. 控制nginx 2.2.7. nginx...
Tomato DualWAN+移动硬盘 搭建nginx+php+mysql服务器教程
基于nginx-1.0.11 php-5.2.17-nts-Win32-VC6-x86制作的绿色版php服务器,解压,运行start.bat就可以启动服务器,可以快速搭建php环境,可为php新手提供一键式搭建php环境
phpfind 2013.12.20 phpfind是7件套,集成最新Nginx+PHP+MySQL+SQL-Front+Zend Guard Loader+XCache。...小巧简易迷你只有13M,非常方便的搭建网站服务器。 有专门开发的控制面板进行控制程序的启停。
Nginx版UPUPW PHP绿色服务器平台采用Nginx+PHP+MariaDB的架构搭建,MariaDB和MySQL完全兼容使用方法一致省内存性能佳。 Nginx版UPUPW PHP绿色服务器平台 1807.1 更新日志: 主体部分: Nginx/1.14.0强化版 轻量级...
YimonServer是一个拥有图形界面的快速搭建Nginx、PHP、MySQL、PHPMyAdmin、eAccelerator、ZendOptimizer、ZendGuard的绿色服务器套件。只要将程序文件夹拷贝到任意分区、目录,双击运行YimonServer.exe即可操作。...
搭建web服务nginx所有的包。LNMP代表的就是:Linux系统下Nginx+MySQL+PHP这种网站服务器架构。 Linux是一类Unix计算机操作系统的统称,是目前最流行的免费操作系统。代表版本有:debian、centos、ubuntu、fedora、...
Linux下mysql+PHP+nginx的搭建,写的很详细,教你怎么在LINUX环境下,搭建mysql+PHP+nginx。
Tengine是由淘宝网发起的Web服务器项目,是一个Nginx...正式介绍TengineRPM一键安装PHP环境,我们将LTMP一键安装组合,称为最完美的PHP服务器组合。 淘宝基于Nginx高效稳定针对大访问请求的Tengine服务器快速搭建方法。
Redhat下用Nginx+PHP5搭建高效PHP应用服务器
11.2 采用Nginx搭建FLV视频服务器 11.3 Nginx+PHP+MySQL在小内存VPS服务器上的优化 11.4 采用Nginx搭建正向代理服务器 第4部分 模块篇 第12章 Nginx的核心模块 12.1 主模块指令 12.2 主模块变量 12.3 事件...
ubuntunginx+PHP+mysql服务器搭建.pdf