一,apt-get 安装

1,安装nginx

sudo apt-get install nginx

所有的配置文件都在/etc/nginx下,虚拟主机配置在/etc/nginx/sites-available下

程序文件在/usr/sbin/nginx

日志放在了/var/log/nginx中

并已经在/etc/init.d/下创建了启动脚本nginx

默认的虚拟主机的目录设置在了/var/www/nginx-default

  启动nginx

sudo /etc/init.d/nginx start
sudo /etc/init.d/nginx reload

2,安装php

fpm

sudo apt-get install php5-fpm
/etc/init.d/php5-fpm start

or fcgi

sudo apt-get install php5-cli php5-cgi php5-mysql

3,安装FastCgi

 apt-get install php5-cgi

也可以再安装spawn-fcgi,spawn-fcgi是fastcgi的管理程序,从Lighthttpd独立出来的项目。实际运营中可以使用php-fpm(php的fastcgi php manager). php 5.3.3中自带php-fpm,但我现在的版本是php 5.3.2.

采用spawn-fcgi执行

sudo /usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 5 -u www-data -g www-data -f /usr/bin/php5-cgi -P /var/run/fastcgi-php.pid

参数意义:

* -f 指定调用FastCGI的进程的执行程序位置,根据系统上所装的PHP的情况具体设置
* -a 绑定到地址addr
* -p 绑定到端口port
* -s 绑定到unix socket的路径path
* -C 指定产生的FastCGI的进程数,默认为5(仅用于PHP)
* -P 指定产生的进程的PID文件路径
* -u和-g FastCGI使用什么身份(-u 用户 -g 用户组)运行,Ubuntu下可以使用www-data,其他的根据情况配置,如nobody、apache等

重启fcgi

php-cgi: 先杀死进程

sudo killall -HUP php5-cgi

再启动fcgi

4,配置nginx支持php

修改nginx的配置文件:/etc/nginx/sites-available/default 修改主机名:

server_name localhost;

修改index的一行修改为:

index index.php index.html index.htm;

去掉下面部分的注释用于支持 php 脚本:

location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000; #
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/nginx-default$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}

重新启动nginx:

/etc/init.d/nginx stop
/etc/init.d/nginx start

启动fastcgi php:

sudo /usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 5 -u www-data -g www-data -f /usr/bin/php5-cgi -P /var/run/fastcgi-php.pid

6,安装memcached服务端

sudo apt-get install memcached

  启动memcached服务

memcached -d -m 128 -p 11111 -u root

  参数说明:

-p 监听的端口
-l 连接的IP地址, 默认是本机
-d start 启动memcached服务
-d restart 重起memcached服务
-d stop|shutdown 关闭正在运行的memcached服务
-d install 安装memcached服务
-d uninstall 卸载memcached服务
-u 以的身份运行 (仅在以root运行的时候有效)
-m 最大内存使用,单位MB。默认64MB
-M 内存耗尽时返回错误,而不是删除项
-c 最大同时连接数,默认是1024
-f 块大小增长因子,默认是1.25-n 最小分配空间,key+value+flags默认是48
-h 显示帮助

  查看服务是否启动

ps aux | grep memcached

  

7,安装memcached php扩展

sudo apt-get install php5-memcached

安装完成后,需要重启nginx和fcgi,才能使memcached生效。

参考资料:

http://www.gaojinbo.com/ubuntu12-04-apt-get-install-php5-5%E5%AE%89%E8%A3%85.html

8 安装mariadb

sudo apt-get install mariadb-server
/etc/init.d/mysql start

二,源代码编译方式

1,准备编译环境

apt-get install build-essential

2,下载php源码

cd /usr/local/src
wget http://cn2.php.net/distributions/php-5.5.13.tar.gz
sudo tar -zxvf php-5.5.13.tar.gz
cd php-5.5.13
./configure --prefix=/etc/php-5.5.13 --without-pear --with-config-file-path=/etc/php-5.5.13/etc/ --enable-shared=yes --with-zlib-dir=/usr/local/lib --with-pcre-dir=/usr/local/lib --enable-zip --enable-mysqlnd --with-libxml-dir=/usr/local/lib --with-iconv-dir=/usr/local/lib --enable-sockets --enable-soap --enable-opcache --enable-embedded-mysqli --with-mysqli --with-mysql --with-mcrypt=/usr/local/lib --enable-mbstring --with-mhash --enable-gd-native-ttf --with-freetype-dir=/usr/local/lib --with-png-dir --with-jpeg-dir=/usr/local/lib --with-gd --enable-fpm --with-fpm-user=www-data --with-fpm-group=www-data --enable-ftp --enable-dba --with-curl
make
make install

