源碼搭建LNMP基礎環境

源碼搭建LNMP基礎環境

實驗環境:
redhat 企業版 5.4
已安裝的軟件包組
Development Libraries
Development Tools
Legacy Software Development
X Software Development
GNME Software Devleopment
KDE Software Development
所需要的源碼包
cmake-2.8.7.tar.gz
libevent-2.0.18-stable.tar.gz
mysql-5.5.22.tar.gz
nginx-1.1.18.tar.gz
pcre-8.12.tar.gz
以上源碼下載地址
http://nginx.org/download/nginx-1.1.18.tar.gz
http://www.cmake.org/files/v2.8/cmake-2.8.7.tar.gz
http://ftp.jaist.ac.jp/pub/mysql/Downloads/MySQL-5.5/mysql-5.5.22.tar.gz
http://cdnetworks-kr-1.dl.sourceforge.net/project/pcre/pcre/8.12/pcre-8.12.tar.gz
http://down1.chinaunix.net/distfiles/libevent-2.0.18-stable.tar.gz

實驗準備
將以上軟件包全部解壓到/usr/src目錄下
[root@localhost ~]tar -zxvf cmake-2.8.7.tar.gz -C /usr/src/
[root@localhost ~]tar -zxvf libevent-2.0.18-stable.tar.gz -C /usr/src/
[root@localhost ~]tar -zxvf pcre-8.12.tar.gz -C /usr/src/
[root@localhost ~]tar -zxvf mysql-5.5.22.tar.gz -C /usr/src/
[root@localhost ~]tar -zxvf nginx-1.1.18.tar.gz -C /usr/src/
[root@localhost ~]tar -zxvf php-5.4.0.tar.gz -C /usr/src/
[root@localhost ~]cd /usr/src/
[root@localhost src]# ll
總計 48
drwxr-xr-x 9 root root 4096 04-08 13:51 cmake-2.8.7
drwxr-xr-x 2 root root 4096 2009-10-01 debug
drwxr-xr-x 3 root root 4096 03-19 17:03 kernels
drwxr-xr-x 8 500 500 4096 11-19 04:21 libevent-2.0.16-stable
drwxr-xr-x 31 7161 wheel 4096 03-03 03:44 mysql-5.5.22
drwxr-xr-x 8 1001 1001 4096 12-15 22:05 nginx-1.0.18
drwxr-xr-x 7 1169 1169 4096 04-08 14:01 pcre-8.12
drwxr-xr-x 14 501 games 4096 02-29 15:37 php-5.4.0
drwxr-xr-x 7 root root 4096 03-19 17:20 redhat
安裝cmake,pcre,libevent
按照默認配置安裝
[root@localhost src]# cd pcre-8.12/
[root@localhost pcre-8.12]# ./configure
[root@localhost pcre-8.12]# make && make install
[root@localhost pcre-8.12]# cd ../cmake-2.8.7/
[root@localhost cmake-2.8.7]#./configure
[root@localhost cmake-2.8.7]#make && make install
[root@localhost cmake-2.8.7]# cd ../libevent-2.0.16-stable/
[root@localhost libevent-2.0.16-stable]#./configuire
[root@localhost libevent-2.0.16-stable]#make && make install
將庫文件指明到系統默認庫文件路徑下
[root@localhost libevent-2.0.16-stable]# cd /usr/local/
[root@localhost local]# vim /etc/ld.so.conf.d/libevent.conf ---->此文件名可以隨便起
        /usr/local/lib/
查看是否成功加載
[root@localhost libevent-2.0.16-stable]# ldconfig -v |grep libevent
libevent_extra-2.0.so.5 -> libevent_extra.so
libevent_core-2.0.so.5 -> libevent_core.so
libevent_pthreads-2.0.so.5 -> libevent_pthreads.so
libevent-2.0.so.5 -> libevent.so
libevent_openssl-2.0.so.5 -> libevent_openssl.so

[root@localhost libevent-2.0.16-stable]# ldconfig -v |grep pcre
libpcreposix.so.0 -> libpcreposix.so.0.0.0
libpcre.so.0 -> libpcre.so.0.0.1
libpcrecpp.so.0 -> libpcrecpp.so.0.0.0
libpcre.so.0 -> libpcre.so.0
安裝nginx
創建nginx系統用戶及組
[root@localhost nginx-1.1.18]# groupadd -r nginx
[root@localhost nginx-1.1.18]# useradd -r -g nginx -s /bin/false -M nginx
配置並安裝nginx
[root@localhost nginx-1.1.18]# ./configure \
> --prefix=/usr/local/nginx \
> --sbin-path=/usr/sbin/nginx \
> --conf-path=/etc/nginx/nginx.conf \
> --error-log-path=/var/log/nginx/error.log \
> --http-log-path=/var/log/nginx/access.log \
> --pid-path=/var/lock/nginx.lock \
> --user=nginx \
> --with-http_ssl_module \
> --with-http_flv_module \
> --with-http_gzip_static_module \
> --with-http_stub_status_module \
> --http-proxy-temp-path=/var/tmp/nginx/proxy/ \
> --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \
> --with-pcre --group=nginx 

