Apache is a powerful Web server. Nowadays, countless Apache servers running on Linux on the Internet are providing powerful support for the increasingly prosperous Web world. This article will show you how to quickly build an ApacheWeb server in the UbuntuLinux system. Although Ubuntu is a new Linux branch, the Ubuntu Organization provides a wide range of support software for Apache. These software can be obtained from the CD of the release version, or from the official site.
Apache is a powerful Web server. Nowadays, countless Apache servers running on Linux on the Internet are providing powerful support for the increasingly prosperous Web world. This article will show you how to quickly build an Apache Web server in Ubuntu Linux.
Although Ubuntu is a new Linux branch, the Ubuntu Organization provides a wide range of support software for Apache, which can be obtained from the CD of the release version, it can also be easily downloaded from the official site. Therefore, Ubuntu is very suitable for serving as a Web server platform.
1. install Apache
Next, we will first introduce how to install Apache. The installation command is as follows:
$ sudo apt-get install apache2
|
Run Apache and the command is as follows:
$ sudo /etc/init.d/apache2 restart
|
During installation, Apache creates a directory:/var/www, which is the root directory for storing documents on the server. You only need to enter http: // localhost/or the IP address of the machine in the address bar of the browser to access all documents placed in this directory.
Ii. install PHP
PHP is a popular server-side scripting language. It is generally used in combination with MySQL or Postgres to manage Web content, blogs, and forums. The following describes the installation method. In fact, the installation is very simple. The command is as follows:
$ sudo apt-get install libapache2-mod-php5
|
Restart Apache to load the modules installed above:
$ sudo /etc/init.d/apache2 restart
|
To verify that the PHP module is correctly loaded, we can create a PHP file and try to access the file through the Web server. In addition, we know that PHP has a built-in phpinfo function that provides detailed information about its environment. Therefore, we can also use the following command to check the working status of PHP:
sudo sh -c "echo '
' > /var/www/info.php"
|
Then, enter http: // localhost/info. php in the address bar of the browser, and press Enter. Then, you will be able to see a face and provide the PHP installation details. Note that if the browser prompts you to download the file instead of displaying the page during this process, Apache does not properly load the PHP module. To solve the problem, add the following command in the/etc/apache2/apache2.conf or/etc/apache2/mod-enabled/php5.conf file:
AddType application/x-httpd-php .php .phtml .php3
|
After adding the preceding command line, to ensure that Apache re-reads the configuration file and closes it, we can use the following command to close it and then start it:
$ sudo /etc/init.d/apache2 stop
$ sudo /etc/init.d/apache2 start
|