CentOS7下安装LNMP以及phpMyAdmin

wangking写道
工作需要用到CentOS7,要求安装LNMP方式,CentOS7下MYSQL已经被Mariadb替代,这个无所谓,完全兼容的,就不需要过虑。那我们就开始吧!

 

1、安装LNMP之前要安装EPEL,以便安装源以外的软件,如Nginx,phpMyAdmin等。

yum install epel-release

 

2、安装Nginx

a) yum install nginx
b) systemctl start nginx #启动nginx
c) systemctl enable nginx #设置开机启动

 3、安装MYSQL(MariaDB)

a) yum install mariadb-server mariadb
b) systemctl start mariadb #启动mariadb
c) systemctl enable mariadb #设置开机启动

 4、设置MariaDB密码

mysql_secure_installation #会要求输入原密码,直接点击回车就行,剩下的就是输入新密码以及确认密码

5、安装PHP

yum install -y php php-fpm php-mysql php-common php-devel php-gd libjpeg* php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-bcmath php-mhash libmcrypt libmcrypt-devel

 

6、开启php-fpm

a) systemctl start php-fpm #开启php-fpm
b) systemctl enable php-fpm #开机自动启动

7、安装phpMyAdmin

 

a) wget https://files.phpmyadmin.net/phpMyAdmin/4.4.12/phpMyAdmin-4.4.12-all-languages.zip
b) cd /usr/share/nginx/html/
c) unzip phpMyAdmin-4.4.12-all-languages.zip
d) mv phpMyAdmin-4.4.12-all-languages phpmyadmin
e) chown -R nginx.nginx /var/lib/php/session
#访问http://youipaddress/phpmyadmin,如果能访问上,那么就成功了!

 

8、修改相应的配置

      A) 修改php.ini的配置

vim /etc/php.ini
#将cgi.fix_pathinfo=1改为 cgi.fix_pathinfo=0

      B) 修改php-fpm的配置

vim /etc/php-fpm.d/www.conf
#将listen = 127.0.0.1:9000的注释去掉,并改为 listen = /var/run/php-fpm/php-fpm.sock

找到以下两行,解除注释
listen.owner = nobody
listen.group = nobody

找下以下两行,将各自的apache改为nginx
user = apache -> user = nginx
group = apache -> group = nginx

 

     C) 修改nginx的配置

vim /etc/nginx/conf.d/default.conf
server {
    listen       80;
    server_name  server_domain_name_or_IP;

    # note that these lines are originally from the "location /" block
    root   /usr/share/nginx/html;
    index index.php index.html index.htm;

    location / {
        try_files $uri $uri/ =404;
    }
    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}
 

 

你可能感兴趣的:(CentOS7下安装LNMP以及phpMyAdmin)