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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Backup and Recovery Policy of GitLab under CentOS System In order to ensure data security and recoverability, GitLab on CentOS provides a variety of backup methods. This article will introduce several common backup methods, configuration parameters and recovery processes in detail to help you establish a complete GitLab backup and recovery strategy. 1. Manual backup Use the gitlab-rakegitlab:backup:create command to execute manual backup. This command backs up key information such as GitLab repository, database, users, user groups, keys, and permissions. The default backup file is stored in the /var/opt/gitlab/backups directory. You can modify /etc/gitlab

The key differences between CentOS and Ubuntu are: origin (CentOS originates from Red Hat, for enterprises; Ubuntu originates from Debian, for individuals), package management (CentOS uses yum, focusing on stability; Ubuntu uses apt, for high update frequency), support cycle (CentOS provides 10 years of support, Ubuntu provides 5 years of LTS support), community support (CentOS focuses on stability, Ubuntu provides a wide range of tutorials and documents), uses (CentOS is biased towards servers, Ubuntu is suitable for servers and desktops), other differences include installation simplicity (CentOS is thin)

The CentOS shutdown command is shutdown, and the syntax is shutdown [Options] Time [Information]. Options include: -h Stop the system immediately; -P Turn off the power after shutdown; -r restart; -t Waiting time. Times can be specified as immediate (now), minutes ( minutes), or a specific time (hh:mm). Added information can be displayed in system messages.

Improve HDFS performance on CentOS: A comprehensive optimization guide to optimize HDFS (Hadoop distributed file system) on CentOS requires comprehensive consideration of hardware, system configuration and network settings. This article provides a series of optimization strategies to help you improve HDFS performance. 1. Hardware upgrade and selection resource expansion: Increase the CPU, memory and storage capacity of the server as much as possible. High-performance hardware: adopts high-performance network cards and switches to improve network throughput. 2. System configuration fine-tuning kernel parameter adjustment: Modify /etc/sysctl.conf file to optimize kernel parameters such as TCP connection number, file handle number and memory management. For example, adjust TCP connection status and buffer size

Steps to configure IP address in CentOS: View the current network configuration: ip addr Edit the network configuration file: sudo vi /etc/sysconfig/network-scripts/ifcfg-eth0 Change IP address: Edit IPADDR= Line changes the subnet mask and gateway (optional): Edit NETMASK= and GATEWAY= Lines Restart the network service: sudo systemctl restart network verification IP address: ip addr

Common problems and solutions for Hadoop Distributed File System (HDFS) configuration under CentOS When building a HadoopHDFS cluster on CentOS, some common misconfigurations may lead to performance degradation, data loss and even the cluster cannot start. This article summarizes these common problems and their solutions to help you avoid these pitfalls and ensure the stability and efficient operation of your HDFS cluster. Rack-aware configuration error: Problem: Rack-aware information is not configured correctly, resulting in uneven distribution of data block replicas and increasing network load. Solution: Double check the rack-aware configuration in the hdfs-site.xml file and use hdfsdfsadmin-printTopo

GitLab Database Deployment Guide on CentOS System Selecting the right database is a key step in successfully deploying GitLab. GitLab is compatible with a variety of databases, including MySQL, PostgreSQL, and MongoDB. This article will explain in detail how to select and configure these databases. Database selection recommendation MySQL: a widely used relational database management system (RDBMS), with stable performance and suitable for most GitLab deployment scenarios. PostgreSQL: Powerful open source RDBMS, supports complex queries and advanced features, suitable for handling large data sets. MongoDB: Popular NoSQL database, good at handling sea

The state of the CentOS firewall can be viewed through the sudo firewall-cmd --state command, returning to running or not running. For more detailed information, you can use sudo firewall-cmd --list-all to view, including configured areas, services, ports, etc. If firewall-cmd does not solve the problem, you can use sudo iptables -L -n to view iptables rules. Be sure to make a backup before modifying the firewall configuration to ensure server security.
