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

How to build a PHP server environment in CentOS

小云云
小云云Original
2018-03-19 10:36:376370browse

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:


##

yum install httpd

Configure ServerName


vi /etc/httpd/conf/httpd.conf

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:


/etc/init.d/iptables status

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--:


vim /etc/sysconfig/iptables

Join:


-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

Then restart and save the firewall:


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

Check again whether it is enabled:


/etc/init.d/iptables status

Start apache:


/etc/init.d/httpd start

2. Installation mysql:

##

yum install mysql mysql-server

Start mysql:

##
/etc/init.d/mysqld start


3 . Install php

##

yum install php php-devel

Restart apache to make php take effect


##
/etc/init.d/httpd restart

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

Code:

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

/etc/init.d/httpd restart

PHP code to test whether mysql link is successful


";
}
mysql_close($con);
?>

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:
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