search
HomeBackend DevelopmentPHP TutorialTeach you how to deploy php projects under Linux - Apache, php, mysql association (share)

This article will share with you how to deploy php projects under Linux - Apache, php, mysql association (sharing), which has certain reference value. Friends in need can refer to it. I hope it will be helpful to you. Everyone helps.

Teach you how to deploy php projects under Linux - Apache, php, mysql association (share)

## The environment for deploying PHP projects under Linux can be divided into two types. One uses compressed packages of Apache, PHP and MySQL. Installation, one is to use the yum command to install.

Use the compressed packages of the three software to install, and you need to manually configure the relationship between the three. The configuration between apache and php is not difficult, but when configuring with mysql, you need to understand php.

The following is to use yum to configure the php environment in linux:

MySql

1. Mysql and apache are best installed first, because When configuring php, you need to configure and test related to mysql and apache

First download the mysql-sever file, because the blogger's Linux environment is the CentOS version, and there seems to be no mysql-sever in the yum source when mysql is installed normally. File, you need to download it from the official website

1.下载mysql-service文件
[root@tele-1 ~]# wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
2.安装mysql-service文件
[root@tele-1 ~]# rpm -ivh mysql-community-release-el7-5.noarch.rpm

2. Install mysql

[root@tele-1 ~]# yum install mysql-community-server

3. After the installation is complete, start the mysql service

[root@tele-1 ~]# service mysqld restart

4. The initial installation of mysql does not have a password, and the default user name is root. So we need to change the password and use the mysql command line to change it

 

1. Enter the mysql command line

[root@tele-1 ~]# mysql -uroot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 474801
Server version: 5.6.36 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

<strong>2.使用命令进行密码修改</strong><br>
mysql> set password for &#39;root&#39;@&#39;localhost&#39; = password(&#39;你要修改的密码&#39;);
Query OK, 0 rows affected (0.06 sec)

5. Because the blogger uses The local navicat software is used to connect to mysql under Linux, so if you want to access it locally, you need to change the user table in the mysql database

1.操作mysql数据库表
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql>
2.查看user表中的数据(在mysql命令行中可以直接进行sql语句编写)
mysql> select * from user;
mysql>

3. In the blogger's table This is the modified table. If you want remote access, you need the data marked in red above. Host refers to the IP address that can access this database, and % means that all requests can be connected.

You can modify a piece of data or add a piece of data. But it is best not to modify the data marked in blue above. The modified statement is in the format below

mysql> update user set Host = &#39;%&#39; where ???

4. Finally, exit or \q are the methods to exit the mysql command line

mysql> \q
Bye

Installing Apache

1. The apache installation method is relatively simple

[root@tele-2 ~]# yum install httpd

2. Access the virtual machine from the external network Address, we need to modify the apache configuration file /etc/httpd/conf/httpd.conf

Find #ServerName www.example.com :80 Change to ServerName localhost:80

As shown in the picture on the right:

## Find #Listen Change to Listen:8080( The open port number in linux is 80XX)

As shown in the picture on the right:

3. After the modification is completed, we need to start the httpd service again and check the startup status

[root@tele-2 ~]# service httpd start
Redirecting to /bin/systemctl start  httpd.service
[root@tele-2 ~]# service httpd status
Redirecting to /bin/systemctl status  httpd.service
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2017-06-05 15:57:34 CST; 5s ago
     Docs: man:httpd(8)
           man:apachectl(8)
  Process: 54532 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=0/SUCCESS)
  Process: 39046 ExecReload=/usr/sbin/httpd $OPTIONS -k graceful (code=exited, status=0/SUCCESS)
 Main PID: 54573 (httpd)
   Status: "Processing requests..."
   Memory: 15.8M
   CGroup: /system.slice/httpd.service
           ├─54573 /usr/sbin/httpd -DFOREGROUND
           ├─54576 /usr/sbin/httpd -DFOREGROUND
           ├─54577 /usr/sbin/httpd -DFOREGROUND
           ├─54578 /usr/sbin/httpd -DFOREGROUND
           ├─54579 /usr/sbin/httpd -DFOREGROUND
           └─54580 /usr/sbin/httpd -DFOREGROUND

Jun 05 15:57:34 tele-2 systemd[1]: Starting The Apache HTTP Server...
Jun 05 15:57:34 tele-2 systemd[1]: Started The Apache HTTP Server.

4. At this point you can access your server, enter localhost or IP address, and an Apache test page powered by centos test page will appear

PHP

 1.php installation command

[root@tele-2 ~]# yum install php

 2. Install directly all the way, and restart the httpd service again after the installation is complete

[root@tele-2 ~]# service httpd start
Redirecting to /bin/systemctl start  httpd.service

3. After restarting, we will test PHP related information. We will create a new PHP interface for testing

In the apache default page path

/

# Create a new test.php page under ##var/www/html and add the code

<?php
 phpinfo();
