说明:本教程主要包括以下三个部分:
1. 源代码编译安装Nginx
2. 源代码编译安装php以及mysql、redis扩展模块
3. 配置虚拟主机
文中所涉及安装包程序均提供下载链接,欢迎使用
运行环境以及前置条件:Ubuntu 12.04 LTS 已安装g++编译环境
所有源程序路径位于:root@ubuntu:/home/shihai/Desktop/Nginx文件夹下,如下图所示:
程序安装路径位于:/usr/local文件夹下
第一部分:安装Nginx
安装Nginx前需要安装依赖库PCRE库、zlib库、SSL库
安装PCRE库??为了rewrite
tar ?zxvf pcre-8.21.tar.gz
cd pcre-8.21
./configure --prefix=/usr/local/pcre-8.21
make
make install
安装zlib库??为了gzip压缩
tar ?zxvf zlib-1.2.8.tar.gz
cd zlib-1.2.8
./configure --prefix=/usr/local/zlib-1.2.8
make
make install
安装ssl库??支持ssl加密
tar -zxvf openssl-1.0.1c.tar.gz
cd openssl-1.0.1c
./config --prefix=/usr/local/openssl-1.0.1
make
make install
安装nginx??服务器软件
tar -zxvf nginx-1.2.8.tar.gz
cd nginx-1.2.8
./configure --prefix=/usr/local/nginx-1.2.8 \
--with-pcre=../pcre-8.21/ \
--with-zlib=../zlib-1.2.8/
make
make install
设定nginx启动的配置文件
/usr/local/nginx-1.2.8/sbin# ./nginx -c /usr/local/nginx-1.2.8/conf/nginx.conf
/usr/local/nginx-1.2.8/sbin# ./nginx -s reload
查看nginx进程
ps ?ef|grep nginx
打开localhost
当你看到上图所示内容时,说明Nginx服务器已经安装成功
第二部分:安装php以及mysql、redis扩展模块
安装ncurses??安装mysql前置条件:
tar -zxvf ncurses-5.4.tar.gz
cd ncurses-5.4
./configure
make
make install
安装mysql??此处使用是源码包编译安装
tar -zxvf mysql-5.1.73.tar.gz
cd mysql-5.1.73
./configure --prefix=/usr/local/mysql-5.1.73
make
make install
安装curl库??用于curl请求
tar -zxvf curl-7.39.0.tar.gz
./configure --prefix=/usr/local/curl-7.39.0
make
make install
安装php
tar -zxvf php-5.2.14.tar.gz
gunzip php-5.2.14-fpm-0.5.14.diff.gz
patch -d php-5.2.14 -p1
cd php-5.2.14
./configure --prefix=/usr/local/php-5.2.14\
--enable-fastcgi \
--enable-fpm \
--enable-sockets \
--enable-mbstring \
--with-mysql=/usr/local/mysql-5.1.73 \
--with-mysqli=/usr/local/mysql-5.1.73/bin/mysql_config\
--with-pdo-mysql=/usr/local/mysql-5.1.73 \
--with-curl=/usr/local/curl-7.39.0 \
--with-openssl=/usr/local/openssl-1.0.1 \
--with-mcrypt
make
make install
启动php-fpm使用如下命令:
/usr/local/php-5.2.14/sbin# ./php-fpm start
启动php-fpm的时候出现
Startingphp_fpm Dec 29 15:27:32.502790 [ERROR] fpm_unix_conf_wp(), line 124: pleasespecify user and group other than root, pool 'default'
解决办法:进入目录:/usr/local/php-5.2.14/etc只需要修改php-fpm.conf
Unix user of processes
Unix group of processes
将去掉即可。至于user/group根据实际情况修改(www)。
重新启动 /usr/local/php-5.2.14/sbin# ./php-fpm restart 成功了
安装redis扩展模块:
unzip phpredis-master.zip
exportPATH=/usr/local/php-5.2.14/bin/:$PATH
cp -r phpredis-master php-5.2.14/ext/
cd php-5.2.14/ext/phpredis-master
phpize
./configure--with-php-config=/usr/local/php-5.2.14/bin/php-config
make
make install
扩展库路径:/usr/local/php-5.2.14/lib/php/extensions/no-debug-non-zts-20060613/
在php扩展库路径下,可以找到编译生成的redis扩展库文件redis.so
打开路径/usr/local/php-5.2.14/lib/php.ini下的php.ini文件,使用命令如下:
vim php.ini
文件内容快速查找(按下“N”可以查找下一个匹配位置),使用命令如下:
:?extension
找到如图所示的指定位置后插入以下内容:
extension = redis.so
php会自动到扩展库路径下加载redis.so文件
如果没找到php.ini文件,可以全盘搜索该文件,使用命令如下:
find / -name php.ini
搜索结果显示此路径下存在/etc/php5/cli/php.ini文件,于是拷贝至/usr/local/php-5.2.14/lib,使用命令如下:
/usr/local/php-5.2.14/lib# cp/etc/php5/cli/php.ini php.ini
此处需要重启php-fpm才能生效,使用命令如下:
/usr/local/php-5.2.14/sbin# ./php-fpmrestart
第三部分:配置nginx虚拟主机
新建虚拟主机配置文件目录
/usr/local/nginx-1.2.8# mkdir vhosts
cd vhosts
touch scott.qq.com.conf
vim scottshi.qq.com.conf
输入以下内容配置自定义虚拟主机:
server {
listen 8001;/*监听端口号*/
server_name scott.qq.com;/*域名*/
access_log/usr/local/nginxweb/htdocs/access.log;/*站点访问日志*/
location / {
root /usr/local/nginxweb/htdocs/;/*页面文件目录*/
index index.php index.html index.htm;
}
error_page 500 502 503 504 /50x.html;/*服务器错误页面*/
location = /50x.html {
root html;
}
# pass the PHP scripts to FastCGI serverlistening on 127.0.0.1:9000
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000; /*Nginx转发请求地址*/
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME/usr/local/nginxweb/htdocs/$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
保存退出后,进入nginx的配置文件nginx.conf
/usr/local/nginx-1.2.8/conf# vim nginx.conf
与默认server层级并列且位于http层级之内,添加如下内容,使得自定义虚拟主机生效:
include /usr/local/nginx-1.2.8/vhosts/*;
保存退出后,重启nginx服务器,重新载入配置文件,使用命令如下:
/usr/local/nginx-1.2.8/sbin# ./nginx ?s reload
编写php测试页面:
进入目录/usr/local/nginxweb/htdocs/,新建test.php文件,输入test.php页面内容:
Phpinfo();
?>
保存退出
使用浏览器,访问以下地址:
scott.qq.com:8001/test.php
此页面会显示配置php时的指令还有各个功能模块,包括fastcgi、mysql、curl、redis等

Long URLs, often cluttered with keywords and tracking parameters, can deter visitors. A URL shortening script offers a solution, creating concise links ideal for social media and other platforms. These scripts are valuable for individual websites a

Following its high-profile acquisition by Facebook in 2012, Instagram adopted two sets of APIs for third-party use. These are the Instagram Graph API and the Instagram Basic Display API.As a developer building an app that requires information from a

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-

This is the second and final part of the series on building a React application with a Laravel back-end. In the first part of the series, we created a RESTful API using Laravel for a basic product-listing application. In this tutorial, we will be dev

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' =>

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.

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

The 2025 PHP Landscape Survey investigates current PHP development trends. It explores framework usage, deployment methods, and challenges, aiming to provide insights for developers and businesses. The survey anticipates growth in modern PHP versio


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

SublimeText3 Chinese version
Chinese version, very easy to use

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

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver CS6
Visual web development tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software
