CentOS7 下 yum 安裝 nginx + php + mysql 及管理

1、使用yum安裝Nginx

? ? ? yum install nginx

2、啟動Nginx服務

? ? ? systemctl start nginx

? ? ? 注:此時瀏覽器訪問IP即可訪問Nginx默認頁面

3、使用yum安裝php

? ? ? yum install php

4、使用yum安裝php相關擴展

? ? ? yum install?php-fpm?php-mysql?php-xml php-mbstring php-openssl php-gd?php-pecl-zip

5、使用yum安裝mysql

? ? ??rpm -Uvh http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm

? ? ? yum install mysql-community-server

? ? ? yum install mysql-community-client

6、配置Nginx

? ? ? 學習 vi 的基本操作

? ? ? 使用vi編輯/etc/nginx/conf.d/default.conf文件

? ? ? vi?/etc/nginx/conf.d/default.conf

? ? ? 在最上面添加如下代碼并保存:

<pre>

server

{

? ? listen 80;

? ? #listen 443 ssl;

? ? server_name 127.0.0.1 localhost;

? ? index index.php index.html index.htm default.php default.htm default.html;

? ? root /www/website/public; #設置網(wǎng)站根目錄,根據(jù)網(wǎng)站位置,自行修改

? ? #SSL-START SSL相關配置,請勿刪除或修改下一行帶注釋的404規(guī)則

? ? #error_page 404/404.html;

? ? #ssl_certificate? ? /etc/letsencrypt/live/core.admin.bchalo.com/fullchain.pem;

? ? #ssl_certificate_key? ? /etc/letsencrypt/live/core.admin.bchalo.com/privkey.pem;

? ? #if (\$server_port !~ 443){

? ? #? ? rewrite ^(/.*)\$ https://\$host$1 permanent;

? ? #}

? ? #error_page 497? https://\$host\$request_uri;

? ? #SSL-END

? ? #ERROR-PAGE-START? 錯誤頁配置,可以注釋、刪除或修改

? ? #error_page 404 /404.html;

? ? #error_page 502 /502.html;

? ? #ERROR-PAGE-END

? ? #跨域請求設置

? ? add_header 'Access-Control-Allow-Origin' '*';

? ? add_header 'Access-Control-Allow-Credentials' 'true';

? ? add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';

? ? add_header 'Access-Control-Allow-Headers' 'accept, content-type,UserToken,Flag';

? ? #Thinkphp的URL重寫規(guī)則

? ? if (!-e \$request_filename) {

? ? ? ? rewrite? ^(.*)\$? /index.php?s=/\$1? last;

? ? ? ? break;

? ? }

? ? #PHP-INFO-START? PHP引用配置,可以注釋或修改

? ? #include enable-php-71.conf;

? ? location ~ [^/]\.php(/|\$)

? ? {

? ? ? ? try_files \$uri =404;

? ? ? ? # fastcgi_pass? unix:/tmp/php-cgi-71.sock;

? ? ? ? fastcgi_pass 127.0.0.1:9000;

? ? ? ? fastcgi_index index.php;

? ? ? ? # FastCGI

? ? ? ? fastcgi_param? SCRIPT_FILENAME? ? \$document_root\$fastcgi_script_name;

? ? ? ? fastcgi_param? QUERY_STRING? ? ? \$query_string;

? ? ? ? fastcgi_param? REQUEST_METHOD? ? \$request_method;

? ? ? ? fastcgi_param? CONTENT_TYPE? ? ? \$content_type;

? ? ? ? fastcgi_param? CONTENT_LENGTH? ? \$content_length;

? ? ? ? fastcgi_param? SCRIPT_NAME? ? ? ? \$fastcgi_script_name;

? ? ? ? fastcgi_param? REQUEST_URI? ? ? ? \$request_uri;

? ? ? ? fastcgi_param? DOCUMENT_URI? ? ? \$document_uri;

? ? ? ? fastcgi_param? DOCUMENT_ROOT? ? ? \$document_root;

? ? ? ? fastcgi_param? SERVER_PROTOCOL? ? \$server_protocol;

? ? ? ? fastcgi_param? HTTPS? ? ? ? ? ? ? \$https if_not_empty;

? ? ? ? fastcgi_param? GATEWAY_INTERFACE? CGI/1.1;

? ? ? ? fastcgi_param? SERVER_SOFTWARE? ? nginx/\$nginx_version;

? ? ? ? fastcgi_param? REMOTE_ADDR? ? ? ? \$remote_addr;

? ? ? ? fastcgi_param? REMOTE_PORT? ? ? ? \$remote_port;

? ? ? ? fastcgi_param? SERVER_ADDR? ? ? ? \$server_addr;

? ? ? ? fastcgi_param? SERVER_PORT? ? ? ? \$server_port;

? ? ? ? fastcgi_param? SERVER_NAME? ? ? ? \$server_name;

? ? ? ? # PHP only, required if PHP was built with --enable-force-cgi-redirect

? ? ? ? fastcgi_param? REDIRECT_STATUS? ? 200;

? ? ? ? # PATHINFO

? ? ? ? set \$real_script_name \$fastcgi_script_name;

? ? ? ? if (\$fastcgi_script_name ~ "^(.+?\.php)(/.+)\$") {

? ? ? ? ? ? set \$real_script_name \$1;

? ? ? ? ? ? set \$path_info \$2;

? ? ? ? }

? ? ? ? fastcgi_param SCRIPT_FILENAME \$document_root\$real_script_name;

? ? ? ? fastcgi_param SCRIPT_NAME \$real_script_name;

? ? ? ? fastcgi_param PATH_INFO \$path_info;

? ? }

? ? #PHP-INFO-END

? ? location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)\$

? ? {

? ? ? ? expires? ? ? 30d;

? ? ? ? access_log off;

? ? }

? ? location ~ .*\.(js|css)?\$

? ? {

? ? ? ? expires? ? ? 12h;

? ? ? ? access_log off;

? ? }

? ? access_log? /www/nginx/log/$1.log;

}

</pre>

7、運行PHP

? ? ? systemctl restart nginx

? ? ? systemctl start php-fpm

? ? ? systemctl start mysqld

8、MySql初始設置

? ? ? 使用cat /var/log/mysqld.log查看Root初始化密碼

? ? ? 登入MySQL:

? ? ? ? ? mysql -uroot -p

? ? ??使用以下命令設置root密碼:

? ? ? ? ? SET GLOBAL validate_password_policy=0;

? ? ? ? ? SET GLOBAL validate_password_length=4;

? ? ? ? ? SET PASSWORD = PASSWORD('新密碼');

? ? ??為MySQL的root用戶添加遠程登錄授權:

? ? ? ? ? GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '密碼' WITH GRANT OPTION;

? ? ? 重啟MySQL:

? ? ? ? ? systemctl restart mysqld

9、根據(jù)以上內容,自行配置WordPress程序

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容