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

 1、Nginx

 一、安裝nginxphp

yum install nginx

二、啓動nginxhtml

systemctl start nginx

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

三、測試nginx是否安裝成功nginx

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

 

4,配置Nginx支持PHP解析vim

     編輯/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-fpm

}post

2、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

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

vim /etc/php.ini

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

三、編輯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

四、啓動PHP—FPM

systemctl start php-fpm

五、設置開機啓動

systemctl enable php-fpm

6,確保Nginx配置文件修該以後,重啓Nginx

systemctl restart nginx

七、在/usr/share/nginx/html/目錄下建立phpinfo.php

    內容以下:

   <?php phpinfo();?>

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

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

    

 3、MySql

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

一、補充yum源(1)

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

二、補充yum源(2)

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

三、安裝mysql

yum install mysql-community-server

四、成功安裝以後重啓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進程IDkill -9 -xxxx            終結ID爲xxxx的進程

相關文章
相關標籤/搜索