Home  >  Article  >  Backend Development  >  How to install php environment under ubuntu

How to install php environment under ubuntu

藏色散人
藏色散人Original
2020-10-10 09:32:148900browse

How to install the php environment under ubuntu: first install Apache and MySQL; then install the new version of php through the command "sudo apt-get install php"; finally install other modules and restart the service.

How to install php environment under ubuntu

Recommended: "PHP Video Tutorial"

1. Install Apache

sudo apt-get install apache2
测试:浏览器访问 http://localhost   //会出现网页。
查看状态: service apache2 status/start/stop/restart
Web目录: /var/www
安装目录: /etc/apache2/
全局配置: /etc/apache2/apache2.conf
监听端口: /etc/apache2/ports.conf
虚拟主机: /etc/apache2/sites-enabled/000-default.conf

2, Install MySQL, skip it if installed. If it is not installed, click here to install mysql.

3. Install PHP

Check the local php version, run

php -v

to install the latest version of php, use the command

sudo apt-get install php

4. Install other modules

sudo apt-get install libapache2-mod-php
sudo apt-get install php7.0-mysql

Restart the service

service apache2 restart
service mysql restart

Test whether Apache can parse PHP

vim /var/www/html/phpinfo.php

文件代码为:<?php echo phpinfo();?>

浏览器访问:http://localhost/phpinfo.php  //会出现PHP Version网页,如果是云服务器,则将 localhost 改为你云服务器IP

5. Modify permissions

sudo chmod 777 /var /www

6. Install phpMyAdmin

sudo apt-get install phpmyadmin

During installation: (space to enter) select apache2, click Confirm (Enter).

If the following error occurs

##, the solution is:

sudo mv /var/lib/dpkg/info /var/lib/dpkg/info_old   //现将info文件夹更名
sudo mkdir /var/lib/dpkg/info     //再新建一个新的info文件夹
sudo apt-get update && apt-get -f install   //重新下载
sudo mv /var/lib/dpkg/info/* /var/lib/dpkg/info_old   //执行完上一步操作后会在新的info文件夹下生成一些文件,现将这些文件全部移到info_old文件夹下
sudo rm -rf /var/lib/dpkg/info  //把自己新建的info文件夹删掉
sudo mv /var/lib/dpkg/info_old  /var/lib/dpkg/info //把以前的info文件夹重新改

Restart and test

//测试
service php7.0-fpm restart  //注意版本
service apache2 restart

//测试
http://localhost/phpmyadmin  //远程侧修改 localhost

7. Configure Apache

vim /etc/apache2/apache2.conf

末尾添加:

include /etc/phpmyadmin/apache.conf

AddType application/x-httpd-php .php .htm .html

AddDefaultCharset UTF-8

Restart the Apache service

service apache2 restart

Note: Enter http://localhost/phpmyadmin/ in the browser to enter the console.

The above is the detailed content of How to install php environment under ubuntu. 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