How to set up centos yum installation php environment: 1. Install apache through "yum install httpd"; 2. Install mysql; 3. Install PHP through "yum install php php-devel" command; 4. Restart apache That’s it.
The operating environment of this article: centOS8 system, PHP7.2 version, DELL G3 computer
centos8 installation and establishment of php environment
After the window/centos dual system installation is completed, next set up a php environment on centos.
There are also many installation tutorials on the Internet, but they are all the same. Below I will directly use yum to install them. The latest version is installed by default.
Install apache:
yum install httpd
//配置ServerName //将#ServerName www.example.com:80修改为ServerName localhost:80 vi /etc/httpd/conf/httpd.conf //启动apache: systemctl start httpd ///查看安装版本: (我的是apache/2.4.37) httpd -v //设置开机启动: systemctl enable httpd
Install mysql:
yum install mysql mysql-server
//启动mysql systemctl start mysqld.service
//设置root密码为123456 mysqladmin -u root password 123456 //后续如果需要修改root密码 alter user 'root'@'%' identified with mysql_native_password by '新密码’; //登录mysql mysql -u root -p //需要输入密码 //设置远程可访问 grant all privileges on *.* to 'root'@'%'with grant option; flush privileges; //如果远程还是无法访问,有可能是防火墙的原因,关闭防火墙 //这里可以查看root用户的host ‘localhost' 已经变成了 ’%‘ use mysql select host,user from user;
Install php:
yum install php php-devel
//查看php版本 (我的是php 7.2.11) php -v //安装php扩展 yum install php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc //我这里在安装php-mysql的时候会提示错误:没有匹配的参数:php-mysql //解决如下: yum search php-mysql //找到两个匹配版本:php-mysqlnd.x86_64 ;执行安装 yum install php-mysqlnd.x86_64
//启动php systemctl start php-fpm //设置开机启动 systemctl enable php-fpm
Finally restart apache: systemctl restart httpd. All installations have been completed here environment.
The default parsing directory of apache is in the /var/www/html directory, change it to the /var/www directory
vim /etc/httpd/conf/httpd.conf
From DocumentRoot “var/www/html/ " Start changing to "var/www/"
Restart apache:
systemctl restart httpd
Testable: Create a new file index.php in the /var/www/ directory. Directly access the browser: localhost will display Contents of index.php
Set up multiple sites: Create a new .conf file in the /etc/httpd/conf.d/ directory; create a new website directory in the corresponding /var/www/ directory
cd /etc/httpd/conf.d/ touch test.conf //test.conf 插入代码 <VirtualHost *:80> DocumentRoot /var/www/test ServerName www.test.com <Directory "/var/www/test"> Require all granted Options FollowSymLinks AllowOverride all #Require all denied </Directory> </VirtualHost>
Customer Specify the IP address and domain name on the hosts side, and you can access the website normally. (Such as 192.168.2.144 www.test.com)
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to install php environment in centos yum. For more information, please follow other related articles on the PHP Chinese website!