Home Operation and Maintenance Linux Operation and Maintenance How to build a PHP server environment in CentOS

How to build a PHP server environment in CentOS

Mar 19, 2018 am 10:36 AM
centos php server

This article mainly introduces how to build a PHP server environment on CentOS. It briefly describes the installation of Apache, mysql, php environment and related test codes on the CentOS platform. It is very simple and practical. Friends who need it can refer to it. I hope it can help everyone. .

1. Install apache first:


##

1

yum install httpd

Copy after login

Configure ServerName


1

vi /etc/httpd/conf/httpd.conf

Copy after login

Change

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

For the external machine, enter the IP of the server at this time For the address, you should see the apache service page. There is no need to enter the port. Apache uses port 80 by default.

If it cannot be opened, port 80 may not be open for external access. Check:


1

/etc/init.d/iptables status

Copy after login
Copy after login

Whether there is information such as 80 or so after it, if not, open it. Pay attention to the position and statement state. There are two horizontal bars in front of the report--:


1

vim /etc/sysconfig/iptables

Copy after login

Join:


1

2

-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT

-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT

Copy after login

Then restart and save the firewall:


1

2

service iptables restart

/etc/rc.d/init.d/iptables save

Copy after login

Check again whether it is enabled:


1

/etc/init.d/iptables status

Copy after login
Copy after login

Start apache:


1

/etc/init.d/httpd start

Copy after login

2. Installation mysql:

##

1

yum install mysql mysql-server

Copy after login

Start mysql:

##

1

/etc/init.d/mysqld start

Copy after login


3 . Install php

##

1

yum install php php-devel

Copy after login

Restart apache to make php take effect


##

1

/etc/init.d/httpd restart

Copy after login
Copy after login

You can now Create a PHP file under directory:/var/www/html/

Code:

1

<?php phpinfo(); ?>

Copy after login

Then access this file, you can see some of PHP Information, the path to the php.ini configuration file can be seen on this page

Install the php extension

##Copy the code

The code is as follows:


yum install php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc

After installing the extension, you need to restart apache again

1

/etc/init.d/httpd restart

Copy after login
Copy after login

PHP code to test whether mysql link is successful


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

<?php

$con = mysql_connect("10.0.@.@@","@@","@@");

if (!$con)

{

 die(&#39;Could not connect: &#39; . mysql_error());

}

mysql_select_db("mydb", $con);

$result = mysql_query("SELECT * FROM sys_user");

while($row = mysql_fetch_array($result))

{

 echo $row[&#39;UserName&#39;] . " " . $row[&#39;PassWord&#39;] . " " . $row[&#39;id&#39;];

 echo "<br />";

}

mysql_close($con);

?>

Copy after login

You can pass the above code into the directory

/var/www/html/

You can see the execution status

Installation directory introduction

Apache points the root directory of the website to by default /var/www/html DirectoryThe default main configuration file is /etc/httpd/conf/httpd.conf

The configuration is stored in /etc/httpd/ conf.d/Directory
Related recommendations:
Use Nginx to build a PHP server

##

The above is the detailed content of How to build a PHP server environment in CentOS. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
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

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1670
14
PHP Tutorial
1274
29
C# Tutorial
1256
24
PHP and Python: Different Paradigms Explained PHP and Python: Different Paradigms Explained Apr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP's Purpose: Building Dynamic Websites PHP's Purpose: Building Dynamic Websites Apr 15, 2025 am 12:18 AM

PHP is used to build dynamic websites, and its core functions include: 1. Generate dynamic content and generate web pages in real time by connecting with the database; 2. Process user interaction and form submissions, verify inputs and respond to operations; 3. Manage sessions and user authentication to provide a personalized experience; 4. Optimize performance and follow best practices to improve website efficiency and security.

Choosing Between PHP and Python: A Guide Choosing Between PHP and Python: A Guide Apr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Python: A Deep Dive into Their History PHP and Python: A Deep Dive into Their History Apr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Why Use PHP? Advantages and Benefits Explained Why Use PHP? Advantages and Benefits Explained Apr 16, 2025 am 12:16 AM

The core benefits of PHP include ease of learning, strong web development support, rich libraries and frameworks, high performance and scalability, cross-platform compatibility, and cost-effectiveness. 1) Easy to learn and use, suitable for beginners; 2) Good integration with web servers and supports multiple databases; 3) Have powerful frameworks such as Laravel; 4) High performance can be achieved through optimization; 5) Support multiple operating systems; 6) Open source to reduce development costs.

PHP's Impact: Web Development and Beyond PHP's Impact: Web Development and Beyond Apr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP vs. Python: Use Cases and Applications PHP vs. Python: Use Cases and Applications Apr 17, 2025 am 12:23 AM

PHP is suitable for web development and content management systems, and Python is suitable for data science, machine learning and automation scripts. 1.PHP performs well in building fast and scalable websites and applications and is commonly used in CMS such as WordPress. 2. Python has performed outstandingly in the fields of data science and machine learning, with rich libraries such as NumPy and TensorFlow.

The Continued Use of PHP: Reasons for Its Endurance The Continued Use of PHP: Reasons for Its Endurance Apr 19, 2025 am 12:23 AM

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

See all articles