Home  >  Article  >  Backend Development  >  How to deploy php project in centos

How to deploy php project in centos

藏色散人
藏色散人Original
2019-11-11 10:22:483525browse

How to deploy php project in centos

How to deploy php projects in centos?

CentOS 7 Deployment PHP Project

Directory

1. Install nginx (automatic)

2. Install mysql

3. Modify mysql login password

4. Install PHP and extensions

5. Configure nginx site

6. Project Test deployment

Written in front: This article uses the editplus tool to edit the server file

1. Install nginx (automatic)

Add nginx source

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

Install nginx

yum install nginx

Start nginx service

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

Test the access. If you can see the nginx welcome interface, it means the installation is successful and you can access it normally

II , install 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

Start the mysql service

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

3. Modify the mysql login password

grep 'temporary password' /var/log/mysqld.log    //查看临时生成的密码
mysql -uroot -p    //使用临时密码登录
> ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码';    //修改密码

4. Install PHP and Extension

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

Edit the /etc/php.ini file and modify the parameters

cgi.fix_pathinfo=0

Edit the /etc/php-fpm.d/www.conf file , modify parameters

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

Start php-fpm service

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

5. Configure nginx site

Modify /etc/nginx/conf.d/default .conf file, add the following parameters

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;
    }
}

Restart nginx service

systemctl restart nginx

6. Project test deployment

New/opt /data/info.php file, open the file for editing, add

<?php phpinfo()?>

. Visit www.sange.com with a browser. If you can see various php configuration information, it means the configuration is successful, such as

Of course, this is just a simple php file created to test the environment. When the project is actually deployed, the user name and password in the project database configuration file need to be modified and the database operation is imported. In this case, if the client needs to log in to the database, the server's mysql needs to be set to allow remote login to grant the user access rights. When the browser needs to connect to the database, it will encounter an error message by default, which is SQLSTATE[HY000] [2003] Can't connect to MySQL server on '127.0.0.1' (13).

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

Cause: SELinux does not allow httpd to access the external network

Solution:

getsebool -a | grep httpd    //查看httpd状态
setsebool httpd_can_network_connect 1     //允许外访问
systemctl restart mysqld.service    //重启mysql服务

The above is the detailed content of How to deploy php project in centos. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:How to download php5Next article:How to download php5