一、安裝nginx
安裝nginx
yum install nginx
複製程式碼
啟動nginx服務
systemctl start nginx #啟動
systemctl restart nginx #重啟
systemctl stop nginx #停止
複製程式碼
二、安裝MySQL
rpm -Uvh http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
yum -y install mysql-community-server
複製程式碼
安裝完成,啟動MySQL
service mysqld start
Redirecting to /bin/systemctl start mysqld.service
複製程式碼
檢視MySQL的狀態
service mysqld status
複製程式碼
設定開機啟動
systemctl enable mysqld
systemctl daemon-reload
複製程式碼
MySQL安裝完成後會生成一個預設密碼,可通過以下方式檢視預設密碼
grep 'temporary password' /var/log/mysqld.log
複製程式碼
修改root密碼
ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPassWord!';
複製程式碼
如果報一下錯誤,說明設定的密碼不符合MySQL的密碼策略
1819 (HY000): Your password does not satisfy the current policy requirements
複製程式碼
MySQL的預設密碼策略要求密碼必須包含:大小寫字母、數字和特殊符號,並且長度不能少於8位。通過msyql環境變數可以檢視密碼策略的相關資訊
mysql> show variables like '%password%';
+---------------------------------------+--------+
| Variable_name | Value |
+---------------------------------------+--------+
| default_password_lifetime | 0 |
| disconnect_on_expired_password | ON |
| log_builtin_as_identified_by_password | OFF |
| mysql_native_password_proxy_users | OFF |
| old_passwords | 0 |
| report_password | |
| sha256_password_proxy_users | OFF |
| validate_password_check_user_name | OFF |
| validate_password_dictionary_file | |
| validate_password_length | 8 |
| validate_password_mixed_case_count | 1 |
| validate_password_number_count | 1 |
| validate_password_policy | MEDIUM |
| validate_password_special_char_count | 1 |
+---------------------------------------+--------+
14 rows in set (0.00 sec)
複製程式碼
如果想修改密碼策略,在/etc/my.cnf檔案新增validate_password_policy配置:
# 選擇0(LOW),1(MEDIUM),2(STRONG)其中一種,選擇2需要提供密碼字典檔案
validate_password_policy=0
複製程式碼
配置預設編碼為utf8,在/etc/my.cnf檔案新增如下配置
character_set_server=utf8
init_connect='SET NAMES utf8'
複製程式碼
重啟MySQL
systemctl restart mysqld
複製程式碼
MySQL預設只允許root使用者在本地登入,如果要在其他機器上連線MySQL,必須修改root許可權或者新增一個遠端使用者,為了安全起見,新增一個新使用者
mysql> GRANT ALL PRIVILEGES ON *.* TO 'jack'@'%' IDENTIFIED BY '@jack2018' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;
複製程式碼
這樣遠端就可以用賬戶名為jack,密碼為@jack2018來登入mysql了,執行 select host, user from mysql.user 檢視下:
mysql> select host,user from mysql.user;
+-----------+---------------+
| host | user |
+-----------+---------------+
| % | jack |
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
+-----------+---------------+
4 rows in set (0.00 sec)
複製程式碼
三、安裝PHP
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
複製程式碼
執行命令安裝PHP
yum install php70w.x86_64 php70w-cli.x86_64 php70w-common.x86_64 php70w-gd.x86_64 php70w-ldap.x86_64 php70w-mbstring.x86_64 php70w-mcrypt.x86_64 php70w-mysql.x86_64 php70w-pdo.x86_64
複製程式碼
安裝php-fpm
yum install php70w-fpm php70w-opcache
複製程式碼
啟動php-fpm
systemctl start php-fpm
複製程式碼
配置nginx配置檔案以支援PHP,找到nginx安裝目錄中nginx.conf檔案,增加如下配置
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
複製程式碼
下面到/usr/share/nginx/html檔案下面建立一個檔案
vi /usr/share/nginx/html/info.php
<?php
phpinfo();
?>
複製程式碼
開啟瀏覽器,訪問 http://公網IP,看到如下頁面說明配置成功了