LNMP ---》源碼包裝nginx MySQL5.6 php
1.安裝mysql
#先解開mysql5.6源碼包
#tar -zxf mysql-5.6.25.tar.gz
#cd mysql-5.6.25/
#useradd mysql
#yum -y install cmake gcc
#yum install gcc-c++
# yum -y install ncurses-devel
#cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DSYSCONFDIR=/etc -DMYSQL_DATADIR=/usr/local/mysql/data -DMYSQL_TCP_PORT=3306 -DMYSQL_USER=mysql -DEXTRA_CHARSETS=all
#make &&make install
#cd /usr/local/mysql/
#./scripts/mysql_install_db --datadir=/usr/local/mysql/data/ --user=mysql (初始化數(shù)據(jù)庫)
#ls /usr/local/mysql/data/
#ls -l /usr/local/mysql/data/mysql
復(fù)制主配置文件啟動(dòng)腳本:
#ls support-files/
#cp support-files/my-default.cnf /etc/my.cnf
#cp support-files/mysql.server /etc/init.d/mysql
#chmod +x /etc/init.d/mysql
#chkcpmfig --add mysql (添加為系統(tǒng)服務(wù))
#chkconfig --list mysql
#chkconfig mysql on
#service mysql status
#netstat -anptu |grep :3306
#service mysql start
#ln -s /usr/local/mysql/* /bin 把命令的路徑添加到path變量里
#echo "export PATH=$PATH:/usr/local/mysql/bin" >>/etc/profile
#source /etc/profile
#echo $PATH
/usr/local/mysql/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/root/bin
#mysql -uroot -p
mysql>quit
設(shè)置數(shù)據(jù)庫管理員從本機(jī)登錄的密碼
#mysqladmin -hlocalhost -uroot password "123456" 這是設(shè)置密碼
#mysql -uroot -p123456
mysql>quit
修改密碼
# mysqladmin -hlocalhost -uroot -p password "11" (新密碼)
Enter password: (這填舊密碼)
#mysql -uroot -p11
#vim /etc/ls.so.conf (庫文件連接 系統(tǒng)啟動(dòng)會(huì)讀這個(gè)文件,會(huì)加載程序的庫文件,第三方軟件就能找到mysql庫文件位置)
/usr/local/mysql/lib/
#ldconfig -v |grep -i --color mysql
2.安裝PHP
安裝PHP 先安裝擴(kuò)展包
libmcrypt-2.5.8.tar.gz
mhash-0.9.9.9.tar.gz
# tar zxf mhash-0.9.9.9.tar.gz
# cd mhash-0.9.9.9/
# ./configure
# make &&make install
# tar -zxf libmcrypt-2.5.8.tar.gz
# cd libmcrypt-2.5.8/
# ./configure
# make &&make install
把庫文件更新到系統(tǒng)默認(rèn)搜索的目錄下
# ln -s /usr/local/lib/libmcrypt* /usr/lib/
# ln -vs /usr/local/lib/libmhash.* /usr/lib/
#ldconfig -v
安裝PHP
# tar zxf php-5.4.24.tar.gz
# cd php-5.4.24/
# ./configure --prefix=/usr/local/php5 --with-mysql=/usr/local/mysql --enable-fpm --enable-mbstring --with-mcrypt --with-mhash --with-config-file-path=/usr/local/php5/etc --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-memached
# yum list |grep xml2* (看上面報(bào)錯(cuò),缺少什么先找到再裝)
# yum -y install *xml2*
# ./configure --prefix=/usr/local/php5 --with-mysql=/usr/local/mysql --enable-fpm --enable-mbstring --with-mcrypt --with-mhash --with-config-file-path=/usr/local/php5/etc --with-mysqli=/usr/local/mysql/bin/mysql_config
# make && make install
3.安裝nginx
配置nginx服務(wù)接收到訪問php文件的請(qǐng)求,把請(qǐng)求發(fā)給本機(jī)的9000端口
安裝nginx
創(chuàng)新互聯(lián)公司主要從事成都網(wǎng)站設(shè)計(jì)、網(wǎng)站制作、網(wǎng)頁設(shè)計(jì)、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)海湖新,十年網(wǎng)站建設(shè)經(jīng)驗(yàn),價(jià)格優(yōu)惠、服務(wù)專業(yè),歡迎來電咨詢建站服務(wù):028-86922220
#useradd nginx
#tar -zxf nginx-1.8.0.tar.gz
#cd nginx-1.8.0/
#yum -y install gcc gcc-c++ openssl openssl-devel pcre pcre-devel
安裝依賴包,由于lnmp安裝在一臺(tái)服務(wù)器上,有些已經(jīng)安裝過了,可用直接./configure編譯了,缺少什么包會(huì)報(bào)錯(cuò)再安裝就行,一般是下面這些依賴:)[[#yum -y install gcc zlib-devel openssl-devel ]]
#./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module
#yum list |grep pcre
#yum -y install pcre*
# ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module
#make && make install
#ln -s /usr/local/nginx/sbin/nginx /usr/sbin/
#netstat -anptu |grep nginx (先要把之前別的占用80端口關(guān)了)
#nginx (#chkconfig nginx on 這里nginx沒有啟動(dòng)腳本,不能設(shè)置開機(jī)自啟 寫腳本)
# echo 1111 > /usr/local/nginx/html/test.html
# yum -y install elinks
# elinks --dump http://localhost/test.html
1111
#vim /usr/local/nginx/conf/nginx.conf
65-71 注釋去掉
69行: fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#nginx -s reload
編寫php腳本文件
#cat /usr/local/nginx/html/test.php
phpinfo();
?>
客戶端訪問
#http://192.168.4.254/test.php (能解釋php代碼)
測(cè)試php程序能否連接數(shù)據(jù)庫
先把數(shù)據(jù)庫服務(wù)開啟
# netstat -anptu |grep :3306
tcp 0 0 :::3306 :::* LISTEN 2634/mysqld
#mysql -hlocalhost -uroot -p123456
mysql>grant all on bbsdb.* to webadmin@"localhost" identified by "123456";
mysql>create database bbsdb;
mysql>quit
#vim /usr/local/nginx/html/db.php
mysql_connect("localhost","webadmin","123456");
if($x){
echo "ok";
}else{
echo "err";
}
?>
測(cè)試
#http://192.168.4.254/db.php
ok
(諾數(shù)據(jù)庫沒開啟,測(cè)試得到的就是err)
——————————————————————————————————————————————————————
4.安裝memcached
安裝memcached服務(wù) (memcache,內(nèi)存存儲(chǔ)——要先裝事件觸發(fā)器的包libevent,libevent和memache要版本兼容,這里libevent-2.0.21,memcached-1.4.24)
先安裝libevent
#yum -y install gcc
#tar -xf libevent-2.0.21-stable.tar.gz (memcached服務(wù)庫文件)
#cd libevent-2.0.21-stable
#./configure
#make && make install
可以直接給庫文件做鏈接也可在庫配置文件中寫進(jìn)去,做下面其一就行。
1) #ln -s /usr/local/lib/libevent/* /usr/lib/
#ldconfig (//刷新)
2) #vim /etc/ld.so.conf (庫文件的配置文件)
/usr/local/lib/
#ldconfig (//刷新)
3) #vim /etc/ld.so.conf/libevent.conf
/usr/local/lib/
#ldconfig
#tar -zxf memcached-1.4.24.tar.gz
#cd memcached-1.4.24
#./configure
#make && make install
#ln -s /usr/local/bin/memached /bin
#memcached -h (查看幫助)
[root@proxe ~]# memcached -u root -m 64 -vv -d 啟動(dòng)memcached
用如下命令進(jìn)行啟動(dòng)
/usr/local/memcached/bin/memcached -d -m 1024 -u ths -l 198.28.1.237 -p 11211 -c1024 -P /tmp/memcached.pid
以上參數(shù)解釋如下:
-d選項(xiàng)是啟動(dòng)一個(gè)守護(hù)進(jìn)程,
-m是分配給Memcache使用的內(nèi)存數(shù)量,單位是MB,我這里是10MB,
-u是運(yùn)行Memcache的用戶,我這里是ths,
-l是監(jiān)聽的服務(wù)器IP地址,如果有多個(gè)地址的話,我這里指定了服務(wù)器的IP地址192.28.1.237,
-p是設(shè)置Memcache監(jiān)聽的端口。默認(rèn)是11211
-c選項(xiàng)是最大運(yùn)行的并發(fā)連接數(shù),默認(rèn)是1024,按照你服務(wù)器的負(fù)載量來設(shè)定,
-P是設(shè)置保存Memcache的pid文件,我這里是保存在/tmp/memcached.pid,
查看服務(wù)是否啟動(dòng):
[root@proxe ~]# netstat -anptu |grep :11211
tcp 0 0 0.0.0.0:11211 0.0.0.0:* LISTEN 6813/memcached
tcp 0 0 :::11211 :::* LISTEN 6813/memcached
udp 0 0 0.0.0.0:11211 0.0.0.0:* 6813/memcached
udp 0 0 :::11211 :::* 6813/memcached
【memcached 沒有關(guān)閉服務(wù)腳本,殺進(jìn)程 pkill -9 memcached 停止服務(wù)】
測(cè)試:
[root@host b]# yum -y install telnet
[root@host b]# telnet 192.168.4.5 11211
Trying 192.168.4.5...
Connected to 192.168.4.5.
Escape character is '^]'.
set name 0 100 3
tom
STORED
get name
VALUE name 0 3
tom
END
replace name 0 200 3
asc
STORED
get name
VALUE name 0 3
asc
END
add set replace delete get
#cd /usr/lcoal/bin
#./php -m (查看php所支持的功能)
#./php -m |grep memcached (查php是否支持memcached)
讓php支持memcached
#cd
# tar -zxvf memcahce-2.2.5
# cd memcahce-2.2.5
#/usr/local/php5/bin/phpize
#./configure --with-php-config=/usr/local/php5/bin/php-config --anable-memcache
#make && make install
#vim /usr/local/php5/etc/php.ini
extension_dir="/usr/local/php5nginx/lib/php/extensions/no-
debug-non-zts-20100525/"
extension=memcache.so
#/etc/init.d/php-fpm restart
修改nginx服務(wù)的主配置文件,接收到請(qǐng)求時(shí),先訪問11211端口。 (設(shè)置先從緩存中查找,沒有再從數(shù)據(jù)庫中查詢)
#vim /usr/local/nginx/conf/nginx.conf
編寫測(cè)試文件
#cat /usr/local/nginx/html/mem.php
$memcache->connect('localhost',11211) or die ('could not
connect!! ');
$memcache->set('name', 'jim'); //定義變量
$get_values=$memcache->get('name');//獲取變量值echo
$get_values;?>
#http://nginx-ip/mem.php
jim