?>
 4. Visit this page and enter localhost/test.php, or ip: Port number/test.php You can see the configuration information of the php environment

 

Associate php and mysql

1. Search module

[root@tele-2 ~]# yum search php
2. Install related modules

[root@tele-2 ~]# yum install php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml  php-xmlrpc
3. After the installation is completed, restart mysqld, Restart httpd and revisit the info.php just now. We find that there is more MySQL related information. As shown on the right:

 至此,php在linux中的运行环境就已经成功配置完成了。

 

1.mysql yum安装默认文件夹及相关命令

数据库目录:/var/lib/mysql/

配置文件:/usr/share/mysql(mysql.server命令及配置文件)

相关命令:/usr/bin(mysqladmin mysqldump等命令)

my.cnf: /etc/my.cnf

启动脚本:/etc/rc.d/init.d/(启动脚本文件mysql的目录)
启动命令:service mysql start
停止命令:service mysql stop
运行状态:service mysql status

 2.apache

配置文件路径:/etc/httpd/conf/httpd.conf
启动命令:service httpd start
停止命令:service httpd stop
运行状态:service httpd status

 3.php

php默认页面路径:/var/www/html

推荐学习:《PHP视频教程

 

 

 

 

The above is the detailed content of Teach you how to deploy php projects under Linux - Apache, php, mysql association (share). For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:CSDN. If there is any infringement, please contact admin@php.cn delete
What is the difference between unset() and session_destroy()?What is the difference between unset() and session_destroy()?May 04, 2025 am 12:19 AM

Thedifferencebetweenunset()andsession_destroy()isthatunset()clearsspecificsessionvariableswhilekeepingthesessionactive,whereassession_destroy()terminatestheentiresession.1)Useunset()toremovespecificsessionvariableswithoutaffectingthesession'soveralls

What is sticky sessions (session affinity) in the context of load balancing?What is sticky sessions (session affinity) in the context of load balancing?May 04, 2025 am 12:16 AM

Stickysessionsensureuserrequestsareroutedtothesameserverforsessiondataconsistency.1)SessionIdentificationassignsuserstoserversusingcookiesorURLmodifications.2)ConsistentRoutingdirectssubsequentrequeststothesameserver.3)LoadBalancingdistributesnewuser

What are the different session save handlers available in PHP?What are the different session save handlers available in PHP?May 04, 2025 am 12:14 AM

PHPoffersvarioussessionsavehandlers:1)Files:Default,simplebutmaybottleneckonhigh-trafficsites.2)Memcached:High-performance,idealforspeed-criticalapplications.3)Redis:SimilartoMemcached,withaddedpersistence.4)Databases:Offerscontrol,usefulforintegrati

What is a session in PHP, and why are they used?What is a session in PHP, and why are they used?May 04, 2025 am 12:12 AM

Session in PHP is a mechanism for saving user data on the server side to maintain state between multiple requests. Specifically, 1) the session is started by the session_start() function, and data is stored and read through the $_SESSION super global array; 2) the session data is stored in the server's temporary files by default, but can be optimized through database or memory storage; 3) the session can be used to realize user login status tracking and shopping cart management functions; 4) Pay attention to the secure transmission and performance optimization of the session to ensure the security and efficiency of the application.

Explain the lifecycle of a PHP session.Explain the lifecycle of a PHP session.May 04, 2025 am 12:04 AM

PHPsessionsstartwithsession_start(),whichgeneratesauniqueIDandcreatesaserverfile;theypersistacrossrequestsandcanbemanuallyendedwithsession_destroy().1)Sessionsbeginwhensession_start()iscalled,creatingauniqueIDandserverfile.2)Theycontinueasdataisloade

What is the difference between absolute and idle session timeouts?What is the difference between absolute and idle session timeouts?May 03, 2025 am 12:21 AM

Absolute session timeout starts at the time of session creation, while an idle session timeout starts at the time of user's no operation. Absolute session timeout is suitable for scenarios where strict control of the session life cycle is required, such as financial applications; idle session timeout is suitable for applications that want users to keep their session active for a long time, such as social media.

What steps would you take if sessions aren't working on your server?What steps would you take if sessions aren't working on your server?May 03, 2025 am 12:19 AM

The server session failure can be solved through the following steps: 1. Check the server configuration to ensure that the session is set correctly. 2. Verify client cookies, confirm that the browser supports it and send it correctly. 3. Check session storage services, such as Redis, to ensure that they are running normally. 4. Review the application code to ensure the correct session logic. Through these steps, conversation problems can be effectively diagnosed and repaired and user experience can be improved.

What is the significance of the session_start() function?What is the significance of the session_start() function?May 03, 2025 am 12:18 AM

session_start()iscrucialinPHPformanagingusersessions.1)Itinitiatesanewsessionifnoneexists,2)resumesanexistingsession,and3)setsasessioncookieforcontinuityacrossrequests,enablingapplicationslikeuserauthenticationandpersonalizedcontent.

See all articles

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 Tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function