CentOS7上安裝並配置Nginx、PHP、MySql


 一、Nginx

 1、安裝nginx

yum install nginx

2、啟動nginx

systemctl start nginx

除了systemctl start nginx之外,常用的相關命令還有systemctl stop nginxsystemctl restart nginxsystemctl status nginx

3、測試nginx是否安裝成功

    瀏覽器輸入ip地址或者域名(已經解析過的域名),如下圖所示,則安裝成功。

 

4,配置Nginx支持PHP解析

     編輯/etc/nginx/nginx.conf,藍色字體處為新加內容

 server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  _;
        root         /usr/share/nginx/html;
        index index.php index.html index.htm;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
        location ~ .php$ {
        try_files $uri =404;
        root /usr/share/nginx/html;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi.conf;
}

}

二、PHP

1,安裝PHP

yum install php php-mysql php-fpm

安裝過程中經常會見到如下問題:
2:postfix-2.10.1-6.el7.x86_64 有缺少的需求 libmysqlclient.so.18()(64bit)
2:postfix-2.10.1-6.el7.x86_64 有缺少的需求 libmysqlclient.so.18(libmysqlclient_18)(64bit)
解決方法:
把php-mysql換成php-mysqlnd
即執行

yum install php php-mysqlnd php-fpm

2、編輯PHP的配置文件,/etc/php.ini,注意去掉分號注釋

vim /etc/php.ini

   將 ;cgi.fix_pathinfo=1 改為 cgi.fix_pathinfo=0

3、編輯PHP-FPM配置文件

vim /etc/php-fpm.d/www.conf

 將
 user = nobody
 group = nobody   

 改為
 user = nginx
 group = nginx
 前提是已經創建了nginx用戶和nginx組。如果沒有創建方法:

1 groupadd -r nginx
2 useradd -r -g nginx nginx

4、啟動PHP—FPM

systemctl start php-fpm

5、設置開機啟動

systemctl enable php-fpm

6,確保Nginx配置文件修該之后,重啟Nginx

systemctl restart nginx

7、在/usr/share/nginx/html/目錄下創建phpinfo.php

    內容如下:

   <?php phpinfo();?>

   查看php進程:ps aux | grep php  查看端口占用:netstat -ano|grep 80

8、瀏覽器上輸入ip/phpinfo.php,如果出現如下界面,說明PHP和Nginx均安裝和配置成功。

    

 三、MySql

CentOS 7的yum源中貌似沒有正常安裝mysql時的mysql-sever文件,需要去官網上下載

1、補充yum源(1)

wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm

2、補充yum源(2)

rpm -ivh mysql-community-release-el7-5.noarch.rpm

3、安裝mysql

yum install mysql-community-server

4、成功安裝之后重啟mysql服務

systemctl start mysqld

初次安裝mysql是root賬戶是沒有密碼的
設置密碼的方法

1 mysql -uroot
2 mysql> set password for ‘root’@‘localhost’ = password('mypasswd');
3 mysql> exit

 

mysql -u root -p

輸入密碼之后,錯誤提示如下:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES),意思是root的密碼不正確。

解決辦法如下:
a.sudo mysqld_safe --user=root --skip-grant-tables --skip-networking &
輸入命令之后,如果提示信息為:
mysqld_safe A mysqld process already exists
 
表示mysqld_safe進程存在,可以通過
ps -A|grep mysql 查看mysqld_safe進程ID
kill -9 -xxxx            終結ID為xxxx的進程


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM