CentOS 7 安裝 lnmp

Tao發表於2019-01-17
  • 本地遠端連線伺服器
  1. 安裝 ssh 服務
yum install ssh
  1. 啟動 ssh
service sshd start  
chkconfig sshd on
  1. yum 換源
yum update
  1. 安裝nginx
yum localinstall http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

yum repolist enabled | grep "nginx*" 

yum -y install nginx
  • 啟動 nginx
service nginx start
  • 設定 nginx 開機自啟動
systemctl enable nginx.service
  • 檢查 nginx 自啟動設定是否成功
systemctl list-dependencies | grep nginx
  • 瀏覽器輸入你的 ip 檢測是否安裝成功,如出現歡迎頁面,則 nginx 安裝成功
  • nginx 配置如下

    server{
    listen  80;
    server_name youserver;
    index index.html index.php;
    root /home/public;  //你的專案路徑
    #charset koi8-r;
    #access_log logs/host.access.log main;
    location / {
    index index.html index.htm index.php;
    try_files $uri $uri/ /index.php?$query_string;
    }
    error_page 404    /404.html;
    # redirect server error pages to the static page /50x.html
    #
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
    root html;
    }
    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ .php$ {
    # proxy_pass http://127.0.0.1;
    #}
    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ .php$ {
    root   /home/public;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME /home/public$fastcgi_script_name;
    include  fastcgi_params;
    }
    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    location ~ /.ht {
    deny all;
    }
    }
    
  1. 安裝 mysql

    yum -y localinstall http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm
    
    yum repolist enabled | grep "mysql.*-community.*"
    
    yum -y install mysql-community-server install mysql-community-devel
    • 啟動 mysql
    service mysqld start
    • 檢查 mysql 是否啟動成功
    service mysqld status 或者 ps -ef | grep mysql
    • 設定 mysql 開機自啟動
    systemctl enable mysqld.service
    • 檢查 mysql 開機自啟動是否設定成功
    systemctl list-dependencies | grep mysqld
    • 更換 mysql root 使用者密碼
    mysql5.7 以後的爭強了安全機制,所以使用yum安裝,系統會自動生成一個隨機的密碼,並且不能設定簡單密碼。所以需要修改 mysql 全域性引數
    
    先用日誌密碼登入 mysql 
    
    grep 'temporary password' /var/log/mysqld.log
    
    會輸出結果: A temporary password is generated for root@localhost: ******
    
    使用此密碼登入後 執行 SHOW VARIABLES LIKE 'validate_password%‘;  檢視 mysql 密碼策略
    
    +--------------------------------------+--------+
    | Variable_name                        | Value  |
    +--------------------------------------+--------+
    | 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      |
    +--------------------------------------+--------+
    
    執行 set global validate_password_policy=LOW;  修改密碼策略
    
    執行 set global validate_password_length=6; 修改驗證密碼長度
    
    切換 user 庫
    
    update user set authentication_string = password('root'), password_expired = 'N', password_last_changed = now() where user = 'root';
    
    重啟 mysqld 服務,再用新密碼登入即可
    
    如果無法登入,提示Access denied for user 'root'@'localhost'
    
    重新更新 root 使用者的 plugin 欄位
    
    update user set plugin='mysql_native_password' where user = 'root';
    
    更新成功後.重新執行更新密碼操作
    
    重新整理許可權  flush privileges;
  • 安裝 php7

    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
    
    yum -y install php71w php71w-fpm
    
    yum -y install php71w-mbstring php71w-common php71w-gd php71w-mcrypt
    
    yum -y install php71w-mysql php71w-xml php71w-cli php71w-devel
    
    yum -y install php71w-pecl-memcached php71w-pecl-redis php71w-opcache
    • 驗證 PHP 是否安裝成功 php -v
    • 驗證 PHP 擴充是否安裝成功 php -m
    • 啟動 PHP-fpm
    service php-fpm star

相關文章