确保安装php的时候指明了--with-apxs2参数
编辑Apache配置文件:
vim /usr/local/apache/conf/httpd.conf
查看该文件是否有下面一行,如果没有,说明php安装的时候没有正确指明了--with-apxs2参数,或安装出错,请参考之前的php安装的文章。
LoadModule php7_modulemodules/libphp7.so
找到
DirectoryIndex index.html
修改为:
DirectoryIndex index.html index.htm index.php
找到
AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps
在下一行添加:
AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps
找到
#Include conf/extra/httpd-vhosts.conf
去掉前面的‘#’号
vim /usr/local/apache/conf/extra/httpd-vhosts.conf
删除里面的内容 添加以下内容:
<VirtualHost *:80> #ServerAdmin [email protected] DocumentRoot "/wwwroot/my-site.com/" ServerName my-site.com #ServerAlias www.my-site.com ErrorLog "logs/my-site.com-error_log" CustomLog "logs/my-site.com-access_log" common<Directory "/wwwroot/my-site.com/"> SetOutputFilter DEFLATE Options FollowSymLinks AllowOverride All Order allow,deny Allow from all DirectoryIndex index.html index.php</Directory></VirtualHost>
创建站点目录:
mkdir -p /wwwroot/my-site.com/
创建一个php的文件,并输出phpinfo:
cat >/wwwroot/my-site.com/index.php<<EOF <?php echo phpinfo();EOF
修改站点目录文件的权限,和Apache的运行用户相同
chmod -R 755 /wwwroot/my-site.com chown -R www:www /wwwroot/my-site.com
重启Apache
systemctl restart httpd
域名解析,这里就直接修改hosts文件啦,加入
127.0.0.1 my-site.com
然后浏览器访问:http://my-site.com/