初次configure会出现

configure: error: mcrypt.h not found. Please reinstall libmcrypt.

这是由于版权关系,未带mcrypt包,需要先安装:

cd /usr/local/src
wget http://softlayer.dl.sourceforge.net/sourceforge/mcrypt/libmcrypt-2.5.8.tar.gz
tar -zxvf libmcrypt-2.5.8.tar.gz
cd /usr/local/src/libmcrypt-2.5.8
./configure --prefix=/usr/local
make
make install 

其他安装过程缺少相关依赖包的处理可参见:http://zgadzaj.com/how-to-install-php-53-and-52-together-on-ubuntu-1204

如果未安装编译环境,会出现:

root@ubuntu:/usr/local/src/libmcrypt-2.5.8# ./configure --prefix=/usr/local
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for gawk... no
checking for mawk... mawk
checking whether make sets $(MAKE)... yes
checking whether to enable maintainer-specific portions of Makefiles... no
checking whether make sets $(MAKE)... (cached) yes
checking for g++... no
checking for c++... no
checking for gpp... no
checking for aCC... no
checking for CC... no
checking for cxx... no
checking for cc++... no
checking for cl... no
checking for FCC... no
checking for KCC... no
checking for RCC... no
checking for xlC_r... no
checking for xlC... no
checking for C++ compiler default output file name... configure: error: C++ compiler cannot create executables
See `config.log' for more details.

拷贝php.ini文件:

root@ubuntu:/etc/php-5.5.13/etc# cp /usr/local/src/php-5.5.13/php.ini-development php.ini

开机自启动php-fpm,运行php-fpm:

/usr/local/src/php-5.5.13为源码路径。

root@ubuntu:/usr/local/src/php-5.5.13/sapi/fpm# cp php-fpm /etc/init.d/
root@ubuntu:/etc/php-5.5.13/etc# cp php-fpm.conf.default php-fpm.conf
root@ubuntu:/etc/php-5.5.13/etc# /etc/init.d/php-fpm
root@ubuntu:/etc/php-5.5.13/etc# ps aux|grep fpm
root 3565 0.0 0.0 130124 4980 ? Ss 16:25 0:00 php-fpm: master process (/etc/php-5.5.13/etc/php-fpm.conf)
www-data 3566 0.0 0.0 130124 4280 ? S 16:25 0:00 php-fpm: pool www
www-data 3567 0.0 0.0 130124 4280 ? S 16:25 0:00 php-fpm: pool www
root 3569 0.0 0.0 12256 940 pts/2 S+ 16:25 0:00 grep --color=auto fpm

停止fpm,直接kill相关进程即可。

重新编译php,添加了一个--with-openssl选项,但是总不起作用。最后删除了源码,重新解压编译才起作用。

看来是这个原因:

需要重新安装 php ,然而是源代码包中执行 make clean 后,然后configure ,make, make install, 发现还是和上次编译的一样,参数没有变化。 肯定是没有删除掉原来configure 出的Makefile文件,查资料后,发现不能用make clean 要用 make distclean 才可以删除包括Makefile文件在内的文件。 重新编译,好了。

参考资料:

http://asange.blog.51cto.com/7125040/1229976

http://my.oschina.net/ruiorz/blog/280289

ubuntu下安装 nginx + php + memcached + mariadb的更多相关文章

  1. Ubuntu下安装Nginx,PHP5(及PHP-FPM),MySQL

    .简介: Tomcat在高并发环境下处理动态请求时性能很低,而在处理静态页面更加脆弱.虽然Tomcat的最新版本支持epoll,但是通过Nginx来处理静态页面要比通过Tomcat处理在性能方面好很多 ...

  2. 转- 在ubuntu下安装Nginx

    一. 安装包安装 1.1 安装Nginx $sudo apt-get install nginx Ubuntu安装之后的文件结构大致为: 所有的配置文件都在/etc/nginx下,并且每个虚拟主机已经 ...

  3. Ubuntu下安装Nginx

    转载自:http://www.cnblogs.com/skynet/p/4146083.html 1.Nginx安装 我使用的环境是64位 Ubuntu 14.04, Nginx是Nginx 1.10 ...

  4. Ubuntu下安装Nginx详细步骤

    Nginx安装之前需要三个支持: 模块依赖性 ①gzip 模块需要 zlib 库 ②rewrite 模块需要 pcre 库 ③ssl 功能需要 openssl 库 预先编译好的包: sudo apt- ...

  5. ubuntu下安装nginx -php

    mysql : sudo apt-get install mysql-server mysql-client nginx: sudo apt-get install nginx安装Nginx稳定版本 ...

  6. Ubuntu下安装nginx及使用

    首先介绍以下nginx.下图来自百科介绍:详细介绍地址:https://baike.baidu.com/item/nginx/3817705?fr=aladdin 在我们平时的开发娱乐中,也许并不会涉 ...

  7. ubuntu下安装memcache及memcached

    memcache 和 memcached 有什么区别呢? memcache最早是在2004年2月开发的,而memcached最早是在2009年1月开发的.所以memcache的历史比memcached ...

  8. ubuntu 下安装nginx

    y@y:~$ sudo apt-get install nginx y@y:~$ sudo service nginx start y@y:~$ nginx默认使用80端口,打开浏览器输入:http: ...

  9. Ubuntu下安装与卸载Nginx

    1.Ubuntu下安装Nginx比较简单 敲入下列命令即可: sudo apt-get update sudo apt-get install nginx 2.Ubuntu下卸载,稍不注意就会入坑 s ...

随机推荐

  1. 整理Crontab 定时计划

    一. 什么是crontab? crontab命令常见于Unix和类Unix的操作系统之中,用于设置周期性被执行的指令.该命令从标准输入设备读取指令,并将其存放于“crontab”文件中,以供之后读取和 ...

  2. python 生成HTmL报告页面 V1.3 修改字体颜色

    HTML报告V1.3 根据文字内容显示不同的字体颜色: 代码如下: # -*- coding=utf-8 -*- import time,os """ V1.2 1.生成 ...

  3. bpm被攻击事件

    bpm登录不上,服务器是windows2008,从深信服上面设置了ddos每秒钟连接超5000次封锁,阻断后面的IP连接,,深信服DDOS日志没有记录 在bpm服务器上面通过netstat -a查看发 ...

  4. 教你如何检查一个函数是否为JavaScript运行时环境内建函数

    在开发过程中,对于某些API在现有的JavaScript运行时环境不支持的时候,我们大都会采用加入polyfill来解决这个问题.但有些时候我们可能需要知道现在某个API到底是否为运行时环境所原生支持 ...

  5. vue自定义拖动指令

    1.在项目开发中,需要对div进行拖动.因为需要自定义组件 a>定义全局拖拽指令: 定义全局指令,需要在main.js中写入vue.directive('drag',{});即可.但是一般会在外 ...

  6. Codeforces 919D Substring (拓扑图DP)

    手动博客搬家: 本文发表于20180716 10:53:12, 原地址https://blog.csdn.net/suncongbo/article/details/81061500 给定一个\(n\ ...

  7. QT创建快捷方式

    1.当我第一次安装完QT后发现它并没有在桌面上给我创建快捷方式,使用起来很难受啊,于是寻找办法,终于找到一个懒办法: 首先进入到上图的BIN目录下找到qtcreator文件,双击运行,然后系统就会在左 ...

  8. JavaSE 学习笔记之Java语法基础(二)

    1,关键字:其实就是某种语言赋予了特殊含义的单词. 保留字:其实就是还没有赋予特殊含义,但是准备日后要使用过的单词. 2,标示符:其实就是在程序中自定义的名词.比如类名,变量名,函数名.包含 0-9. ...

  9. uva 交叉染色法10004

    鉴于网上讲交叉染色的资料比较少,于是我把我自己的心得与方法贴出来,方便与大家共同进步. 二分图: 百度百科传送门 wiki百科传送门 判断一个图是否为二分图可以用交叉染色的方法来判断,可以用BFS,也 ...

  10. js的map文件

    什么是source map文件 source map文件是js文件压缩后,文件的变量名替换对应.变量所在位置等元信息数据文件,一般这种文件和min.js主文件放在同一个目录下. 比如压缩后原变量是ma ...