centos php environment setup tutorial

藏色散人
Release: 2020-10-10 09:43:35
Original
5709 people have browsed it

How to build centos php environment: first install apache and configure ServerName; then install mysql; then use the command "yum install php php-devel" to install php; finally restart the service.

centos php environment setup tutorial

Recommended: "centos Getting Started Tutorial"

CentOSBuild a PHP server The environment method

is as follows:

1. Install apache first:

yum install httpd
Copy after login

Configure ServerName

vi /etc/httpd/conf/httpd.conf
Copy after login

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

When the external machine enters the IP address of the server, you should see apache On the 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
Copy after login
Copy after login

is followed by 80 and other information, otherwise Open it, pay attention to the position and statement state, there are two horizontal bars in front of the description -:

vim /etc/sysconfig/iptables
Copy after login

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
Copy after login

Then restart and save the firewall :

service iptables restart
/etc/rc.d/init.d/iptables save
Copy after login

Check again whether it is enabled:

/etc/init.d/iptables status
Copy after login
Copy after login

Start apache:

/etc/init.d/httpd start
Copy after login

2. Install mysql:

yum install mysql mysql-server
Copy after login

Start mysql:

/etc/init.d/mysqld start
Copy after login

3. Install php

yum install php php-devel
Copy after login

Restart apache to make php take effect

/etc/init.d/httpd restart
Copy after login
Copy after login

At this time, you can create a PHP file in the directory:/var/www/html/

Code:

<?php phpinfo(); ?>
Copy after login

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

Install php extension

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
Copy after login
Copy after login

PHP code to test whether mysql link is successful

<?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/
and you can see the execution situation

Installation Directory introduction

Apache points the root directory of the website to /var/www/html Directory
The default main configuration file is /etc/ httpd/conf/httpd.conf
Configuration is stored in the /etc/httpd/conf.d/ directory

The above is the detailed content of centos php environment setup tutorial. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template