[root@localhost nginx-1.1.18]# make && make install
[root@localhost nginx-1.1.18]# make && make install
啓動nginx
[root@localhost nginx-1.1.18]# /usr/sbin/nginx
[root@localhost nginx-1.1.18]# netstat -utpln |grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 18898/nginx: master
安裝mysql
添加系統用戶
[root@localhost mysql-5.5.22]# groupadd mysql
[root@localhost mysql-5.5.22]# useradd -r -g mysql -M mysql
配置並安裝mysql
[root@localhost mysql-5.5.22]# cmake \
> -DDCMAKE_INSTALL_PREFIX=/usr/local/mysql \
>-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock
>-DDEFAULT_CHARSET=utf8 \
>-DDEFAULT_COLLATION=utf8_general_ci \
>-DWITH_EXTRA_CHARSETS=all \
>-DWITH_MYISAM_STORAGE_ENGINE=1 \
>-DWITH_INNOBASE_STORAGE_ENGINE=1 \
>-DWITH_MEMORY_STORAGE_ENGINE=1 \
>-DWITH_READLINE=1 \
>-DENABLED_LOCAL_INFILE=1 \
>-DMYSQL_DATADIR=/data/mysql \
>-DMYSQL_USER=mysql \
>-DMYSQL_TCP_PORT=3306
----------注:mysql中的CMAKE選項


[root@localhost mysql-5.5.22]# make
[root@localhost mysql-5.5.22]# make install
修改權限
[root@localhost mysql-5.5.22]# cd /usr/local/
[root@localhost local]# chmod +w mysql
[root@localhost local]# chown -R mysql:mysql mysql
連接庫文件
[root@localhost local]# ln -s mysql/lib/libmysqlclient.so.18 /usr/lib/libmysqlclient.so.18
重做配置文件並添加啓動項
[root@localhost local]# cd /usr/local/mysql/support-files/
[root@localhost support-files]# cp my-medium.cnf /etc/my.cnf
注:my-large.cnf適用於1G內存左右的服務器,可以根據自己配置情況選用my-large.cnf 或 my-huge.cnf my-medium.cnf等不同配置
[root@localhost support-files]# cp mysql.server /etc/init.d/mysqld
建立放置數據與日誌的目錄並修改權限
[root@localhost support-files]# mkdir -p /var/mysql/data/
[root@localhost support-files]# mkdir -p /var/mysql/log/
[root@localhost support-files]# chown -R mysql:mysql /var/mysql/
初始化mysql
[root@localhost support-files]# /usr/local/mysql/scripts/mysql_install_db \
>--defaults-file=/etc/my.cnf \
>--basedir=/usr/local/mysql \
>--datadir=/var/mysql/data \
>--user=mysql
將 mysql 加入開機啓動
[root@localhost support-files]#chmod +x /etc/init.d/mysqld
[root@localhost support-files]#vim /etc/init.d/mysqld


[root@localhost support-files]#chkconfig --add mysqld
[root@localhost support-files]#chkconfig mysqld on
啓動 mysql
service mysqld start
[root@localhost php]# netstat -utpln |grep mysql
tcp 0 0 :::3306 :::* LISTEN 15955/mysqld
安裝PHP
[root@localhost php-5.4.0]# ./configure \
>--prefix=/usr/local/php \
--with-mysql=/usr/local/mysql \
--with-openssl \
--enable-fpm \
--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=/etc/php \
--with-config-file-scan-dir=/etc/php \
--with-bz2 --with-curl
make&&make install
爲php-fpm提供配置文件:
[root@localhost php]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
編輯php-fpm的配置文件:
[root@localhost php]# vim /usr/local/php/etc/php-fpm.conf


啓動php-fpm
[root@localhost php]# /usr/local/php/sbin/php-fpm
[root@localhost php]# ps aux | grep php-fpm

修改環境變量中的搜索路徑分別加php-fpm的路徑
[root@localhost php]# vim /etc/profile


[root@localhost php]# . /etc/profile
nginx與php連接
[root@localhost ~]# vim /etc/nginx/nginx.conf


[root@localhost ~]# vim /etc/nginx/fastcgi_params

新建index.php的測試頁面
[root@localhost ~]# vim /usr/local/nginx/html/index.php
<?
phpinfo();
?>

通過瀏覽器訪問此測試頁面


測試Mysql的連接是否正常
[root@localhost ~]# vim /usr/local/nginx/html/index.php

重新啓動nginx
[root@localhost ~]# pkill -1 nginx
通過瀏覽器訪問此測試頁面

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章