LNMP源碼包部署筆記

一.從官方下載最新版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
php

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

(重命名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
mysql

啓動:nginx

    /usr/local/nginx/sbin/nginxc++

中止:sql

    結束nginx直接結束進程就能夠,也能夠killall -r nginx
vim

    /usr/local/nginx/sbin/nginx -s stop瀏覽器

從新加載配置文件(不重啓加載配置文件):curl

    /usr/local/nginx/sbin/nginx -s reloadsocket

添加到開機啓動:
    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
一、編輯/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,測試

相關文章
相關標籤/搜索