首先來介紹一下nginx.nginx是一個高性能的 http 和 反向代理 伺服器,也是一個 imap/pop3/smtp 代理伺服器。nginx不僅可以作為web伺服器,也可以作為負載均衡器,之前也有文章介紹,大家可以看一下.
mysql是一款開源免費的資料軟體,mysql是一個小型關系型資料庫管理系統,其體積小、速度快、總體擁有成本低,尤其是開放源碼這一特點,許多中小型網站為了降低網站總體擁有成本而選擇了mysql作為網站資料庫.
php,是英文超級文本預處理語言hypertext preprocessor的縮寫。php 是一種 html 内嵌式的語言,是一種在伺服器端執行的嵌入html文檔的腳本語言,語言的風格有類似于c語言,被廣泛的運用。
首先 上傳或下載下傳源碼壓縮檔案
首先安裝nginx
1安裝其依賴
編譯yum
yum -y install zlib-devel pcre-devel openssl-devel
進入/usr/src目錄
解壓檔案
tar –zxvf nginx-1.1.18.tar.gz
進入 目錄 進行預編譯
[root@localhost ~]# cd /usr/src/
[root@localhost src]# cd nginx-1.1.18
[root@localhost nginx-1.1.18]#[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/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --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/ --with-pcre
執行編譯
make
執行安裝
make install
察看
[root@localhost nginx-1.1.18]# echo $path
/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
建立目錄
[root@localhost nginx-1.1.18]# mkdir -pv /var/tmp/nginx
啟動察看
root@localhost nginx-1.1.18]# nginx
[root@localhost nginx-1.1.18]# netstat -tupln |grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* listen 11071/nginx: master
測試外網通路測試成功
2下面來安裝mysql
首先安裝依賴預設情況下已安裝
圖
[root@localhost src]# yum -y install ncurses-devel-5.5-24.20060715.i386.rpm
建立使用者
[root@localhost src]# useradd -m -s /sbin/nologin mysql
解壓 資料庫源碼包
[root@localhost src]# tar -zxvf mysql-5.0.87.tar.gz
進入目錄進行預測試
[root@localhost mysql-5.0.87]# ./configure --prefix=/usr/local/mysql --without-debug --with-extra-charsets=utf8,gbk --enable-assembler --with-mysql-ldflags=-all-static --with-client-ldflags=-all-static --with-unix-socket-path=/tmp/mysql.sock --with-ssl
編譯
安裝
安裝完成後複制檔案和啟動腳本
[root@localhost mysql-5.0.87]# cp support-files/my-medium.cnf /etc/my.cnf 複制配置檔案
[root@localhost mysql-5.0.87]# cp support-files/mysql.server /etc/init.d/mysqld複制啟動腳本
[root@localhost mysql-5.0.87]# chmod +x /etc/init.d/mysqld 給啟動腳本執行權限
做一個軟連接配接 為了以後友善我們為所有的二進制可執行檔案和動态連結庫檔案
[root@localhost ~]# ln -s /usr/local/mysql/lib/mysql/lib* /usr/lib 動态資料庫軟連接配接
[root@localhost ~]# ln -s /usr/local/mysql/bin/* /usr/local/bin/可執行的二進制檔案做軟連接配接
初始化資料庫
[root@localhost mysql-5.0.87]# mysql_install_db --user=mysql 以mysql的使用者來安裝資料庫
[root@localhost mysql-5.0.87]# chown -r root.mysql /usr/local/mysql/更改安裝目錄屬主為root,所屬組為mysql
[root@localhost mysql-5.0.87]# chown -r mysql.mysql /usr/local/mysql/var/更改資料庫目錄屬主和屬組都為mysql
啟動mysql
<code>service mysqld start</code>
現在我們檢視mysql是否啟動成功,mysql占用tcp的3306端口,我們檢視端口是否被占用:
<code>[root@localhost mysql-5.0.87]# netstat -antlp |grep 3306</code>
<code>tcp 0 0 0.0.0.0:3306 0.0.0.0:* listen 6129/mysqld </code>
<code>[root@localhost mysql-5.0.87]#</code>
<code>下面安裝php</code>
<code>首先安裝依賴包</code>
<code>上傳 </code>libmcrypt mhash mcrypt
下圖
tar -jxvf libmcrypt-2.5.8.tar.bz2
<code>./configure</code>
<code>make</code>
tar -jxvf mhash-0.9.9.9.tar.bz2
cd mhash-0.9.9.9
./configure
make inst all
做連接配接
[root@localhost src]# ln -s /usr/local/lib/libmcrypt* /usr/lib
[root@localhost src]# ln -s /usr/local/lib/libmhash.* /usr/lib/
tar -zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8
下面安裝php
1
tar -jxvf php-5.4.0.tar.bz2
2
cd php-5.4.0
3
./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql/ --with-zlib --enable-xml --disable-rpath --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --with-curl --with-curlwrappers --enable-fpm --enable-fastcgi --with-mcrypt --with-gd --with-openssl --with-mhash --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc -enable-zip --enable-soap
到這裡整個lnmp已經安裝完成.下面我們就配置php和nginx能運作php網站:
cp php.ini-production /usr/local/php/php.ini # 如果是開發就複制php.ini-development
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
ln -s /usr/local/php/bin/php /usr/bin/
配置php-fpm,編輯php-fpm.conf
vi /usr/local/php/etc/php-fpm.conf
找到listen那一行,修改成如下内容:
listen = /var/run/php-fpm/php-fpm.sock # 使用unix socket
啟動php-fpm
mkdir /var/run/php-fpm
/usr/local/php/sbin/php-fpm
然後配置nginx,編輯nginx配置檔案
vi /usr/local/nginx/conf/nginx.conf
修改nginx配置檔案支援php
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.php index.html index.htm; # 添加index.php的首頁檔案
}
# 添加下面内容
location ~ \.php$ {
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param script_filename $document_root/$fastcgi_script_name;
include fastcgi_params;
include fastcgi.conf;
修改完畢後儲存退出重新開機nginx
pkill -9 nignx
/usr/local/nginx/sbin/nginx
然後在/usr/local/nginx/html下建立index.php
vi /usr/local/nginx/html/index.php
添加下面内容
<?php
phpinfo();
?>
儲存退出後通路http://192.168.101.2/index.php,看到下面頁面表示已經安裝配置成功: