1. 程式人生 > >centos7.2 搭建lnmp環境(轉)

centos7.2 搭建lnmp環境(轉)

現在 working arc emctl 加密解密 容易 restart lis 三方

一.nginx安裝

1.下載對應當前系統版本的nginx包(package)

? wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

2.建立nginx的yum倉庫(默認yum是沒有nginx的)

? rpm -ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm

3.下載並安裝nginx

? yum install nginx

4.nginx啟動(nginx安裝目錄下-/usr/sbin/)

? systemctl start nginx.service

ps:一些其它nginx相關命令:

nginx相關配置文件:

? 默認的配置文件在 /etc/nginx/conf.d 路徑下,使用該配置已經可以正確地運行nginx;

? 如需要自定義,修改其下的 default.conf 等文件即可;

在瀏覽器地址欄中輸入部署nginx環境的機器的IP,如果一切正常,應該能看到如下字樣的內容。

Welcome to nginx!

If you see this page, the nginx web server is successfully installed andworking. Further configuration is required.

For online documentation and support please refer tonginx.org.Commercial support is available atnginx.com.

Thank you for using nginx.

第二步:MYSQL安裝

1.先下載mysql的repo源;相關命令:

? wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

2.安裝mysql-community-release-el7-5.noarch.rpm包

(安裝這個包後,會獲得兩個mysql的yum repo源:/etc/yum.repos.d/mysql-community.repo,/etc/yum.repos.d/mysql-community-source.repo)

? rpm -ivh mysql-community-release-el7-5.noarch.rpm

3.安裝MYSQL

? sudo yum install mysql-server

4.重置密碼

? 更改用戶權限:

sudo chown -R root:root /var/lib/mysql

? 重啟服務:

systemctl restart mysql.service

? 登錄,並修改密碼:

?
1 2 3 4 5 6 7 mysql -u root ? mysql > use mysql; ? mysql > update user set password=password(‘123456‘) where user=‘root‘; ? mysql > exit;

第三步:安裝php

1.查看當前安裝的php版本( yum list installed | grep php)

? 如果存在php安裝包先刪除之前版本 用yum remove 移除 php相關的包

2.rpm 安裝 Php7 相應的 yum源

?
1 2 3 ? rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm ? rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

3.安裝php7.1

yum install php71w

4.安裝php擴展

? php71w-mysql.x8664 mysql擴展(作為依賴同時安裝 php71w-pdo.x8664)

? php71w-gd.x86_64 GD庫,是php處理圖形的擴展庫,GD庫提供了一系列用來處理圖片的API,使用GD庫可以處理圖片,或者生成圖片。

? php71w-ldap.x86_64 "輕量級目錄訪問協議",是一個用於訪問"目錄服務器"(Directory Servers)的協議;

php71w-mbstring.x86_64 mbstring擴展庫用於處理多字節字符串,PHP內置的字符串長度函數strlen無法正確處理中文字符串,它得到的只是字符串所占的字節數。對於GB2312的中文編碼,strlen得到的值是漢字個數的2倍,而對於UTF-8編碼的中文,就是1~3倍的差異了。采用mb_strlen函數可以較好地解決這個問題。

php71w-mcrypt.x86_64 Mcrypt擴展庫可以實現加密解密功能,就是既能將明文加密,也可以密文還原。

5.安裝PHP FPM

? yum install php71w-fpm

關於 php-fpm

? PHP-FPM其實是PHP源代碼的一個補丁,旨在將FastCGI進程管理整合進PHP包中。必須將它patch到你的PHP源代碼中,在編譯安裝PHP後才可以使用。

? 現在我們可以在最新的PHP 5.3.2的源碼樹裏下載得到直接整合了PHP-FPM的分支,據說下個版本會融合進PHP的主分支去。相對Spawn-FCGI,PHP-FPM在CPU和內存方面的控制都更勝一籌,而且前者很容易崩潰,必須用crontab進行監控,而PHP-FPM則沒有這種煩惱。

? PHP5.3.3已經集成php-fpm了,不再是第三方的包了。PHP-FPM提供了更好的PHP進程管理方式,可以有效控制內存和進程、可以平滑重載PHP配置,比spawn-fcgi具有更多優點,所以被PHP官方收錄了。在./configure的時候帶 –enable-fpm參數即可開啟PHP-FPM。

使用PHP-FPM來控制PHP-CGI的FastCGI進程

第四步:配置nginx

修改配置文件之前記得備份

1.nginx配置文件位置:(/etc/nginx/conf.d/default.conf)

? 修改web root目錄(如果沒有需求也可以不用修改,使用默認即可):

root /wwwdata/html;

? 配置php解析,修改 下面代碼中黑色加粗部分:

?
1 2 3 4 5 6 7 8 9 10 11 ? location ~.php$ { ? fastcgi_pass 127.0.0.1:9000; ? fastcgi_index index.php; ?fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; ? include fastcgi_params; ? }

2.php-fpm配置文件位置:(/etc/php-fpm.d/www.conf)

? 修改

user =nginx

? group=nginx

3.啟動nginx服務:

systemctl start nginx.service

? 如需設置開機自啟使用以下命令:

sudo systemctl enable nginx.service

? 查看啟動狀態:

systemctl status nginx

看到以下字眼說明啟動成功!

?Active: active (running) since 六 2016-11-19 13:40:04 CST; 50min ago

4.啟動PHP-FPM:

systemctl start php-fpm.service
?

如需設置開機自啟試用以下命令:

sudo systemctl enable php-fpm.service

? 查看啟動狀態:

systemctl status php-fpm.service

看到以下字眼說明啟動成功!

?Active: active (running) since 六 2016-11-19 14:14:33 CST; 18min ago

至此,php+mysql+nginx 環境搭建完成!

附 mysql遠程連接 命令

 grant usage on *.* to [email protected] identified by ‘fred‘;//創建用戶fred密碼ferd
    select host,user,password from mysql.user where user=‘fred‘;//查看記錄  
    grant all privileges on *.* to [email protected]%‘identified by ‘fred‘;//設置可以遠程訪問

centos7.2 搭建lnmp環境(轉)