0

0

ubuntu下安装 nginx + php + memcached + mariadb

php中文网

php中文网

发布时间:2016-06-06 19:44:07

|

1260人浏览过

|

来源于php中文网

原创

一,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 默认的虚拟主

一,apt-get 安装

1,安装nginx

sudo apt-get install nginx

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

程序文件在/usr/sbin/nginx 

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

立即学习PHP免费学习笔记(深入)”;

并已经在/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 显示帮助

  查看服务是否启动

易优建筑工程集团公司网站源码1.7.1
易优建筑工程集团公司网站源码1.7.1

易优建筑工程集团公司网站源码是基于易优cms开发的,前端页面针对建筑工程施工公司集团的实际需求进行设计,建站行业公司只要通过后台把网站名称、栏目名称、图片替换一下就可以制作属于自己的网站了。前端页面截图 网站首页 项目展示 集团资讯 联系我们项目案例 安装环境要求:操作系统:Linux/Unix/Windows软件环境:Apache/Nginx/IIS + PHP 5.5~7.1 + MySQL

下载

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 130124124  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 130124124  4280 ?        S    16:25   0:00 php-fpm: pool www  
www-data  3567  0.0  0.0 130124124  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

PHP速学教程(入门到精通)
PHP速学教程(入门到精通)

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载

相关标签:

本站声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

相关专题

更多
虚拟号码教程汇总
虚拟号码教程汇总

本专题整合了虚拟号码接收验证码相关教程,阅读下面的文章了解更多详细操作。

29

2025.12.25

错误代码dns_probe_possible
错误代码dns_probe_possible

本专题整合了电脑无法打开网页显示错误代码dns_probe_possible解决方法,阅读专题下面的文章了解更多处理方案。

20

2025.12.25

网页undefined啥意思
网页undefined啥意思

本专题整合了undefined相关内容,阅读下面的文章了解更多详细内容。后续继续更新。

37

2025.12.25

word转换成ppt教程大全
word转换成ppt教程大全

本专题整合了word转换成ppt教程,阅读专题下面的文章了解更多详细操作。

6

2025.12.25

msvcp140.dll丢失相关教程
msvcp140.dll丢失相关教程

本专题整合了msvcp140.dll丢失相关解决方法,阅读专题下面的文章了解更多详细操作。

2

2025.12.25

笔记本电脑卡反应很慢处理方法汇总
笔记本电脑卡反应很慢处理方法汇总

本专题整合了笔记本电脑卡反应慢解决方法,阅读专题下面的文章了解更多详细内容。

6

2025.12.25

微信调黑色模式教程
微信调黑色模式教程

本专题整合了微信调黑色模式教程,阅读下面的文章了解更多详细内容。

5

2025.12.25

ps入门教程
ps入门教程

本专题整合了ps相关教程,阅读下面的文章了解更多详细内容。

4

2025.12.25

苹果官网入口直接访问
苹果官网入口直接访问

苹果官网直接访问入口是https://www.apple.com/cn/,该页面具备0.8秒首屏渲染、HTTP/3与Brotli加速、WebP+AVIF双格式图片、免登录浏览全参数等特性。本专题为大家提供相关的文章、下载、课程内容,供大家免费下载体验。

218

2025.12.24

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
Rust 教程
Rust 教程

共28课时 | 3.8万人学习

【web前端】Node.js快速入门
【web前端】Node.js快速入门

共16课时 | 1.9万人学习

MySQL 初学入门(mosh老师)
MySQL 初学入门(mosh老师)

共3课时 | 0.3万人学习

关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号