對於在Linux系統中安裝web服務其實都是差很少的,只是軟件的選擇不同,不過在php-5.2.17和之前的版本LNMP環境和之後安裝有一點區別,就是啓用--enable-fastcgi這個模塊。如今我用php-5.3.27來搭建LNMP環境,對於搭建不成功的網友們但願給我留言,你們一塊兒解決問題,一塊兒進步。php
1.安裝Linux系統 --這一步省略html
2.安裝nginx服務
[root@RedHat1 samba]# tar xvf nginx-1.3.13.tar.gz
[root@redhat1 samba]# cd nginx-1.3.13
[root@redhat1 nginx-1.3.13]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_sub_module --with-http_gunzip_module --without-http_rewrite_module --without-http_proxy_module --without-http_upstream_ip_hash_module
[root@redhat1 nginx-1.3.13]# make && make install
[root@redhat1 nginx-1.3.13]# echo $?
0 mysql
[root@redhat1 nginx-1.3.13]# useradd -s /sbin/nologin -M nginxlinux
[root@redhat1 nginx-1.3.13]# cd /usr/local/nginx/sbin/
[root@redhat1 sbin]# ./nginx
[root@redhat1 sbin]# netstat -an |grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN
[root@redhat1 sbin]#nginx
3.測試nginx服務是否正常啓動web
2.安裝mysql數據庫軟件
[root@redhat1 samba]# tar xvf mysql-5.1.51.tar.gz
[root@redhat1 samba]# cd mysql-5.1.51
[root@redhat1 mysql-5.1.51]# ./configure --prefix=/usr/local/mysql-5.1
[root@redhat1 mysql-5.1.51]# make && make install
[root@redhat1 mysql-5.1.51]# cd /usr/local/mysql-5.1/bin --進入安裝mysql目錄
[root@redhat1 bin]# ./mysqld_safe & --啓動數據庫
[root@redhat1 bin]# netstat -an | grep 3306 --檢查mysql是否啓動
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
[root@redhat1 bin]# mysql -u root -p --登錄數據庫,密碼爲空
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 108
Server version: 5.1.51-log Source distribution
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>redis
3.安裝php軟件
[root@redhat1 samba]# tar xvf php-5.3.27.tar.gz
[root@redhat1 samba]# cd php-5.3.27
[root@redhat1 php-5.3.27]# ./configure --prefix=/usr/local/php-5.3.27 --enable-fpm --with-gd --with-mysql=/usr/local/mysql5.1/ --with-mysqli=/usr/local/mysql5.1/bin/mysql_config --with-png-dir --with-jpeg-dir --with-zlib --with-ldap --with-curl --with-snmp --with-freetype-dir
[root@redhat1 php-5.3.27]# make && make install
[root@redhat1 php-5.3.27]# cd /usr/local/php-5.3.27/etc/
[root@redhat1 etc]# cp -a php-fpm.conf.default php-fpm.conf
[root@redhat1 etc]# cp /home/samba/php-5.3.27/php.ini-development php.inisql
4.nginx和php相接合
[root@redhat1 etc]# cd /usr/local/nginx/conf/
[root@redhat1 conf]# vim nginx.conf --去掉如下注釋
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
[root@redhat1 conf]# vim ../html/index.php --建立php首頁文件
<?php
phpinfo();
?>數據庫
5.啓動服務,並測試
[root@redhat1 conf]# /usr/local/php-5.3.27/sbin/php-fpm
[root@redhat1 conf]# /usr/local/nginx/sbin/nginx
[root@redhat1 conf]# netstat -an |more
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTENvim