centos下nginx+php+mysql

2025-11-05 08:42:32

1、 首页 Linuxcentos下nginx+php+mysql

centos下nginx+php+mysql

2015/09/15

|

Linux

|

|

0 Reply

代理服务器使用的是nginx,现在需要使用php,又不愿意在安装一个apache来运行php,那就用nginx和php-fpm来支持php文件的解析和执行

1、安装php依赖程序

yum -y install yum-fastestmirror ntp patch make flex bison tar libtool libtool-libs kernel-devel libjpeg libjpeg-devel libpng libpng-devel libtiff libtiff-devel gettext gettext-devel libxml2 libxml2-devel zlib-devel  net-snmp file glib2 glib2-devel bzip2 diff* openldap-devel bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel vim-minimal unzip

# 安装PHP支持GD库模块yum -y install freetype freetype-devel png jpeg zlib gd php-gd*# 安装PHP 5.* 组件yum -y install libiconv libevent mhash mcrypt# 安装MYDSQL所需要系统库相关库文件yum install -y gcc gcc-c++ gcc-g77 autoconf automake  fiex* ncurses-devel libmcrypt* libtool-ltdl-devel*

注意:

1、如果不能安装的话,请更新的你的yum源再试。

2、如果报yum找不到libmcrypt

yum  install epel-release  //扩展包更新包

yum  update //更新yum源yum install libmcrypt libmcrypt-devel mcrypt mhash  就ok了

2、下载php和nginx最新版稳定安装包

php下载地址:http://php.net/downloads.php

nginx下载地址:http://www.nginx.cn/nginx-download

3、php安装

解压缩下载的php安装文件,这里以php-5.5.29.tar.gz为例

#tar zxvf php-5.5.29.tar.gz

#cd php-5.5.29

./configure –prefix=/usr/local/php5 –with-config-file-path=/uusr/local/php5/lib –with-mysql –with-libxml-dir –enable-ftp –enable-sockets –with-gd –with-jpeg-dir –with-png-dir –with-freetype-dir –with-zlib-dir –enable-gd-native-ttf –enable-magic-quotes –with-iconv –enable-mbstring=all –disable-cgi –with-openssl –with-mcrypt –enable-bcmath –enable-calendar –enable-exif –enable-libxml –with-bz2 –with-curl –with-xmlrpc –with-gettext –disable-cli  –disable-debug  –enable-zend-multibyte –with-mhash –enable-pcntl –enable-sysvsem –enable-inline-optimization –enable-soap –disable-ipv6 –enable-fpm

注意:如果你的mysql是rpm安装的话可以不指定路径,其他路径按照自己的要求设定

#make

#make install

#cp php.ini-development /usr/local/php5/lib/php.ini

#cd /usr/local/php5

#cd etc

#cp  php-fpm.conf.default  php-fpm.conf

#vim php-fpm.conf启用如下几行,即去掉前面的分号(;)    pid = run/php-fpm.pid    error_log = log/php-fpm.log    log_level = notice    listen = 127.0.0.1:9000    listen.allowed_clients = 127.0.0.1    pm = dynamic    pm.max_children = 50    pm.start_servers = 5    pm.min_spare_servers = 5    pm.max_spare_servers = 35    pm.max_requests = 500    env[HOSTNAME] = $HOSTNAME    env[PATH] = /usr/local/bin:/usr/bin:/bin    env[TMP] = /tmp    env[TMPDIR] = /tmp    env[TEMP] = /tmpwq保存退出

#/usr/local/php5/sbin/php-fpm# netstat -antpl (如果看到9000端口,PHP-FPM配置成功)

4、nginx安装

# 安装NGINX 组件yum -y install pcre*

进入下载目录,解压nginx安装程序包并进入目录

#tar zxvf nginx-1.5.7.tar.gz

#cd nginx-1.5.7

#./configure –prefix=/usr/local/nginx –with-http_stub_status_module –with-http_ssl_module –with-http_gzip_static_module –with-pcre –http-client-body-temp-path=/tmp/nginx_client –http-proxy-temp-path=/tmp/nginx/proxy –http-fastcgi-temp-path=/tmp/nginx/fastcgi  –http-uwsgi-temp-path=/tmp/nginx/uwsgi –http-scgi-temp-path=/tmp/nginx/scgi

#make#make instal

修改nginx.conf配置为

location ~ \.php$ {            root           html;   #你的网站目录            fastcgi_pass   127.0.0.1:9000;            fastcgi_index  index.php;            fastcgi_param  SCRIPT_FILENAME  $document_root/$fastcgi_script_name;            include        fastcgi_params;

}测试:在html(/usr/local/nginx/html)目录下编辑文件phpinfo.php,内容为:

<?phpphpinfo();?>

启动nginx

#/usr/local/nginx/sbin/nginx

访问http://localhost/phpinfo.php,能够访问正常

到此nginx+php环境搭建完毕,mysql的安装请看rpm安装mysql篇,请移步http://www.mxznblog.com/linux/rpmmysql.html

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
相关推荐
  • 阅读量:100
  • 阅读量:170
  • 阅读量:53
  • 阅读量:169
  • 阅读量:127
  • 猜你喜欢