码迷,mamicode.com
首页 > 其他好文 > 详细

LNMP源码包部署笔记

时间:2015-10-23 12:08:38      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:

一.从官方下载最新版nginx、mysql、php安装包
wget http://nginx.org/download/nginx-1.6.2.tar.gz
wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.21.tar.gz

wget http://hk1.php.net/get/php-5.6.3.tar.gz/from/this/mirror

(重命名php安装包,mv mirror php-5.6.3.tar.gz)

二.环境准备(yum安装编译时所依赖的包)
yum install zlib-devel pcre-devel openssl-devel -y
yum install wget gcc gcc-c++ make cmake ncurses-devel libtool zilib-devel -y
yum install libevent libevent-devel -y 
yum install libxml2 libxml2-devel -y
yum install php-xml php-xml-devel -y
yum install bzip2 bzip2-* -y
yum install gd php-gd -y
yum install zip unzip -y
yum install curl libcurl libcurl-* -y



三.nginx安装
1.添加nginx组和用户
groupadd -r nginx
useradd -r -g nginx -r -s /sbin/nologin nginx


2.创建tmp文件夹
mkdir /var/tmp/nginx


3.编译安装
./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_flv_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/tmp/nginx/client/ \
--http-proxy-temp-path=/var/tmp/nginx/proxy/ \
--http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \
--http-scgi-temp-path=/var/tmp/nginx/scgi \
--with-pcre


make && makeinstall


4.拷贝配置文件
cd /usr/local/nginx/conf
cp nginx.conf.default nginx.conf


5.启动nginx、停止nginx、重启nginx

启动:

    /usr/local/nginx/sbin/nginx

停止:

    结束nginx直接结束进程就可以,也可以killall -r nginx

    /usr/local/nginx/sbin/nginx -s stop

重新加载配置文件(不重启加载配置文件):

    /usr/local/nginx/sbin/nginx -s reload

添加到开机启动:
    echo "/usr/local/nginx/sbin/nginx" >> /etc/rc.local


四.mysql编译安装
1.添加mysql组和用户
groupadd -r mysql
useradd -r -g mysql -r -s /sbin/nologin mysql


2.编译安装
说明:mysql5.5及以后的版本编译方式与之前版本不同 用cmake
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/data/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS:STRING=utf8,gbk \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DMYSQL_USER=mysql \
-DMYSQL_TCP_PORT=3306


make && make install


3.修改mysql配置文件
cp support-files/my-medium.cnf /etc/my.cnf
cp support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
chown -R mysql:mysql /usr/local/mysql


4.初始化mysql
cd /usr/local/mysql
./scripts/mysql_install_db  --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data  --user=mysql


5.启动方法:
方法1:
启动服务
/etc/init.d/mysqld start
开机启动
chkconfig –add mysqld 




方法2:
cd /usr/local/mysql/bin
./mysqld_safe --user=mysql &
//开机启动
echo "/usr/local/mysql/bin/mysqld_safe --user=mysql &" >> /etc/rc.local




6.配置mysql用户
/usr/local/mysql/bin/mysqladmin -u root password 123
/usr/local/mysql/bin/mysql -u root -p


五.php编译安装
1.编译安装
./configure \
--prefix=/usr/local/php \
--with-mysql=/usr/local/mysql \
--with-pdo-mysql \
--with-openssl \
--enable-fpm \
--enable-sockets \
--enable-sysvshm \
--enable-zip \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--enable-mbstring \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib-dir \
--with-libxml-dir=/usr \
--enable-xml \
--with-config-file-path=/usr/local/php/etc \
--with-config-file-scan-dir=/usr/local/php/etc/php.d \
--with-bz2 \
--with-gd \
--with-curl




make && make install


2.初始化配置文件

拷贝php配置文件到安装目录

# cp php.ini-production /usr/local/php/etc/php.ini 


为php-fpm提供配置文件:
# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf 
编辑php-fpm的配置文件:
# vim /usr/local/php/etc/php-fpm.conf
配置fpm的相关选项为你所需要的值:
pm.max_children = 150
pm.start_servers = 8
pm.min_spare_servers = 5
pm.max_spare_servers = 10




接下来就可以启动php-fpm了:
# /usr/local/php/sbin/php-fpm


使用如下命令来验正(如果此命令输出有中几个php-fpm进程就说明启动成功了):
# ps aux | grep php-fpm


六.整合nginx和php5
1、编辑/etc/nginx/nginx.conf,在server范围里添加如下选项:
location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            include        fastcgi.conf;
        }


并在所支持的主页面格式中添加php格式的主页,类似如下:
在server内修改以下两行
root   html;
index  index.php index.html index.htm;


2.重启nginx服务


3.在/usr/html新建index.php的测试页面,测试php是否能正常工作:
# cat > /usr/html/index.php << EOF
<?php
phpinfo();
?>


通过浏览器访问测试


七.基于域名访问的虚拟主机配置
1.mkdir /usr/local/nginx/conf/vhost
2.在 nginx.conf配置文件 http范围内加上 include vhost/*.conf
3.在/usr/local/nginx/conf/vhost里新建虚拟主机的配置文件,配置文件建议命名:域名.conf
配置文件内容如下:
/usr/local/nginx/conf/vhost/demo.mhj.com
server {
        listen       80;
        server_name  cloud.010host.com;




            root   /data/www/cloud.010host.com;
            index  index.php index.html index.htm;


        #error_page  404              /404.html;


        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        #location = /50x.html {
        #    root   html;
        #}




        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            include        fastcgi.conf;
        }


        # deny access to .htaccess files, if Apache‘s document root
        # concurs with nginx‘s one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }
4.重启nginx,测试


LNMP源码包部署笔记

标签:

原文地址:http://my.oschina.net/u/783086/blog/521049

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!