How to Install And Configure Apache In Ubuntu
2013-10-15 13:29
731 查看
http://www.maketecheasier.com/install-and-configure-apache-in-ubuntu/
If you intend to set
up a web server (or streaming server) in your Ubuntu machine, apache is one important module that you must install. In this tutorial, we will show you how to install and configure apache for your Ubuntu.
Note: If you just want to have a quick setup of LAMP server, follow
the guide here.
Getting apache onto your Ubuntu machine is easy. Using either the Synaptic Package Manager, Ubuntu Software Center, search and install the “apache2” module. Alternatively, you can open a terminal and type the following command:
Once the installation finished, open a browser and go to the URL “http://localhost“.
If you see the word “It Works!“, then your installation of apache is successful.
Start, Stop and Restart Apache
After you have installed Apache, it will be added to the init.d list and will auto start whenever you boot up your computer. The following commands allow you to start, restart, stop Apache.
To prevent Apache from autostart when booting up:
To restore Apache back to the autostart list:
Note: the above commands will work in debian-based distro (including Ubuntu) only.
Changing the default localhost folder
By default, apache will operate on the “/var/www” folder. This means that whatever files you place in this /var/www folder will be visible from the URL http://localhost.
In some instances, you may want the “localhost” to point to another folder instead, say /home/user/public_html. Here is how you do it:
First, make sure the /home/damien/public_html folder exists. Create a simple html file, name it index.htmland place it in the public_html folder.
Open a terminal and type:
Change
Change
Save and exit the file.
Restart the apache
Now, in your browser, reload the URL http://localhost.
You should see the html file that you have placed in the public_html folder.
Configuring different sites
The above trick allows you to change the default operating folder of apache, however, some of you might not want to override the default settings. An alternative is to create multiple sites and point apache to the active site.
Create a new settings file for your new site.
Next, edit this settings file.
Change
Change
Save and exit the file.
Disable the default setting and make active the site1 settings
Lastly, restart the apache.
With this trick, you can create multiple site configuration file, each pointing to a different folder. You can then easily switch between the sites with the a2dissite and a2ensite command
Enabling .htaccess file
.htaccess file is a powerful file that can be used to control and customize a site server behavior
without editing the core Apache module. By default, the .htaccess functionality is turned off and all instances of.htaccess files are completely ignored. The server will
not even attempt to read .htaccess files in the filesystem.
To enable .htaccess file, open up the settings file that you have created earlier:
Scroll down the file until you see the part “
Save and exit the file.
If you intend to set
up a web server (or streaming server) in your Ubuntu machine, apache is one important module that you must install. In this tutorial, we will show you how to install and configure apache for your Ubuntu.
Note: If you just want to have a quick setup of LAMP server, follow
the guide here.
Installing Apache
Getting apache onto your Ubuntu machine is easy. Using either the Synaptic Package Manager, Ubuntu Software Center, search and install the “apache2” module. Alternatively, you can open a terminal and type the following command:sudo apt-get install apache2 |
If you see the word “It Works!“, then your installation of apache is successful.
Configuring Apache
Start, Stop and Restart ApacheAfter you have installed Apache, it will be added to the init.d list and will auto start whenever you boot up your computer. The following commands allow you to start, restart, stop Apache.
sudo /etc/init.d/apache2 start #start apache sudo /etc/init.d/apache2 stop #stop apache sudo /etc/init.d/apache2 restart #restart apache |
sudo update-rc.d -f apache2 remove |
sudo update-rc.d apache2 defaults |
Changing the default localhost folder
By default, apache will operate on the “/var/www” folder. This means that whatever files you place in this /var/www folder will be visible from the URL http://localhost.
In some instances, you may want the “localhost” to point to another folder instead, say /home/user/public_html. Here is how you do it:
First, make sure the /home/damien/public_html folder exists. Create a simple html file, name it index.htmland place it in the public_html folder.
Open a terminal and type:
gksu gedit /etc/apache2/sites-enabled/000-default |
DocumentRoot /var/wwwto
DocumentRoot /home/user/public_html.
Change
<Directory /var/www/>to
<Directory /home/user/public_html/>.
Save and exit the file.
Restart the apache
sudo /etc/init.d/apache2 restart |
You should see the html file that you have placed in the public_html folder.
Configuring different sites
The above trick allows you to change the default operating folder of apache, however, some of you might not want to override the default settings. An alternative is to create multiple sites and point apache to the active site.
Create a new settings file for your new site.
sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/site1 |
gksu gedit /etc/apache2/sites-available/site1 |
DocumentRoot /var/wwwto
DocumentRoot /home/user/public_html.
Change
<Directory /var/www/>to
<Directory /home/user/public_html/>.
Save and exit the file.
Disable the default setting and make active the site1 settings
sudo a2dissite default && sudo a2ensite site1 |
sudo /etc/init.d/apache2 restart |
Enabling .htaccess file
.htaccess file is a powerful file that can be used to control and customize a site server behavior
without editing the core Apache module. By default, the .htaccess functionality is turned off and all instances of.htaccess files are completely ignored. The server will
not even attempt to read .htaccess files in the filesystem.
To enable .htaccess file, open up the settings file that you have created earlier:
gksu gedit /etc/apache2/sites-available/site1 |
<Directory /home/user/public_html/>“. Underneath that line of code, change
AllowOverride Noneto
AllowOverride All.
Save and exit the file.
相关文章推荐
- How To Configure Logging And Log Rotation In Apache On An Ubuntu VPS
- How to install and configure Apache, PHP, MySql and phpMyadmin on ubuntu
- How to install and configure Apache and PHP on ubuntu
- How to install and configure Apache, PHP, MySql and phpMyadmin on ubuntu
- How to install LAMP (Apache, PHP and MySQL in Linux) using Yum
- Howto Install and Configure PCL on Ubuntu
- How to Install Apache Tomcat 8 (on Windows, Mac OS X, Ubuntu) and Get Started with Java Servlet Prog
- how to install and configure Remote BLOB Storage (RBS) in a SharePoint 2013 farm
- how to install and configure snmp in freebsd
- How to Install and Configure Bind 9 (DNS Server) on Ubuntu / Debian System
- Howto Install and Configure Chinese Input Methods on Ubuntu
- How to Configure and Install ownCloud on Ubuntu 16.04
- How to Install and Configure VNC on Ubuntu 14.04
- Howto Install and Configure Doxygen for QtCreator on Ubuntu
- Howto Install and Configure VTK on Ubuntu
- Howto Install and Configure QtCreator on Ubuntu
- Howto Install and Configure ROS on Ubuntu
- How to install LAMP (Apache, PHP and MySQL in Linux) using Yum