yum 安裝依賴(很重要)
yum -y install php-mcrypt libmcrypt-devel libxml2 libxml2-devel curl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel libxslt libxslt-devel cyrus-sasl-plain cyrus-sasl cyrus-sasl-devel cyrus-sasl-lib m4 autoconf gcc gcc-c++ openssl openssl-devel pcre pcre-devel zlib zlib-devel wget net-tools zip unzip bzip2
下載必要安裝包
wget -O nginx-1.12.1.tar.gz https://nginx.org/download/nginx-1.12.1.tar.gz //nginx 安裝包
wget -O php-7.2.tar.gz http://cn2.php.net/get/php-7.2.3.tar.gz/from/this/mirror //php7.2安裝
1 安裝nginx
1.1 解壓編譯安裝nginx(安裝在/server/nginx目錄下)
tar zxvf nginx-1.12.1.tar.gz //解壓
cd nginx-1.12.1/ //進入解壓後的目錄,###下面的代碼複製每行行尾會有空格,請自行復制到文本編輯中去掉
./configure \
--prefix=/server/nginx \
--pid-path=/server/var/nginx/nginx.pid \
--lock-path=/server/var/nginx/nginx.lock \
--error-log-path=/server/var/nginx/error.log \
--http-log-path=/server/var/nginx/access.log \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-http_ssl_module
1.2安裝
make && make install
1.3 安裝完成後,開啓nginx 服務
/server/nginx/sbin/nginx
1.3.1 可以將nginx 命令加入環境變量中,方便使用(此三步可以忽略)
vi /etc/profile
1.3.2 在文件末尾加入
export PATH="$PATH:/server/nginx/sbin"
1.3.3 保存退出後,使之立即生效
source /etc/profile
1.4 訪問IP地址,如果沒出現nginx歡迎頁面,則開通防火牆80端口
查看防火牆狀態
firewall-cmd --state
打開80端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
命令含義:
--zone #作用域
--add-port=80/tcp #添加端口,格式爲:端口/通訊協議
--permanent #永久生效,沒有此參數重啓後失效
重啓防火牆
firewall-cmd --reload
防火牆常用命令介紹
firewall-cmd --state ##查看防火牆狀態,是否是running
firewall-cmd --reload ##重新載入配置,比如添加規則之後,需要執行此命令
firewall-cmd --get-zones ##列出支持的zone
firewall-cmd --get-services ##列出支持的服務,在列表中的服務是放行的
firewall-cmd --query-service ftp ##查看ftp服務是否支持,返回yes或者no
firewall-cmd --add-service=ftp ##臨時開放ftp服務
firewall-cmd --add-service=ftp --permanent ##永久開放ftp服務
firewall-cmd --remove-service=ftp --permanent ##永久移除ftp服務
firewall-cmd --add-port=80/tcp --permanent ##永久添加80端口
iptables -L -n ##查看規則,這個命令是和iptables的相同的
man firewall-cmd ##查看幫助
firewall-cmd --list-ports ##查看防火牆開啓的端口
至此nginx安裝完成
2 安裝PHP7
2.1 解壓編譯安裝php7(安裝目錄/server/php7)
tar zxvf php-7.2.tar.gz //解壓
cd php-7.2.3 //進入安裝目錄 ###下面的代碼複製每行行尾會有空格,請自行復制到文本編輯中去掉
./configure --prefix=/server/php7 \
--with-config-file-path=/server/php7/etc \
--with-curl \
--with-gd \
--with-gettext \
--with-iconv-dir \
--with-kerberos \
--with-libdir=lib64 \
--with-libxml-dir \
--with-openssl \
--with-pcre-regex \
--with-pdo-sqlite \
--with-pear \
--with-xmlrpc \
--with-xsl \
--with-zlib \
--enable-fpm \
--enable-bcmath \
--enable-libxml \
--enable-inline-optimization \
--enable-mbregex \
--enable-mbstring \
--enable-opcache \
--enable-pcntl \
--enable-shmop \
--enable-soap \
--enable-sockets \
--enable-sysvsem \
--enable-xml \
--enable-zip \
--enable-static \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--disable-debug \
--disable-fileinfo \
--enable-maintainer-zts
2.2 安裝
make && make install
時間較長(根據機器性能決定,1G1核 大概在15分鐘)
2.3 安裝完成後,將php加入環境變量,添加php配置文件
cp php.ini-production /server/php7/etc/php.ini //添加配置文件
vi /etc/profile //編輯環境變量文件
在文件中添加
export PATH="$PATH:/server/php7/bin"
使改動立即生效
source /etc/profile
查看php版本
php -v
2.4 配置php-fpm
cp /server/php7/etc/php-fpm.conf.default /server/php7/etc/php-fpm.conf
cp /server/php7/etc/php-fpm.d/www.conf.default /server/php7/etc/php-fpm.d/www.conf
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm //添加執行權限
啓動php-fpm
/etc/init.d/php-fpm start
至此php7安裝完成
3 yum安裝mariadb 10
3.1 添加倉庫
vi /etc/yum.repos.d/MariaDB.repo
文件中添加代碼
[mariadb]
name = MariaDB
baseurl = https://mirrors.ustc.edu.cn/mariadb/yum/10.2/centos7-amd64
gpgkey=https://mirrors.ustc.edu.cn/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck=1
注:以上的源,如果無效,則使用下方官網的源
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.2/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
3.2 編輯保存退出後,安裝
yum install -y MariaDB-server MariaDB-client
3.3 安裝成功後啓動
systemctl start mariadb //啓動程序
systemctl enable mariadb // 自啓動
systemctl status mariadb //查看狀態
3.4 配置mariadb
設置Root 用戶的登陸密碼
mysql_secure_installation
根據命令提示,主要是做以下幾件事情:
設置root密碼
是否禁止遠程 root訪問
是否禁止 test數據庫的訪問
是否禁用匿名用戶
是否重新加載privilleges-table信息
初始化完成後,登錄測試
mysql -uroot -p //代表你之前初始化設置的密碼 exit命令可以退出
配置字符集
vi /etc/my.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
vi /etc/my.cnf.d/mysql-clients.cnf
在[mysql]中添加
default-character-set=utf8
全部配置完成,重啓mariadb
systemctl restart mariadb
之後進入MariaDB查看字符集
mysql -uroot -p //代表密碼
mysql> show variables like "%character%";show variables like "%collation%"; //
至此mariadb 安裝完成。但是如果想要外面能訪問此數據庫,如想使用navicat來連接到這個數據庫,則還要其它的配置,您往下看
首先開放防火牆端口,開啓後要重啓防火牆:
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload
mysql>create user username@localhost identified by 'password';
直接創建用戶並授權的命令
mysql>grant all on . to username@localhost identified by 'password';
授予外網登陸權限 ,這裏授權用戶可以外網訪問此數據庫,如用數據庫連接工具navicat連接
mysql>grant all privileges on . to username@'%' identified by 'password';
授予權限並且可以授權
mysql>grant all privileges on . to username@'hostname' identified by 'password' with grant option;
簡單的用戶和權限配置基本就這樣了。
其中只授予部分權限把 其中 all privileges或者all改爲select,insert,update,delete,create,drop,index,alter,grant,references,reload,shutdown,process,file其中一部分。