1. 程式人生 > >lnmp安裝

lnmp安裝

class one curl entos die iba 選項 def ng-

編輯lnmp安裝,為了以後使用方便,若要將nmp分開到不同server上,只需要將安裝目錄創建,安裝命令沒有變化

1 環境初始化

技術分享圖片
#系統環境
[root@anyux ~]# cat /etc/redhat-release 
CentOS Linux release 7.4.1708 (Core) 
[root@anyux ~]# uname -a
Linux anyux 3.10.0-693.el7.x86_64 #1 SMP Tue Aug 22 21:09:27 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

#關閉selinux firewall
[root@anyux 
~]# getenforce Disabled [root@anyux ~]# systemctl status firewalld.service ● firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled) Active: inactive (dead) Docs: man:firewalld(1)
View Code

1.1創建目錄

#源碼包存放位置
mkdir -p /server/tools #程序安裝位置 mkdir /application/

2安裝nginx

2.1 下載及準備安裝
http://www.nginx.org

#進入存放位置
cd /server/tools/
wget   http://nginx.org/download/nginx-1.10.3.tar.gz

# 解壓
tar xf nginx-1.10.3.tar.gz 

# 創建用戶
useradd www -u 1014 -s /sbin/nologin -M

# 解除依賴
yum install -y openssl-devel pcre-devel

2.2 nginx編譯安裝

cd nginx-1.10.3/

# 配置安裝選項
./configure --prefix=/application/nginx-1.10.3 --user=www --group=www --with-http_stub_status_module --with-http_ssl_module
# --prefix=/application/nginx-1.10.3 指定安裝位置
# --user=www --group=www 指定運行用戶
# --with-http_stub_status_module 開啟http_stub_status_module模塊
# --with-http_ssl_module 開啟http_stub_status_module模塊

# 編譯 安裝
make && make install

# 創建軟鏈接 方便使用及版本遷移
ln -s /application/nginx-1.10.3/ /application/nginx 

# 清除 /application/nginx/conf/nginx.conf 註釋信息
egrep -v "#|^$" /application/nginx/conf/nginx.conf.default >/application/nginx/conf/nginx.conf 
# 啟動測試
/application/nginx/sbin/nginx

# 檢查nginx服務狀態
# 也可以在瀏覽器輸入IP地址查看

curl -s  -I  -w %{http_code}"\n" -o /dev/null 10.0.0.127
200 
# 返回值 200 表示成功 查看http狀態碼了解更多詳情
# -o(小寫字母O):將文件保存為命令行中指定的文件名的文件中   此處定向到為空
# -s: 取消默認curl信息頭
# -w %{http_code}: 輸出http狀態碼的內容 
# 10.0.0.127: web服務器IP地址

# 檢查服務是不開啟
ps -ef | grep nginx 

# 檢查80端口
netstat -lntup | grep 80

3安裝php

# 解決依賴
 yum install -y zlib-devel openssl-devel pcre-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libivonv-devel freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel libxslt-devel bzip2-devel readline-devel recode recode-devel libtidy libtidy-devel libmcrypt-devel mhash mcrypt

# libiconv 安裝包需要自己下載 

cd /server/tools/
# 解壓
tar xf libiconv-1.14.tar.gz 
cd libiconv-1.14/
# 配置安裝選項 指定安裝位置
./configure --prefix=/usr/local/libiconv 
# 編譯 安裝
make && make install

# 如果上面的安裝出錯 使用下載 libiconv rpm包使用
鏈接:https://pan.baidu.com/s/1eR1LB8I 密碼:rnr2
cd /server/tools
# http://php.net/get/php-5.5.32.tar.gz/from/a/mirror 下載php源碼的位置
# 下載php5.5.32
wget http://110.96.193.6:82/1Q2W3E4R5T6Y7U8I9O0P1Z2X3C4V5B/php.net/distributions/php-5.5.32.tar.gz
# 解壓
tar xf php-5.5.32.tar.gz

cd cd php-5.5.32/
#

# 配置安裝選項 
./configure --prefix=/application/php-5.5.32 --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir=/usr/local/libiconv --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-soap --enable-short-tags --enable-static --with-xsl --with-fpm-user=www --with-fpm-group=www --enable-ftp --enable-opcache=no

# 編譯 安裝
make && make install

# 檢查 echo $?
# 返回0 表示成功

# 創建php軟件鏈接
ln -s /application/php-5.5.32/ /application/php

# 配置php-fpm.conf
mkdir /application/php/etc/ -p
cp /server/tools/php-5.5.32/sapi/fpm/php-fpm.conf /application/php/etc/

# 配置php.ini
mkdir /application/php/lib/ -p
\cp /server/tools/php-5.5.32/php.ini-production /application/php/lib/php.ini

4 配置 nginx 解析php腳本

vim /application/nginx/conf/nginx.conf
# 在server模塊中加入 index.php 
    location / {
        root   html;
        index  index.php index.html index.htm;
    }

