Home > php教程 > php手册 > ubuntu下安装 nginx + php + memcached + mariadb

ubuntu下安装 nginx + php + memcached + mariadb

WBOY
Release: 2016-06-06 19:44:07
Original
1215 people have browsed it

一,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
Copy after login

所有的配置文件都在/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
Copy after login

 

2,安装php

fpm

sudo apt-get install php5-fpm<br>/etc/init.d/php5-fpm start
Copy after login

or fcgi

sudo apt-get install php5-cli php5-cgi php5-mysql
Copy after login

 

3,安装FastCgi

<span> apt-get install php5-cgi</span>
Copy after login

也可以再安装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
Copy after login
Copy after login

参数意义:

* -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等
Copy after login

重启fcgi

php-cgi: 先杀死进程

sudo killall -HUP php5-cgi
Copy after login

再启动fcgi

4,配置nginx支持php

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

server_name localhost;
Copy after login

修改index的一行修改为:

index index.php index.html index.htm;
Copy after login

去掉下面部分的注释用于支持 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;
}
Copy after login

重新启动nginx:

/etc/init.d/nginx stop
/etc/init.d/nginx start
Copy after login

启动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
Copy after login
Copy after login

6,安装memcached服务端

sudo apt-get install memcached
Copy after login

  启动memcached服务

memcached -d -m 128 -p 11111 -u root
Copy after login

  参数说明:

-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 显示帮助
Copy after login

  查看服务是否启动

ps aux | grep memcached
Copy after login

  

7,安装memcached php扩展

sudo apt-get install php5-memcached
Copy after login

 安装完成后,需要重启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-<span>server
</span>/etc/init.d/mysql start
Copy after login

 

 

二,源代码编译方式

1,准备编译环境

apt-get install build-essential
Copy after login

2,下载php源码

cd /usr/local/<span>src
wget http:</span>//cn2.php.net/distributions/php-5.5.13<span>.tar.gz
sudo tar </span>-zxvf php-5.5.13<span>.tar.gz
cd php</span>-5.5.13<span>
.</span>/configure --prefix=/etc/php-5.5.13 --without-pear --with-config<span>-file</span>-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-<span>curl
make
make install</span>
Copy after login

 

 初次configure会出现

configure: error: mcrypt.h not found. Please reinstall libmcrypt.
Copy after login

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

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

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

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

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

拷贝php.ini文件:

root@ubuntu:/etc/php-5.5.13/etc<span>#</span><span> cp /usr/local/src/php-5.5.13/php.ini-development php.ini</span>
Copy after login

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

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

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

停止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

Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template