search
HomeBackend DevelopmentPHP TutorialNginx+Php-fpm+MySQL+Redis源代码编译安装指南

说明:本教程主要包括以下三个部分:

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等












 

 

 

 

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Explain how load balancing affects session management and how to address it.Explain how load balancing affects session management and how to address it.Apr 29, 2025 am 12:42 AM

Load balancing affects session management, but can be resolved with session replication, session stickiness, and centralized session storage. 1. Session Replication Copy session data between servers. 2. Session stickiness directs user requests to the same server. 3. Centralized session storage uses independent servers such as Redis to store session data to ensure data sharing.

Explain the concept of session locking.Explain the concept of session locking.Apr 29, 2025 am 12:39 AM

Sessionlockingisatechniqueusedtoensureauser'ssessionremainsexclusivetooneuseratatime.Itiscrucialforpreventingdatacorruptionandsecuritybreachesinmulti-userapplications.Sessionlockingisimplementedusingserver-sidelockingmechanisms,suchasReentrantLockinJ

Are there any alternatives to PHP sessions?Are there any alternatives to PHP sessions?Apr 29, 2025 am 12:36 AM

Alternatives to PHP sessions include Cookies, Token-based Authentication, Database-based Sessions, and Redis/Memcached. 1.Cookies manage sessions by storing data on the client, which is simple but low in security. 2.Token-based Authentication uses tokens to verify users, which is highly secure but requires additional logic. 3.Database-basedSessions stores data in the database, which has good scalability but may affect performance. 4. Redis/Memcached uses distributed cache to improve performance and scalability, but requires additional matching

Define the term 'session hijacking' in the context of PHP.Define the term 'session hijacking' in the context of PHP.Apr 29, 2025 am 12:33 AM

Sessionhijacking refers to an attacker impersonating a user by obtaining the user's sessionID. Prevention methods include: 1) encrypting communication using HTTPS; 2) verifying the source of the sessionID; 3) using a secure sessionID generation algorithm; 4) regularly updating the sessionID.

What is the full form of PHP?What is the full form of PHP?Apr 28, 2025 pm 04:58 PM

The article discusses PHP, detailing its full form, main uses in web development, comparison with Python and Java, and its ease of learning for beginners.

How does PHP handle form data?How does PHP handle form data?Apr 28, 2025 pm 04:57 PM

PHP handles form data using $\_POST and $\_GET superglobals, with security ensured through validation, sanitization, and secure database interactions.

What is the difference between PHP and ASP.NET?What is the difference between PHP and ASP.NET?Apr 28, 2025 pm 04:56 PM

The article compares PHP and ASP.NET, focusing on their suitability for large-scale web applications, performance differences, and security features. Both are viable for large projects, but PHP is open-source and platform-independent, while ASP.NET,

Is PHP a case-sensitive language?Is PHP a case-sensitive language?Apr 28, 2025 pm 04:55 PM

PHP's case sensitivity varies: functions are insensitive, while variables and classes are sensitive. Best practices include consistent naming and using case-insensitive functions for comparisons.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function