# 在server模塊中添加
    location ~* .*\.(php|php5)?$ {
                root html;
                fastcgi_pass  127.0.0.1:9000;
                fastcgi_index index.php;
                include fastcgi.conf;
    }
# 檢查nginx配置狀態
/application/nginx/sbin/nginx -t

# 重啟nginx 
/application/nginx/sbin/nginx -s reload
# 啟動php-ftp程序
/application/php/sbin/php-fpm

# 輸入phpinfo

echo -e <?php \n phpinfo();\n ?> > /application/nginx/html/index.php

5 mysql安裝(二進制安裝)

# 下載mysql
# 地址一:mysql官網上查找
https://dev.mysql.com/downloads/mirrors/

# 地址二:搜狐鏡像
http://mirrors.sohu.com/mysql/

# 選擇一個可用的版本 mysql-5.6.34-linux-glibc2.5-x86_64.tar.gz

# 安裝CentOS7系統軟件需要解決libaio依賴
yum install -y libaio
# 解壓
tar xf /server/tools/mysql-5.6.34-linux-glibc2.5-x86_64.tar.gz 

# 創建目錄
mkdir -p /application/mysql5.6.34 

# 移動目錄文件
mv /server/tools/mysql-5.6.34-linux-glibc2.5-x86_64/* /application/mysql5.6.34/ 
# 創建軟鏈接
ln -s /application/mysql5.6.34/ /application/mysql      

# 創建用戶
useradd -s /sbin/nologin -M mysql  -u 1015    
# 修改權限                   
chown -R mysql.mysql /application/mysql    

# 初始化數據庫                 
/application/mysql/scripts/mysql_install_db --basedir=/application/mysql --datadir=/application/mysql/data/ --user=mysql

# 替換啟動腳本中的內容
sed -i s#/usr/local/mysql#/application/mysql#g /application/mysql/bin/mysqld_safe /application/mysql/support-files/mysql.server 

# 復制啟動腳本  
\cp /application/mysql/support-files/mysql.server /etc/init.d/mysqld            
# 復制配置文件                  
\cp /application/mysql/support-files/my-default.cnf /etc/my.cnf 

# 復制客戶端                                   
\cp /application/mysql/bin/mysql /etc/init.d/mysql  

# 創建軟鏈接
ln -s /application/mysql/bin/mysql /bin/mysql              

# 啟動服務
/etc/init.d/mysqld start 

# 鏈接測試
mysql                         

6 編寫php連接mysql測試頁面

#使用mysql函數連接
cat >/application/nginx/html/mysql.php <<EOF
<?php 
$link=mysql_connect("localhost","root","")or die(mysql_error());
var_dump($link);
?>      
EOF

#使用mysqli對象連接
cat >/application/nginx/html/mysqli.php <<EOF
<?php 
$link=new mysqli("localhost","root","")or die(mysql_error());
var_dump($link);
?>      
EOF

#$connection = new PDO("mysql:dbname=$db;host=$host", $username, $password);
cat >/application/nginx/html/mysql_pdo.php <<EOF
<?php 
$link = new PDO("mysq:dbname=mysql;host=localhost", root, ‘‘) or die(mysql_error());
var_dump($link);
?>
EOF

7 安裝 thinkphp-3.2.3

# 下載地址 
wget http://www.thinkphp.cn/download/610.html -O thinkphp3.2.3_full.zip

# 創建指定thinkphp目錄
mkdir -p /application/nginx/html/thinkphp

# 解壓到指定目錄
unzip  thinkphp3.2.3_full.zip -d /application/nginx/html/thinkphp

# 授權
chown -R www.www /application/nginx/html/

# thinkphp連接mysql.user數據庫

//數據庫配置信息
cat >/application/nginx/html/thinkphp/Application/Common/Conf/config.php <<EOF
<?php
return array(
        //‘配置項‘=>‘配置值‘
DB_TYPE   => mysql, // 數據庫類型
DB_HOST   => localhost, // 服務器地址
DB_NAME   => mysql, // 數據庫名
DB_USER   => root, // 用戶名
DB_PWD    => ‘‘, // 密碼
DB_PORT   => 3306, // 端口
DB_PREFIX => ‘‘, // 數據庫表前綴 
DB_CHARSET=> utf8, // 字符集
DB_DEBUG  =>  TRUE, // 數據庫調試模式 開啟後可以記錄SQL日誌 3.2.3新增
// 開啟路由
URL_ROUTER_ON   => true, 
);
?>
EOF

# 查看連接數據庫 此示例僅使用mysql方式連接數據庫,讀者可以使用其他方式連接
cat > /application/nginx/html/thinkphp/Application/Home/Controller/IndexController.class.php <<EOF
<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
    public function index(){
        $User = D(User);
        $list = $User->getField(Host,User,password,":");
        dump($list);
    }
}
EOF

lnmp安裝