搭建centOS環(huán)境?? 采用yum 安裝
為什么選擇centos系統(tǒng)?CentOS是RedHat企業(yè)版的分支,也是企業(yè)操作系統(tǒng)的代表糕韧。服務器系統(tǒng)多采用CentOS
接下來我們一步一步搭建環(huán)境
一:yum 安裝nginx
1.??? 添加NginxRepo 到CentOS中?
sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
2.安裝nginx
sudo yum? -y? install nginx
3.添加nginx隨系統(tǒng)啟動
systemctl enable nginx.service
4.啟動nginx
systemctl? start?? nginx.service
查看nginx版本? nginx? -v???????????????? 我的版本 nginx version: nginx/1.12.2?
至此Web? Sever安裝完畢咧叭!
二:yum 安裝PHP7
centos php7安裝方法? 一:通過源碼編譯安裝???? 二:使用第三方Repo源進行安裝。
yum 源本身沒有php7所以得添加Repo源
1.添加源執(zhí)行以下兩步
rpm? -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
2.成功添加Repo源后持寄,執(zhí)行php7安裝 我安裝的是php7.2
sudo? yum? install? php72w? php72w-common? php72w-cli? php72w-fpm? php72w-mysql? php72w-opcache? php72w-mcrypt
通過yum簡單方式安裝php7代碼 與 周邊的必要模塊。 執(zhí)行下面的命令可以看到很長的列表娱俺,可以列出php7支持的所有模塊稍味。
sudo? yum? search? php72w-
3.php需要到gd模塊?
sudo? yum install? php72w-gd
查看php版本? php -v
? php啟動、停止荠卷、重啟systemctl?? start? php-fpm /? systemctl?? restart?? php-fpm? /? systemctl? stop php-fpm
4.通過nginx 與php-fpm讓他們工作起來 首先編輯nginx的虛擬主機配置文件 文件位置
/etc/nginx/conf.d/default.conf
在配置文件中 加入
location? ~ \.php$? {
?????? root????????? /usr/share/nginx/html;???? //web根目錄
??????? try_files $uri = 404;
??????? fastcgi_split_path_info ^(.+\.php)(/.+)$;
??????? fastcgi_pass 127.0.0.1:9000;?? //非常重要php-fpm運行時的端口
??????? fastcgi_index index.php;
??????? fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
??????? include fastcgi_params;
}
在/var/www? 目錄下創(chuàng)建index.php <?php? echo?? phpinfo();??? ?>
訪問IP? 看到php配置頁? 說明php與nginx 安裝成功
三模庐、安裝數(shù)據(jù)庫? 如果你想要安裝mariadb高版本的? 請?zhí)^直接看四
centOS 上yum源以不存在mysql? 而是mariaDB版本5.多的
1直接yum -y? install?? mariadb?? mariadb-server
安裝完成MariaDB,首先啟動MariaDB
2. systemctl start mariadb
設置開機啟動
3.systemctl enable mariadb
接下來進行MariaDB的相關簡單配置
4. mysql_secure_installation
首先是設置密碼僵朗,會提示先輸入密碼
5. Enter current password for root (enter for none):<–初次運行直接回車
四赖欣、安裝mariadb高版本?
mariadb版本查看 參考官網(wǎng)版本
https://downloads.mariadb.org/mariadb/repositories/#mirror=tuna&distro=CentOS
添加MariaDB的yum源
1.創(chuàng)建MariaDB.repo
sudo vim? /etc/yum.repos.d/Mariadb.repo
2.將以下文件中的字段添加到MariaDB.repo文件中
# MariaDB10.1CentOS repository list - created2016-12-0103:36 UTC
# http://downloads.mariadb.org/mariadb/repositories/[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.1/centos7-amd64gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDBgpgcheck=1
3.yum安裝MariaDB
sudo yum -y install MariaDB-server MariaDB-client
4.啟動MariaDB服務
systemctl start mysql.service
systemctl enable mysql.service
5.配置MariaDB服務
使用mysql_secure_installation配置MariaDB服務
mysql_secure_installation
具體設置
#由于一開始安裝MariaDB數(shù)據(jù)庫后, root用戶默認密碼為空, 所以只需要按Enter鍵
Enter current password for root (enter for none):
#是否設置root用戶的新密碼
Set root password? [Y/n] y
#錄入新密碼
New password:
#確認新密碼
Re-enter new password:
#是否刪除匿名用戶,生產(chǎn)環(huán)境建議刪除
Remove anonymous users? [Y/n] y
#是否禁止root遠程登錄,根據(jù)自己的需求選擇
Disallow root login remotely? [Y/n] n
#是否刪除test數(shù)據(jù)庫
Remove test database and access to it? [Y/n] y
#是否重新加載權限表
Reload privilege tables now? [Y/n] y
5.配置MariaDB的字符集
查看/etc/my.cnf文件內(nèi)容,其中包含一句!includedir /etc/my.cnf.d 說明在該配置文件中引入/etc/my.cnf.d 目錄下的配置文件验庙。
1)使用vi server.cnf命令編輯server.cnf文件顶吮,在[mysqld]標簽下添加
init_connect='SET collation_connection = utf8_unicode_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake
如果/etc/my.cnf.d 目錄下無server.cnf文件,則直接在/etc/my.cnf文件的[mysqld]標簽下添加以上內(nèi)容粪薛。
2)用vi ?client.cnf命令編輯/etc/my.cnf.d/client.cnf文件悴了,在[client]標簽下添加?
default-character-set=utf8
3)用vi ?mysql-clients.cnf命令編輯/etc/my.cnf.d/mysql-clients.cnf文件,在[mysql]標簽下添加?
default-character-set=utf8
配置完成后?systemctl restart mariadb 重啟服務违寿。
進入到數(shù)據(jù)庫查看字符設置湃交。
show variableslike"%character%";
show variables like"%collation%";
6開啟遠程訪問
1.防火墻添加3306端口
查看firewall狀態(tài)
firewall-cmd --state
狀態(tài)是not running,啟動firewall
systemctl start firewalld
狀態(tài)是running
開放3306端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent
重新載入
firewall-cmd --reload
2.明明之前有設置root開啟遠程的藤巢,但是我這里訪問不了搞莺,所以重新去MariaDB賦權限
#進入Mariadb
mysql -uroot -p
#選擇數(shù)據(jù)庫
use mysql;
#添加權限
Grant all on *.* to 'root'@'%' identified by 'root用戶的密碼' with grant option;
#重新載入
flush privileges;