centos怎么部署php项目-PHP问题

资源魔 27 0

centos怎样部署php名目?

CentOS 7部署PHP名目

目次

1、装置nginx(主动)

2、装置mysql

3、修正mysql登录明码

4、装置PHP及扩大

5、设置装备摆设nginx站点

6、名目测试部署

写正在后面:本文编纂效劳器文件应用的是editplus对象

1、装置nginx(主动)

增加nginx源

rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

装置nginx

yum install nginx

启动nginx效劳

systemctl start nginx.service    //启动
systemctl enable nginx.service    //开机启动

测试拜访,假如能够看到nginx欢送界面则阐明装置胜利且能失常拜访

2、装置mysql

wget http://dev.mysql.com/get/mysql-co妹妹unity-release-el7-5.noarch.rpm    //下载mysql源
rpm -ivh mysql-co妹妹unity-release-el7-5.noarch.rpm    //装置mysql源
yum install mysql-co妹妹unity-server    //装置mysql

启动mysql效劳

systemctl start mysqld    //启动
systemctl enable mysqld    //开机启动
systemctl daemon-reload    //开机启动

3、修正mysql登录明码

grep 'temporary password' /var/log/mysqld.log    //查看暂时天生的明码
mysql -uroot -p    //应用暂时明码登录
> ALTER USER 'root'@'localhost' IDENTIFIED BY '新明码';    //修正明码

4、装置PHP及扩大

yum install php php-mysql php-fpm php-mbstring php-gd php-pear php-mhash php-eaccelerator  php-cli php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mssql php-snmp php-soap php-tidy php-co妹妹on php-devel php-pecl-xdebug phpmyadmin php-mcrypt -y

编纂/etc/php.ini文件,修正参数

cgi.fix_pathinfo=0

编纂/etc/php-fpm.d/www.conf文件,修正参数

listen = /var/run/php-fpm/php-fpm.sock

启动php-fpm效劳

systemctl start php-fpm    //启动
systemctl enable php-fpm.service    //开机启动

5、设置装备摆设nginx站点

修正/etc/nginx/conf.d/default.conf文件,增加以下参数

server {
    listen       80;
    server_name  www.sange.com;    #需求修正客户端hosts文件
 
    root   /opt/data;    #PHP名目根门路
    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;
    }
}

重启nginx效劳

systemctl restart nginx

6、名目测试部署

新建/opt/data/info.php文件,关上文件编纂,增加

<?php phpinfo()?>

阅读器拜访www.sange.com,能够看到php各类设置装备摆设信息则阐明设置装备摆设胜利,如

当然,这只是为了测试一下环境而新建的一个简略php文件,认真正部署名目的时分,需求修正名目数据库设置装备摆设文件顶用户名跟明码,导入数据库操作。正在这类状况下,假如需求客户端登录数据库,效劳器的mysql需求设置容许近程登录性能,授予用户拜访权限。当阅读器拜访需求衔接数据库时,默许状况下会遇到一个谬误提醒,那就是SQLSTATE[HY000] [2003] Can't connect to MySQL server on '127.0.0.1' (13)。

成绩:SQLSTATE[HY000] [2003] Can't connect to MySQL server on '127.0.0.1' (13)

缘由:SELinux 没有让 httpd 拜访外网

处理方法:

getsebool -a | grep httpd    //查看httpd状态
setsebool httpd_can_network_connect 1     //容许外拜访
systemctl restart mysqld.service    //重启mysql效劳

以上就是centos怎样部署php名目的具体内容,更多请存眷资源魔其它相干文章!

标签: php教程 Centos php项目 php故障解决 php使用问题

抱歉,评论功能暂时关闭!