search
HomeBackend DevelopmentPHP ProblemHow to deploy php project in centos

How to deploy php project in centos

Nov 11, 2019 am 10:22 AM
centosphp project

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment