一、配置nginx
? ? ? ?1、下載對(duì)應(yīng)當(dāng)前系統(tǒng)版本的nginx包(package)
? ? ? ? ? ? ? wget?http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
? ? ? ?2、建立nginx的yum倉(cāng)庫(kù)
? ? ? ? ? ? ?rpm-ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm
? ? ? ?3、使用yum安裝Nginx:
? ? ? ? ? ? ?sudo yum install nginx
? ? ? ?4、按照提示,輸入yes后開始安裝。安裝完畢后,Nginx的配置文件在/etc/nginx目錄下。使用以下命令啟動(dòng)Nginx:
? ? ? ? ? ? ?sudo systemctl start nginx
? ? ? ?5、檢查系統(tǒng)中firewalld防火墻服務(wù)是否開啟,如果已開啟,我們需要修改防火墻配置,開啟Nginx外網(wǎng)端口訪問。
? ? ? ? ? ? ?sudo systemctl status firewalld
? ? ? ?6、如果顯示active (running),則需要調(diào)整防火墻規(guī)則的配置。
? ? ? ? ? ? 修改/etc/firewalld/zones/public.xml文件,在zone一節(jié)中增加:
? ? ? ? ? ? <zone>
? ? ? ? ? ? ? ? ? ?...
? ? ? ? ? ? ? ? ? ?<service name="nginx" />
? ? ? ? ? ? </zone>
? ? ? ? 7、保存后重新加載firewalld服務(wù):
? ? ? ? ? ? ? sudo systemctl reload firewalld
? ? ? ? 8、您可以通過瀏覽器訪問http://<外網(wǎng)IP地址>來確定Nginx是否已經(jīng)啟動(dòng)。
? ? ? ? 9、最后將Nginx設(shè)置為開機(jī)啟動(dòng):
? ? ? ? ? ? ? sudo systemctl enable nginx.service
二、mariadb安裝
? ? ? ?1、安裝mariadb:
? ? ? ? ? ? ?sudo yum install mariadb-server
? ? ? ?2、啟動(dòng)MariaDB服務(wù)
? ? ? ? ? ? ?sudo systemctl start mariadb
? ? ? ?3、MariaDB默認(rèn)root密碼為空,我們需要設(shè)置一下,執(zhí)行腳本:
? ? ? ? ? ? ?sudo /usr/bin/mysql_secure_installation
? ? ? ? ? ? ①首先提示輸入當(dāng)前的root密碼:
? ? ? ? ? ? ? ? Enter current password for root (enter for none):初始root密碼為空,我們直接敲回車進(jìn)行下一步。
? ? ? ? ? ? ? ? ?Set root password? [Y/n]設(shè)置root密碼,默認(rèn)選項(xiàng)為Yes,我們直接回車,提示輸入密碼,在這里設(shè)置您的MariaDB的root賬戶密碼。
? ? ? ? ? ? ? ? ?Remove anonymous users? [Y/n]是否移除匿名用戶,默認(rèn)選項(xiàng)為Yes,建議按默認(rèn)設(shè)置,回車?yán)^續(xù)。
? ? ? ? ? ? ? ? ?Disallow root login remotely? [Y/n]是否禁止root用戶遠(yuǎn)程登錄?如果您只在本機(jī)內(nèi)訪問MariaDB,建議按默認(rèn)設(shè)置,回車?yán)^續(xù)。如果您還有其他云主機(jī)需要使用root賬號(hào)訪問該數(shù)據(jù)庫(kù),則需要選擇n。
? ? ? ? ? ? ? ? ?Remove test database and access to it? [Y/n]是否刪除測(cè)試用的數(shù)據(jù)庫(kù)和權(quán)限?建議按照默認(rèn)設(shè)置,回車?yán)^續(xù)。
? ? ? ? ? ? ? ? ?Reload privilege tables now? [Y/n]是否重新加載權(quán)限表?因?yàn)槲覀兩厦娓铝藃oot的密碼,這里需要重新加載,回車。完成后你會(huì)看到Success!的提示,MariaDB的安全設(shè)置已經(jīng)完成。
? ? ? ? ? ? ?②以權(quán)限用戶root登錄MariaDB:
? ? ? ? ? ? ? ? ?mysql -uroot -p
? ? ? ? ? ? ? ? ?按提示輸入root密碼,就會(huì)進(jìn)入MariaDB的交互界面,說明已經(jīng)安裝成功。
? ? ? ? ? ? ?③選擇mysql庫(kù)
? ? ? ? ? ? ? ? ?use mysql;
? ? ? ? ? ? ?④查看mysql庫(kù)中的user表的host值(即可進(jìn)行連接訪問的主機(jī)/IP名稱)
? ? ? ? ? ? ? ? ?select 'host' from user whereuser='root';
? ? ? ? ? ? ?⑤修改host值(以通配符%的內(nèi)容增加主機(jī)/IP地址),當(dāng)然也可以直接增加IP地址,如果這步出錯(cuò)"ERROR 1062(23000): Duplicate entry '%-root' for key 'PRIMARY'"由說明該記錄有了,跳過這步
? ? ? ? ? ? ? ? ?update user set host = '%' where user='root';
? ? ? ? ? ? ?⑥刷新MySQL的系統(tǒng)權(quán)限相關(guān)表
? ? ? ? ? ? ? ? ?flush privileges;
? ? ? ? ? ? ?⑦再重新查看user表時(shí),有修改,然后重起mariadb服務(wù)即可完成
? ? ? ?4、最后我們將MariaDB設(shè)置為開機(jī)啟動(dòng)。
? ? ? ? ? ? ?sudo systemctl enable mariadb
三、mysql安裝
1.先下載mysql5.7的repo源;相關(guān)命令:
wgethttp://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm
2.安裝mysql57-community-release-el7-8.noarch.rpm:(安裝這個(gè)包后,會(huì)獲得兩個(gè)mysql的yum repo源:/etc/yum.repos.d/mysql-community.repo,/etc/yum.repos.d/mysql-community-source.repo):
rpm-ivh mysql57-community-release-el7-8.noarch.rpm
3.安裝MySQL:
yuminstall mysql-server
一路Y下去即可;
4.安裝完畢后,重啟服務(wù)器命令:
servicemysqld restart
注:在/var/log/mysqld.log文件中會(huì)自動(dòng)生成一個(gè)隨機(jī)的密碼,我們需要先取得這個(gè)隨機(jī)密碼,以用于登錄MySQL服務(wù)端:
grep"password" /var/log/mysqld.log
會(huì)打印出如下內(nèi)容:
Atemporary password is generated for root@localhost: hilX0U!9i3_6
我們復(fù)制root@localhost:后面的隨機(jī)字符串,這個(gè)字符串就是MySQL在安裝完成后為我們隨機(jī)生成的密碼;
或
密碼就在這個(gè)日志的文件里
/var/log/mysqld.log
例如:標(biāo)注的就是密碼
2017-03-26T21:53:36.234194Z1 [Note] A temporary password is generated for root@localhost: >b&uAW1D>n7k
5.登錄到MySQL服務(wù)端并更新用戶root的密碼:
mysql-u root -philX0U!9i3_6
打印出MySQL的版本即表明已登錄;
由于修改密碼:
setpassword for 'fred'@'localhost'=password('passwd');
可能會(huì)報(bào)錯(cuò)
由以下兩個(gè)命令解決:
setglobal validate_password_policy=0;
setglobal validate_password_length=4;
開始設(shè)置自己的密碼:
setpassword for root@localhost=password('passwd');
刷新權(quán)限使之生效:
flushprivileges;
設(shè)置用戶root可以在任意IP下被訪問:
grant
all privileges on *.* to root@"%" identified by "新密碼";
設(shè)置用戶root可以在本地被訪問:
grant
all privileges on *.* to root@"localhost" identified by "新密碼";
刷新權(quán)限使之生效:
flushprivileges;
更新MySQL的用戶root的密碼:
set
password = password('新密碼');
注意:由于MySQL5.7采用了密碼強(qiáng)度驗(yàn)證插件validate_password,故此我們需要設(shè)置一個(gè)有一定強(qiáng)度的密碼;
輸入exit后用新密碼再次登錄看看吧!
5.將mysql設(shè)置為開機(jī)啟動(dòng):
sudosystemctl enable mysqld
安裝PHP7.0
1.刪除舊版本
如果已經(jīng)安裝過php就先刪除之前的版本。檢查方法如下:
yumlist installed | grep php
然后將安裝的包進(jìn)行刪除
比如yum remove php.x86_64 php-cli.x86_64 php-common.x86_64php-gd.x86_64 php-ldap.x86_64 php-mbstring.x86_64 php-mcrypt.x86_64php-mysql.x86_64 php-pdo.x86_64
具體根據(jù)顯示的安裝列表的名稱進(jìn)行相應(yīng)的刪除
2.rpm安裝Php7相應(yīng)的yum源:
rpm-Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm
?rpm -Uvhhttps://mirror.webtatic.com/yum/el7/webtatic-release.rpm
3.安裝php7.0
yuminstall php70w
4.安裝php擴(kuò)展
?php70w-mysql.x86_64mysql擴(kuò)展(作為依賴同時(shí)安裝php70w-pdo.x8664)
?php70w-gd.x86_64GD庫(kù),是php處理圖形的擴(kuò)展庫(kù),GD庫(kù)提供了一系列用來處理圖片的API,使用GD庫(kù)可以處理圖片,或者生成圖片。
?php70w-ldap.x86_64 "輕量級(jí)目錄訪問協(xié)議",是一個(gè)用于訪問"目錄服務(wù)器"(Directory Servers)的協(xié)議;
php70w-mbstring.x86_64
mbstring擴(kuò)展庫(kù)用于處理多字節(jié)字符串,PHP內(nèi)置的字符串長(zhǎng)度函數(shù)strlen無法正確處理中文字符串,它得到的只是字符串所占的字節(jié)數(shù)。對(duì)于GB2312的中文編碼,strlen得到的值是漢字個(gè)數(shù)的2倍,而對(duì)于UTF-8編碼的中文,就是1~3倍的差異了。采用mb_strlen函數(shù)可以較好地解決這個(gè)問題。
php70w-mcrypt.x86_64
Mcrypt擴(kuò)展庫(kù)可以實(shí)現(xiàn)加密解密功能,就是既能將明文加密,也可以密文還原。
5.安裝PHP FPM
?yum install php70w-fpm
關(guān)于php-fpm
?PHP-FPM其實(shí)是PHP源代碼的一個(gè)補(bǔ)丁,旨在將FastCGI進(jìn)程管理整合進(jìn)PHP包中。必須將它patch到你的PHP源代碼中,在編譯安裝PHP后才可以使用。
?現(xiàn)在我們可以在最新的PHP 5.3.2的源碼樹里下載得到直接整合了PHP-FPM的分支,據(jù)說下個(gè)版本會(huì)融合進(jìn)PHP的主分支去。相對(duì)Spawn-FCGI,PHP-FPM在CPU和內(nèi)存方面的控制都更勝一籌,而且前者很容易崩潰,必須用crontab進(jìn)行監(jiān)控,而PHP-FPM則沒有這種煩惱。
?PHP5.3.3已經(jīng)集成php-fpm了,不再是第三方的包了。PHP-FPM提供了更好的PHP進(jìn)程管理方式,可以有效控制內(nèi)存和進(jìn)程、可以平滑重載PHP配置,比spawn-fcgi具有更多優(yōu)點(diǎn),所以被PHP官方收錄了。在./configure的時(shí)候帶–enable-fpm參數(shù)即可開啟PHP-FPM。
使用PHP-FPM來控制PHP-CGI的FastCGI進(jìn)程
配置nginx
修改配置文件之前記得備份
1.nginx配置文件位置:(/etc/nginx/nginx.conf)
?# For more information on configuration,see:
#* Official English Documentation: http://nginx.org/en/docs/
#* Official Russian Documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes auto;
error_log
/var/log/nginx/error.log; #錯(cuò)誤日志記錄的位置
pid /run/nginx.pid; #nginx.pid為記錄nginx主進(jìn)程pid文件;切勿修改、移動(dòng)
# Load dynamic modules. See/usr/share/nginx/README.dynamic.
include/usr/share/nginx/modules/*.conf;
#引入/usr/share/nginx/modules/目錄下的所有以.conf結(jié)尾的文件
events {
worker_connections 1024;
}
http {
log_formatmain'$remote_addr - $remote_user [$time_local]"$request" '
'$status $body_bytes_sent"$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log/var/log/nginx/access.logmain;
sendfileon;
tcp_nopushon;
tcp_nodelayon;
keepalive_timeout65;
types_hash_max_size 2048;
include/etc/nginx/mime.types;
default_typeapplication/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
#這句很重要,引入所有etc/nginx/conf.d/目錄下的.conf文件
#***etc/nginx/conf.d/目錄存放的就是分站點(diǎn)的文件(下面會(huì)給出實(shí)例代碼)***
server {
#由于我們的nginx需要配置多站點(diǎn),所以在此就需要注釋一些東西
listen80 default_server;
listen[::]:80 default_server;
#保留監(jiān)聽的端口
# server_name_;
# root/usr/share/nginx/php;
# Load configuration files for thedefault server block.
# include /etc/nginx/default.d/*.conf;
# location / {
# }
# error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
# location ~ \.php$ {
# root/usr/share/php;
# fastcgi_pass127.0.0.1:9000;
# fastcgi_indexindex.php;
# fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;
# includefastcgi_params;
# }
}
# Settings for a TLS enabledserver.
#
#server {
#listen443 ssl http2 default_server;
#listen[::]:443 ssl http2 default_server;
#server_name_;
#root/usr/share/nginx/html;
#
#ssl_certificate"/etc/pki/nginx/server.crt";
#ssl_certificate_key"/etc/pki/nginx/private/server.key";
#ssl_session_cache shared:SSL:1m;
#ssl_session_timeout10m;
#ssl_ciphers HIGH:!aNULL:!MD5;
#ssl_prefer_server_ciphers on;
#
## Load configuration files for thedefault server block.
#include /etc/nginx/default.d/*.conf;
#
#location / {
#}
#
#error_page 404 /404.html;
#location = /40x.html {
#}
#
#error_page 500 502 503 504 /50x.html;
#location = /50x.html {
#}
#}
}
2.php-fpm配置文件位置:(/etc/php-fpm.d/www.conf)
?修改
user = nginx
??group= nginx
3.啟動(dòng)nginx服務(wù):
systemctl start nginx.service
?如需設(shè)置開機(jī)自啟使用以下命令:
sudo systemctl enable nginx.service
?查看啟動(dòng)狀態(tài):
systemctl status nginx
看到以下字眼說明啟動(dòng)成功!
?Active:
active (running) since六2016-11-19 13:40:04 CST; 50min ago
4.啟動(dòng)PHP-FPM:
systemctl start php-fpm.service
?
如需設(shè)置開機(jī)自啟試用以下命令:
sudo systemctl enable php-fpm.service
?查看啟動(dòng)狀態(tài):
systemctl status php-fpm.service
看到以下字眼說明啟動(dòng)成功!
?Active:
active (running) since六2016-11-19 14:14:33 CST; 18min ago