-
裝備的工具
Ubuntu16.04 , Xshell
-
使用Xshell鏈接到Ubuntu
使用xshell鏈接Ubuntu不是必須的,只是為了操作的方便,同時默認是你的Ubuntu已經(jīng)安裝好了
在Ubuntu中打開終端 ,執(zhí)行命令
sudo apt-get install openssh-server
因為Ubuntu16.04默認不安裝ssh-server服務,要使用Xshell連接上Ubuntu才需要安裝
-
對安裝的軟件源進行優(yōu)化
首先備份原有的軟件安裝源
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
打開源文件替換成阿里的源
vim /etc/apt/sources.list
清空sources.list文件中的所有內容
復制下面的內容全部粘貼到sources.list文件中
deb http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multivers
//更新源 sudo apt-get update
軟件源優(yōu)化完畢
-
安裝Nginx,MySQL,PHP
//安裝Nginx sudo apt-get isntall nginx //查看Nginx版本號 Nginx -v //nginx version: nginx/1.4.6 (Ubuntu) //測試Nginx curl -I 'http://127.0.0.1' //顯示結果如下,表示安裝成功 HTTP/1.1 200 OK Server: nginx/1.4.6 (Ubuntu) Date: Sat, 04 Mar 2017 06:52:38 GMT Content-Type: text/html Content-Length: 612 Last-Modified: Tue, 04 Mar 2014 11:46:45 GMT Connection: keep-alive ETag: "5315bd25-264" Accept-Ranges: bytes
//安裝mysql sudo apt-get install mysql-server //安裝過程中會要求輸入數(shù)據(jù)庫密碼 自行處理后 回車鍵 //mysql安裝結束后 測試一下 mysql -uroot -p //能進入數(shù)據(jù)庫就表示安裝成功
//安裝php7.0 sudo apt-get install php7.0 //查看php是否安裝成功 php -v //安裝php7.0-fpm sudo apt-get install php7.0-fpm //如果沒有這個安裝包執(zhí)行下面的命令 加入一個ppa源 sudo apt-add-repository ppa:ondrej/php
//修改配置文件讓Nginx與php-fpm集成起來 /* *通常Nginx與fastcgi通信有兩種,一種是UNIX socket(默認) 另一種是TCP *我這里使用UNIX socket方式 */ //首先 sudo vim /etc/php/7.0/fpm/pool.d/www.conf /* *在www.conf的大概36行的位置 *如果是下面的路徑就是正確的 */ listen = /run/php/php7.0-fpm.sock /* *保存并退出www.conf文件 檢查該配置文件是否正確 *提示 test is successful 表示配置文件是正確的 */ sudo php-fpm7.0 -t //其次 修改Nginx配置文件 sudo vim /etc/nginx/sites-enabled/default //修改 約在24行的配置 不修改就是默認的位置 修改之后是表示自己的項目以后的主要的根目錄 //修改 約在25行的配置 表示表示能解析的文件類型 e.g:index index.php index.html index.htm index.nginx-debian.html 24 root /var/www; 25 index index.php index.html index.htm; //修改 約在54行到64行之間的配置文件 修改后如下 54 location ~ \.php$ { 55 # fastcgi_split_path_info ^(.+\.php)(/.+)$; 56 # # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini 57 # 58 # # With php5-cgi alone: 59 # fastcgi_pass 127.0.0.1:9000; 60 # # With php5-fpm: 61 fastcgi_pass unix:/run/php/php7.0-fpm.sock; 62 # fastcgi_index index.php; 63 include fastcgi_params; 64 } /* * 一定要確保 www.conf中的監(jiān)聽的路徑和此處的fastcgi_pass unix的路徑是一致的 * 保存退出該配置文件 */ /* * 檢測Nginx的配置文件是否正確 */ sudo nginx -t /* * 如果出現(xiàn)如下提示,表示配置文件是正確的 * nginx: the configuration file /etc/nginx/nginx.conf syntax is ok * nginx: configuration file /etc/nginx/nginx.conf test is successful */ /* * 修改php.ini配置 */ vim /etc/php5/fpm/php.ini cgi.fix_pathinfo=0 /* * 重啟Nginx與php-fpm */ systemctl restart nginx systemctl restart php7.0-fpm
?
-
LNMP環(huán)境測試
//進入項目更根目錄
cd /var/www
//新建一個測試文件
vim index.php
//寫入如下內容
<?php
phpinfo();
?>
//打開Ubuntu的瀏覽器
//輸入localhost 就能看到結果了
2017-03-04.png
php連接MySQL
//查看軟件源中有那些php7.0能安裝的軟件包 apt-cache search php7.0 //先安裝php-mysql sudo apt-get install php7.0-mysql //在 /var/www 目錄先新建一個文件con.php vim con.php //在該文件中寫入 如下內容 <?php /* *$link = mysqli_connect('數(shù)據(jù)庫地址','數(shù)據(jù)庫登錄用戶','你的數(shù)據(jù)庫密碼','使用的庫'); *例如 */ $link = mysqli_connect('127.0.0.1','root','123456','sys'); if (! $link ) { die( 'Connect Error (' . mysqli_connect_errno () . ') ' . mysqli_connect_error ()); }else{ echo "success"; } ?> //在瀏覽器地址欄中輸入localhost/con.php //顯示success就表示連接成功
2017-03-04.png
安裝php擴展
//gd庫擴展
sudo apt-get install php7.0-gd
//加密擴展
sudo apt-get install php7.0-mcryp
//curl擴展
sudo apt-get install php7.0-curl
//安裝memcache擴展
sudo apt-get install php-memcached
.... 根據(jù)自己的需要去安裝擴展
2017-03-04.png
?