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