Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does centos7 deploy the php project

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

Centos7 how to deploy the php project, I believe that many inexperienced people do not know what to do, so this article summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.

Centos7 deployment method of php project: 1, install nginx and mysql;2 through yum install, change mysql login password; 3, install PHP and extension; 4, configure nginx site; 5, test and deploy the project.

This article operating environment: centos7 system, PHP7.1 version, DELL G3 computer

How does centos7 deploy the php project?

CentOS 7 how to deploy the PHP project:

First, install nginx (automatic)

Add nginx Feed

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 the nginx service

Systemctl start nginx.service / / start

Systemctl enable nginx.service / / Boot start

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

Second, install mysql

Wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm / / download mysql feed

Rpm-ivh mysql-community-release-el7-5.noarch.rpm / / install the mysql source

Yum install mysql-community-server / / install mysql

Start the mysql service

Systemctl start mysqld / / start

Systemctl enable mysqld / / Boot start

Systemctl daemon-reload / / Boot start

3. Modify the mysql login password

Grep 'temporary password' / var/log/mysqld.log / / View temporarily generated passwords

Mysql-uroot-p / / Log in with a temporary password

> ALTER USER 'root'@'localhost' IDENTIFIED BY' New password; / / change password

Fourth, 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 / etc/php.ini file, modify parameters

Cgi.fix_pathinfo=0

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

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

Start the php-fpm service

Systemctl start php-fpm / / start

Systemctl enable php-fpm.service / / Boot start

5. Configure nginx site

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

Server {

Listen 80

Server_name www.sange.com; # needs to modify the client hosts file

Root / opt/data; # PHP project root path

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 the nginx service

Systemctl restart nginx

VI. Project test deployment

Create a new / opt/data/info.php file, open file editing, add

When the browser accesses www.sange.com, you can see various configuration information of php, which indicates that the configuration is successful, such as

Of course, this is just a new simple php file to test the environment. When you actually deploy the project, you need to change the user name and password in the project database configuration file and import the database operation. In this case, if the client is required to log in to the database, the server's mysql needs to be set up to allow remote login and grant the user access. By default, when a browser needs to connect to a database, it will encounter an error message: SQLSTATE [HY000] [2003] Can't connect to MySQL server on '127.0.0.1' (13).

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

Reason: SELinux does not allow httpd to access the public network

Solution:

Getsebool-a | grep httpd / / View httpd status

Setsebool httpd_can_network_connect 1 / / allow external access

Systemctl restart mysqld.service / / restart the mysql service

After reading the above, have you mastered how centos7 deploys the php project? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report