Install apache+PHP under Ubuntu

1、 Install apache2
sudo apt-get install apache2

Run the following command to restart: sudo /etc/init.d/apache2 restart

Enter http://localhost or http://127.0.0.1 in the browser. If you see It works!, then Apache has been successfully installed.

If you don’t see It works at this time! Don't worry, please see the solution below:

It should be noted that the common apache release version configuration file is:
httpd.conf
The main configuration file of the Ubuntu release version is:
/etc/apache2/apache2.conf

So, if you see someone configure httpd.conf, but you don't have this, it's normal!

**If you don’t see It works! So ** modify /etc/apache2/apache2.conf, add a line of content: ServerName 127.0.0.1:80

Some commonly used commands in Apache2

The generated start and stop file is: /etc/init.d/apache2

The configuration file is: /etc/apache2/apache2.conf

Start: sudo apache2ctl -k start

Stop: sudo apache2ctl -k stop

Restart: sudo apache2ctl -k restart

After installing apache, a directory named www will be returned under /var, and there is an html folder in it. This is the default web directory of apache. Due to the security principles of the Linux system, the file read and write permissions under the directory are changed. Only the root user is allowed to operate, so we cannot create new PHP files in the www folder, nor can we modify or delete them. We must first modify the read and write permissions of the /var/www directory, execute the command: sudo chmod 777 /var/www

2、 Install PHP

sudo apt-get install libapache2-mod-php5 php5

After installation, we need to restart Apache to let it load the PHP module:

sudo /etc/init.d/apache2 restart

** 3、 test**

Now you can create a new test.php file under the Web directory to test whether PHP can run normally:

sudo vim /var/www/test.php

Then enter:

Then save the file and enter http://127.0.0.1/test.php in the browser. If hello, world!! is displayed on the webpage, then PHP is already running normally.

** 4、 reference**

For more information about apache configuration file and Web shared directory, please see here, in simple terms:

The configuration file of apache under ubuntu is /etc/apache2/apache2.conf, and Apache will automatically read the configuration information of this file when it starts. Other configuration files, such as httpd.conf, are included through the Include directive, and these Include lines can be found in apache2.conf. For Ubuntu, the default web document root directory of apache is /var/www, which is specified in /etc/apache2/sites-enabled/000-default: DocumentRoot /var/www/

Recommended Posts

Install apache+PHP under Ubuntu
Install node.js under Ubuntu
Install python3.6 under Ubuntu 16.04
Install mysql under Ubuntu 16.04
Install Thrift under ubuntu 14.10
Install OpenJDK10 under Ubuntu
Install Caffe under Ubuntu 14.04
2018-09-11 Install arduino under Ubuntu
Install ROS under ROS Ubuntu 18.04[2]
Install MySQL under Ubuntu
Install Yarm-PM2 under Ubuntu
Install server-side Shadowsocks under Ubuntu 16.04
Install rgl package under Ubuntu
Install 3 single-cell R packages under Ubuntu
Install and deploy Gerrit under Ubuntu
Install MySQL under Ubuntu 18.04 (graphic tutorial)
Install JDK1.8 original under Ubuntu Kylin
Small tool: install screenshot tool under ubuntu
Install nodejs and npm under Ubuntu 16.04
How to install Audacious under Ubuntu
How to install Tensorflow under ubuntu 16.04
Compile and install QEMU under Ubuntu
ubuntu18.04 install python2
ubuntu18.04 install docker
ubuntu12.04 install python3
Ubuntu install guide
ubuntu install nodejs
ubuntu 16 install asp.net
ubuntu install leanote
ubuntu install Jenkins
docker install ubuntu
ubuntu install elasticsearch
ubuntu16.0.1 install pagoda
ubuntu18.04 install python
ubuntu 18.04 install teamviewer
ubuntu install sendmail
Install linux (ubuntu) dual system under windows system
Install YouCompleteMe plugin for vim under Ubuntu
Install PyTesser under ubuntu 14.04 for OCR recognition
Install Ubuntu with Parallels Desktop under Mac
Three ways to install software under Ubuntu
Install utility software collection under Ubuntu system
install vscode on ubuntu18
How to install vim editor under Linux (Ubuntu 18.04)
Install mysql-pytho in Ubuntu
ubuntu install zsh terminal
Install Redis on Ubuntu
Install R4 on ubuntu20
Install nvtop on Ubuntu 18.04
Install postgresql-10 on Ubuntu 18.04
Install docker on Ubuntu
Install mysql5.7 under CentOS7
Ubuntu18.04 install opencv 3.2.0 solution
Install ActiveMQ under Centos7
Python MySQLd under Ubuntu
Install Docker on ubuntu18.04
Start working under ubuntu
Install nodejs10 on Ubuntu16
Install PostgreSQL12 under CentOS7
Install the old version of seurat under Ubuntu
Install CentOS under VMware