ubuntu下安装 nginx + php + memcached + mariadb
一,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的更多相关文章
- Ubuntu下安装Nginx,PHP5(及PHP-FPM),MySQL
.简介: Tomcat在高并发环境下处理动态请求时性能很低,而在处理静态页面更加脆弱.虽然Tomcat的最新版本支持epoll,但是通过Nginx来处理静态页面要比通过Tomcat处理在性能方面好很多 ...
- 转- 在ubuntu下安装Nginx
一. 安装包安装 1.1 安装Nginx $sudo apt-get install nginx Ubuntu安装之后的文件结构大致为: 所有的配置文件都在/etc/nginx下,并且每个虚拟主机已经 ...
- Ubuntu下安装Nginx
转载自:http://www.cnblogs.com/skynet/p/4146083.html 1.Nginx安装 我使用的环境是64位 Ubuntu 14.04, Nginx是Nginx 1.10 ...
- Ubuntu下安装Nginx详细步骤
Nginx安装之前需要三个支持: 模块依赖性 ①gzip 模块需要 zlib 库 ②rewrite 模块需要 pcre 库 ③ssl 功能需要 openssl 库 预先编译好的包: sudo apt- ...
- ubuntu下安装nginx -php
mysql : sudo apt-get install mysql-server mysql-client nginx: sudo apt-get install nginx安装Nginx稳定版本 ...
- Ubuntu下安装nginx及使用
首先介绍以下nginx.下图来自百科介绍:详细介绍地址:https://baike.baidu.com/item/nginx/3817705?fr=aladdin 在我们平时的开发娱乐中,也许并不会涉 ...
- ubuntu下安装memcache及memcached
memcache 和 memcached 有什么区别呢? memcache最早是在2004年2月开发的,而memcached最早是在2009年1月开发的.所以memcache的历史比memcached ...
- ubuntu 下安装nginx
y@y:~$ sudo apt-get install nginx y@y:~$ sudo service nginx start y@y:~$ nginx默认使用80端口,打开浏览器输入:http: ...
- Ubuntu下安装与卸载Nginx
1.Ubuntu下安装Nginx比较简单 敲入下列命令即可: sudo apt-get update sudo apt-get install nginx 2.Ubuntu下卸载,稍不注意就会入坑 s ...
随机推荐
- esp32(M5STACK) ARDUINO开发环境搭建(ubuntu)
首先去官网下载arduino https://www.arduino.cc/en/main/software 由于国产链接下载慢的缘故,所以可以采用百度网盘的方式进行下载,具体下载方法 ...
- eas之MrpUI
package com.kingdee.eas.custom.mrp.client; import java.awt.Component;import java.awt.event.*;import ...
- 然而,该来的还是来了(Diary)
2017-05-07 LG月赛成功炸掉...发现自己真的好多东西不会啊.对某些知识仅仅有最基础的一点理解啊!连线段树都理解不了怎么办?归并排序(including分治+贪心)全部炸掉啊.感觉自 ...
- centos7系统修改内核
修改centos6的内核启动顺序,只需要修改/etc/grub.conf 里的default项配置即可.那么centos7系统该如何修改呢? 下面就centos7系统修改内核,做如下记录: 一般在编译 ...
- PAT 1065. A+B and C
Given three integers A, B and C in [-263, 263], you are supposed to tell whether A+B > C. Input S ...
- css sprites拼合
一.什么是css sprites css sprites直译过来就是CSS精灵.通常被解释为“CSS图像拼合”或“CSS贴图定位”.就是把网页中一些背景图片整合拼合成一张图片中,再利用DIV CSS的 ...
- APIO2017听课笔记关键词
- hdu 2089 数位dp入门题
#include<stdio.h> //dp[i][0]代表不存在不吉利数字 //dp[i][1]代表不存在不吉利数字但是以2开头 //dp[i][2]代表存在不吉利数字 #define ...
- 数据结构----队列:顺序队列&顺序循环队列、链式队列、顺序优先队列
一.队列的概念: 队列(简称作队,Queue)也是一种特殊的线性表,队列的数据元素以及数据元素间的逻辑关系和线性表完全相同,其差别是线性表允许在任意位置插入和删除,而队列只允许在其一端进行插入操作在其 ...
- PAAS平台的web应用性能測试与分析
引言 为什么我会写这一篇博客,由于近期非常多京东云擎jae的用户反应一个问题就是他们部署在jae上面的应用訪问非常慢,有极少数应用甚至常常出现504超时现象.当然大家首先想到的是jae性能太差,这也是 ...