安裝Nginx
要使用官方Nginx源,無需手動編譯避免繁瑣操作。
手動配置yum源
[root@nginx~]vim /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
執(zhí)行yum安裝
[root@nginx ~]# yum install nginx -y
啟動nginx并加入開機(jī)自啟
[root@nginx ~]# systemctl start nginx
[root@nginx ~]# systemctl enable nginx
安裝php(7.1版)
移除舊版php
[root@nginx ~]# yum remove php-mysql-5.4 php php-fpm php-common -y
配置擴(kuò)展源
[root@nginx nginx]# yum localinstall -y http://mirror.webtatic.com/yum/el7/webtatic-release.rpm
安裝php7.1版
[root@nginx ~]# yum -y install php71w php71w-cli php71w-common php71w-devel
php71w-embedded php71w-gd php71w-mcrypt php71w-mbstring php71w-pdo php71w-xml php71w-fpm
php71w-mysqlnd php71w-opcache php71w-pecl-memcached php71w-pecl-redis php71w-pecl-mongodb
統(tǒng)一系統(tǒng)權(quán)限煤蹭,修改php-fpm運(yùn)行的用戶和組身份
[root@web02 ~]# sed -i '/^user/c user = www' /etc/php-fpm.d/www.conf
[root@web02 ~]# sed -i '/^group/c group = www' /etc/php-fpm.d/www.conf
創(chuàng)建用戶(www)
useradd www
啟動php-fpm管理進(jìn)程俘陷,并加入開機(jī)自啟
root@nginx ~]# systemctl start php-fpm
[root@nginx ~]# systemctl enable php-fpm
配置Nginx連接php,并進(jìn)行測試
[root@nginx conf.d]# cat /etc/nginx/conf.d/blog.zhangweibin.conf
server {
listen 80;
server_name www.zhangweibin.com;
locationn / {
root /code/test;
index index.php index.html;
}
location ~ \.php$ {
root /code/test;
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
創(chuàng)建對應(yīng)站點目錄
[root@Nginx conf.d]# mkdir /code/test
[root@Nginx conf.d]# vim /code/test/index.php
####該文件內(nèi)容為測試php成功連接
<?
phpinfo();
?>
檢查Nginx配置
[root@nginx ~]# nginx -t
重載Nginx
[root@nginx ~]# systemctl reload nginx
hosts解析
10.0.0.60 test.zhangweibin.com
測試
瀏覽器訪問:http://test.zhangweibin.com
安裝Mysql(5.7版)
配置Mysql擴(kuò)展源
[root@nginx ~]# rpm -ivh http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql57-community-release-el7-10.noarch.rpm
yum安裝
[root@nginx ~]# yum install mysql-community-server -y
啟動Mysql钥平,并加入開機(jī)自啟
[root@nginx ~]# systemctl start mysqld
[root@nginx ~]# systemctl enable mysqld
使用Mysq初始密碼登錄數(shù)據(jù)庫
[root@nginx ~]# mysql -uroot -p$(awk '/temporary password/{print $NF}' /var/log/mysqld.log)
修改數(shù)據(jù)庫密碼
修改默認(rèn)密碼規(guī)則
數(shù)據(jù)庫默認(rèn)密碼規(guī)則必須攜帶大小寫字母、特殊符號姊途,字符長度大于8否則會報錯涉瘾。
mysql> set password for root@localhost = password('123456');
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
因此設(shè)定較為簡單的密碼時需要首先修改set global validate_password_policy和_length參數(shù)值
mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password_length=1;
Query OK, 0 rows affected (0.00 sec)
修改密碼
mysql> set password for root@localhost = password('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)
測試php能否連接Mysql
[root@nginx ~]# vim /code/test/mysqli.php
<?php
$servername = "localhost";
$username = "root";
$password = "6256133";
> // 創(chuàng)建連接
$conn = mysqli_connect($servername, $username, $password);
> // 檢測連接
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
echo "連接成功";
?>
部署workpress
下載workpress數(shù)據(jù)包
[root@nginx ~]# wget https://cn.wordpress.org/wordpress-4.9.4-zh_CN.tar.gz
解壓到站點目錄
[root@nginx ~]# tar xf wordpress-4.9.4-zh_CN.tar.gz -C /code/test
修改權(quán)限
[root@nginx ~]# chown -R www.www /code/test/
創(chuàng)建workpress數(shù)據(jù)庫
[root@http-server ~]# mysql -uroot -p123456
mysql> create database wordpress;
mysql> exit