实战在Ubuntu上配置Nginx+PHP+MySQL环境
Nginx是一款近些年来日益流行的 高性能的HTTP和反向代理服务器,同时也是一个IMAP/POP3/SMTP 代理服务器 ,他的发音是"Engine X"
(怪不得我感觉之前读的那么别扭,原来读的不对。。),今天刚好又拿到一个ec2配额,在ubuntu上尝试了一下部署这套环境
对ec2配置的提示 如果你需要在ec2上做web服务,记得到安全组的入站设置内允许80端口通讯
1.安装FastCGI
FastCGI是负责Nginx解析php的一个模块,有关FastCGI的介绍请看下文,下文引自 博客园 - Ubuntu中Nginx的安装与配置
Nginx完全是轻量级的,必须借助第三方的FastCGI处理器才可以对PHP进行解析,因此其实这样看来Nginx是非常灵活的,它可以和任何第三方提供解析的处理器实现连接从而实现对PHP的解析(在nginx.conf中很容易设置)。Nginx可以使用spwan-fcgi。在早期版本中需要安装lighttpd,但是在9.10版本以后直接安装spawn-fcgi就可以。
安装spwan-fcgi可以用ubuntu自带的 apt-get 来安装
sudo apt-get install spawn-fcgi
2.安装与启动nginx
同样道理安装nginx也可以用 apt-get 来进行安装
sudo apt-get install nginx
按照此方式安装后,nginx的各个文件位置大概如下
配置文件目录: /etc/nginx
每个虚拟主机的配置文件的目录: /etc/nginx/sites-available
启动程序文件: /usr/sbin/nginx
日志文件( access.log 和 error.log ): /var/log/nginx
启动脚本: /etc/init.d/nginx
虚拟主机默认目录: /usr/share/nginx/www
安装完成后即可通过启动脚本控制nginx开关
启动: sudo /etc/init.d/nginx start
停止: sudo /etc/init.d/nginx stop
重启: sudo /etc/init.d/nginx restart
3.安装PHP、MySQL并配置PHP使之正常运行
继续使用apt-get安装php、mysql和中间件等组件
sudo apt-get install php5-cli php5-cgi mysql-server php5-mysql
然后定位到nginx的虚拟主机配置目录,编辑 default 这个文件(记得开sudo),然后找如下代码
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; }
请注意,如果这步配置错误或者没有配置就会出现访问php脚本时浏览器弹出下载的问题,所以说我并不推荐在配置成功之前便将代码部署至服务器,这样很可能由于配置失误造成风险。去掉 # With php5-fpm 下面三行代码的注释并保存,然后重启nginx
sudo /etc/init.d/nginx restart
然后定位到你的虚机主机默认目录,写一个简单的php脚本保存下,比如
<?php phpinfo();
然后到浏览器里访问这个脚本,如果一切正常就算成功了

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP logging is essential for monitoring and debugging web applications, as well as capturing critical events, errors, and runtime behavior. It provides valuable insights into system performance, helps identify issues, and supports faster troubleshoot

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

Alipay PHP...

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.
