在CentOS7系统安装php运行环境:nginx + MariaDB + php-fpm

云友“gzchenyou”曾在帖子 里提到不能正常连接mysql数据库,所以写此帖。

环境:阿里云 CentOS 7 64位系统。

过程:

1.添加 epel 软件安装源
yum install epel-release

2.安装 nginx web:
yum install nginx

3.启动 nginx web服务:
systemctl start nginx
bbs-aliyun-dongshan3-283598-1.png

4.将nginx设置为开机自启动:
systemctl enable nginx

5.安装MariaDB数据库:
yum install mariadb-server mariadb

6.启动MariaDB数据库服务:
systemctl start mariadb

7.通过管理脚本,设置MariaDB数据库管理员root的密码:
mysql_secure_installation

8.设置MariaDB随系统启动自启动:
systemctl enable mariadb

9.安装php-fpm及一些基本的php组件:
yum install php php-mysql php-fpm php-mbstring php-gd

10.编辑php.ini配置文件,设置 cgi.fix_pathinfo 为 0:
vi /etc/php.ini

11.设置 php-fpm 的默认www配置文件,如将监听网络地址修改为本地的sock文件,修改运行用户和组为 nginx:
vi /etc/php-fpm.d/www.conf
bbs-aliyun-dongshan3-283598-2.png

11.启动php-fpm服务:
systemctl start php-fpm

12.设置php-fpm服务为自启动:
systemctl enable php-fpm

13.创建一个新站点配置文件,如phpmyadmin:

vi /etc/nginx/conf.d/phpmyadmin.conf

且将下载好的phpmyadmin文件放在站点配置文件中提到的路径,例子内容如下:

server {
    listen       80;
    server_name  yun.anqun.org;
    # note that these lines are originally from the "location /" block
    root   /usr/share/nginx/html/phpmyadmin;
    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;
    }
}

14.重启nginx服务:
systemctl restart nginx

15.因为修改了php-fpm的运行用户,所以需修改php session存储目录的属组:
chown root:nginx /var/lib/php/session
bbs-aliyun-dongshan3-283598-3.png

参考:https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-centos-7

标签: none

添加新评论