开发者社区> 问答> 正文

在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
[attachment=102593]

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-gd10.编辑php.ini配置文件,设置 cgi.fix_pathinfo 为 0:
vi /etc/php.ini
11.设置 php-fpm 的默认www配置文件,如将监听网络地址修改为本地的sock文件,修改运行用户和组为 nginx:
vi /etc/php-fpm.d/www.conf
[attachment=102594]

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
[attachment=102595]

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

展开
收起
dongshan8 2016-05-30 17:56:07 9102 0
1 条回答
写回答
取消 提交回答
  • 一个程序员,欢迎骚扰!!!
    MariaDB数据库管理系统原来是是MySQL的一个分支  长见识了

    -------------------------

    还有  强大的systemctl  以前 还真不知道

    2016-05-30 21:08:35
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
PHP安全开发:从白帽角度做安全 立即下载
PHP 2017.北京 全球开发者大会——高可用的PHP 立即下载
复杂PHP系统性能瓶颈排查及优化 立即下载