一、配置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倉庫
? ? ? ? ? ? ?rpm-ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm
? ? ? ?3、使用yum安裝Nginx:
? ? ? ? ? ? ?sudo yum install nginx
? ? ? ?4、按照提示,輸入yes后開始安裝。安裝完畢后,Nginx的配置文件在/etc/nginx目錄下。使用以下命令啟動Nginx:
? ? ? ? ? ? ?sudo systemctl start nginx
? ? ? ?5、檢查系統中firewalld防火墻服務是否開啟,如果已開啟,我們需要修改防火墻配置,開啟Nginx外網端口訪問。
? ? ? ? ? ? ?sudo systemctl status firewalld
? ? ? ?6、如果顯示active (running),則需要調整防火墻規則的配置。
? ? ? ? ? ? 修改/etc/firewalld/zones/public.xml文件,在zone一節中增加:
? ? ? ? ? ? <zone>
? ? ? ? ? ? ? ? ? ?...
? ? ? ? ? ? ? ? ? ?<service name="nginx" />
? ? ? ? ? ? </zone>
? ? ? ? 7、保存后重新加載firewalld服務:
? ? ? ? ? ? ? sudo systemctl reload firewalld
? ? ? ? 8、您可以通過瀏覽器訪問http://<外網IP地址>來確定Nginx是否已經啟動。
? ? ? ? 9、最后將Nginx設置為開機啟動:
? ? ? ? ? ? ? sudo systemctl enable nginx.service
二、mariadb安裝
? ? ? ?1、安裝mariadb:
? ? ? ? ? ? ?sudo yum install mariadb-server
? ? ? ?2、啟動MariaDB服務
? ? ? ? ? ? ?sudo systemctl start mariadb
? ? ? ?3、MariaDB默認root密碼為空,我們需要設置一下,執行腳本:
? ? ? ? ? ? ?sudo /usr/bin/mysql_secure_installation
? ? ? ? ? ? ①首先提示輸入當前的root密碼:
? ? ? ? ? ? ? ? Enter current password for root (enter for none):初始root密碼為空,我們直接敲回車進行下一步。
? ? ? ? ? ? ? ? ?Set root password? [Y/n]設置root密碼,默認選項為Yes,我們直接回車,提示輸入密碼,在這里設置您的MariaDB的root賬戶密碼。
? ? ? ? ? ? ? ? ?Remove anonymous users? [Y/n]是否移除匿名用戶,默認選項為Yes,建議按默認設置,回車繼續。
? ? ? ? ? ? ? ? ?Disallow root login remotely? [Y/n]是否禁止root用戶遠程登錄?如果您只在本機內訪問MariaDB,建議按默認設置,回車繼續。如果您還有其他云主機需要使用root賬號訪問該數據庫,則需要選擇n。
? ? ? ? ? ? ? ? ?Remove test database and access to it? [Y/n]是否刪除測試用的數據庫和權限?建議按照默認設置,回車繼續。
? ? ? ? ? ? ? ? ?Reload privilege tables now? [Y/n]是否重新加載權限表?因為我們上面更新了root的密碼,這里需要重新加載,回車。完成后你會看到Success!的提示,MariaDB的安全設置已經完成。
? ? ? ? ? ? ?②以權限用戶root登錄MariaDB:
? ? ? ? ? ? ? ? ?mysql -uroot -p
? ? ? ? ? ? ? ? ?按提示輸入root密碼,就會進入MariaDB的交互界面,說明已經安裝成功。
? ? ? ? ? ? ?③選擇mysql庫
? ? ? ? ? ? ? ? ?use mysql;
? ? ? ? ? ? ?④查看mysql庫中的user表的host值(即可進行連接訪問的主機/IP名稱)
? ? ? ? ? ? ? ? ?select 'host' from user whereuser='root';
? ? ? ? ? ? ?⑤修改host值(以通配符%的內容增加主機/IP地址),當然也可以直接增加IP地址,如果這步出錯"ERROR 1062(23000): Duplicate entry '%-root' for key 'PRIMARY'"由說明該記錄有了,跳過這步
? ? ? ? ? ? ? ? ?update user set host = '%' where user='root';
? ? ? ? ? ? ?⑥刷新MySQL的系統權限相關表
? ? ? ? ? ? ? ? ?flush privileges;
? ? ? ? ? ? ?⑦再重新查看user表時,有修改,然后重起mariadb服務即可完成
? ? ? ?4、最后我們將MariaDB設置為開機啟動。
? ? ? ? ? ? ?sudo systemctl enable mariadb
三、mysql安裝
1.先下載mysql5.7的repo源;相關命令:
wgethttp://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm
2.安裝mysql57-community-release-el7-8.noarch.rpm:(安裝這個包后,會獲得兩個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.安裝完畢后,重啟服務器命令:
servicemysqld restart
注:在/var/log/mysqld.log文件中會自動生成一個隨機的密碼,我們需要先取得這個隨機密碼,以用于登錄MySQL服務端:
grep"password" /var/log/mysqld.log
會打印出如下內容:
Atemporary password is generated for root@localhost: hilX0U!9i3_6
我們復制root@localhost:后面的隨機字符串,這個字符串就是MySQL在安裝完成后為我們隨機生成的密碼;
或
密碼就在這個日志的文件里
/var/log/mysqld.log
例如:標注的就是密碼
2017-03-26T21:53:36.234194Z1 [Note] A temporary password is generated for root@localhost: >b&uAW1D>n7k
5.登錄到MySQL服務端并更新用戶root的密碼:
mysql-u root -philX0U!9i3_6
打印出MySQL的版本即表明已登錄;
由于修改密碼:
setpassword for 'fred'@'localhost'=password('passwd');
可能會報錯
由以下兩個命令解決:
setglobal validate_password_policy=0;
setglobal validate_password_length=4;
開始設置自己的密碼:
setpassword for root@localhost=password('passwd');
刷新權限使之生效:
flushprivileges;
設置用戶root可以在任意IP下被訪問:
grant
all privileges on *.* to root@"%" identified by "新密碼";
設置用戶root可以在本地被訪問:
grant
all privileges on *.* to root@"localhost" identified by "新密碼";
刷新權限使之生效:
flushprivileges;
更新MySQL的用戶root的密碼:
set
password = password('新密碼');
注意:由于MySQL5.7采用了密碼強度驗證插件validate_password,故此我們需要設置一個有一定強度的密碼;
輸入exit后用新密碼再次登錄看看吧!
5.將mysql設置為開機啟動:
sudosystemctl enable mysqld
安裝PHP7.0
1.刪除舊版本
如果已經安裝過php就先刪除之前的版本。檢查方法如下:
yumlist installed | grep php
然后將安裝的包進行刪除
比如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
具體根據顯示的安裝列表的名稱進行相應的刪除
2.rpm安裝Php7相應的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擴展
?php70w-mysql.x86_64mysql擴展(作為依賴同時安裝php70w-pdo.x8664)
?php70w-gd.x86_64GD庫,是php處理圖形的擴展庫,GD庫提供了一系列用來處理圖片的API,使用GD庫可以處理圖片,或者生成圖片。
?php70w-ldap.x86_64 "輕量級目錄訪問協議",是一個用于訪問"目錄服務器"(Directory Servers)的協議;
php70w-mbstring.x86_64
mbstring擴展庫用于處理多字節字符串,PHP內置的字符串長度函數strlen無法正確處理中文字符串,它得到的只是字符串所占的字節數。對于GB2312的中文編碼,strlen得到的值是漢字個數的2倍,而對于UTF-8編碼的中文,就是1~3倍的差異了。采用mb_strlen函數可以較好地解決這個問題。
php70w-mcrypt.x86_64
Mcrypt擴展庫可以實現加密解密功能,就是既能將明文加密,也可以密文還原。
5.安裝PHP FPM
?yum install php70w-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/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; #錯誤日志記錄的位置
pid /run/nginx.pid; #nginx.pid為記錄nginx主進程pid文件;切勿修改、移動
# Load dynamic modules. See/usr/share/nginx/README.dynamic.
include/usr/share/nginx/modules/*.conf;
#引入/usr/share/nginx/modules/目錄下的所有以.conf結尾的文件
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/目錄存放的就是分站點的文件(下面會給出實例代碼)***
server {
#由于我們的nginx需要配置多站點,所以在此就需要注釋一些東西
listen80 default_server;
listen[::]:80 default_server;
#保留監聽的端口
# 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.啟動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