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
vi /etc/httpd/conf/httpd.conf
#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
vim /etc/sysconfig/iptables
-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
service iptables restart /etc/rc.d/init.d/iptables save
/etc/init.d/iptables status
/etc/init.d/httpd start
2. Installation mysql:
##
yum install mysql mysql-server
/etc/init.d/mysqld start
##
yum install php php-devel
/etc/init.d/httpd restart
You can now Create a PHP file under directory:/var/www/html/
Code:
<?php phpinfo(); ?>
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 $con = mysql_connect("10.0.@.@@","@@","@@"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("mydb", $con); $result = mysql_query("SELECT * FROM sys_user"); while($row = mysql_fetch_array($result)) { echo $row['UserName'] . " " . $row['PassWord'] . " " . $row['id']; echo "<br />"; } mysql_close($con); ?>
/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!