类别:PHP问题 / 日期:2019-11-26 / 浏览:188 / 评论:0

centos怎样布置php项目?

CentOS 7布置PHP项目

目次

一、装置nginx(自动)

二、装置mysql

三、修正mysql登录暗码

四、装置PHP及扩大

五、设置nginx站点

六、项目测试布置

写在前面:本文编辑效劳器文件运用的是editplus东西

一、装置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迎接界面则申明装置胜利且能一般接见

二、装置mysql

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

启动mysql效劳

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

三、修正mysql登录暗码

grep 'temporary password' /var/log/mysqld.log    //检察暂时生成的暗码
mysql -uroot -p    //运用暂时暗码登录
> ALTER USER 'root'@'localhost' IDENTIFIED BY '新暗码';    //修正暗码

四、装置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-common 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    //开机启动

五、设置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

六、项目测试布置

新建/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项目的细致内容,更多请关注ki4网别的相干文章!

打赏

感谢您的赞助~

打开支付宝扫一扫,即可进行扫码打赏哦~

版权声明 : 本文未使用任何知识共享协议授权,您可以任何形式自由转载或使用。

 可能感兴趣的文章