Apache2 HTTP server is the most popular webserver in used today. It powers a lot of the websites you visit online. This brief tutorial shows students and new users how to install Apache2 webserver on Ubuntu. Install Apache With SSL in Ubuntu 13.10. M.el Khamlichi - October 23, 2013. Install apache. Sudo apt-get install apache2 apache2-doc apache2-utils Reading package lists. Done Building dependency tree Reading state information. Done The following extra packages will be installed: apache2-bin apache2-data libapr1 libaprutil1.
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:
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.
Configuring Apache
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.html and place it in the public_html folder.
Open a terminal and type:
Change DocumentRoot /var/www
to DocumentRoot /home/user/public_html
.
Change <Directory /var/www/>
to <Directory /home/user/public_html/>
.
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 DocumentRoot /var/www
to 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
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 “<Directory /home/user/public_html/>
“. Underneath that line of code, change AllowOverride None
to AllowOverride All
.
Save and exit the file.
Recommended read:
1. Install LAMP server in Ubuntu
2. How to install VLC-Shares in Ubuntu and stream audio/video to Android
Ebooks
This brief tutorial shows students and new users how to install WordPress CMS on Ubuntu 16.04 / 17.10 and 18.04 LTS with Apache2, MariaDB and PHP 7.2 support with Let’s Encrypt free SSL/TLS enabled… {LAMP + Let’s Encrypt}
This setup will probably be how all WordPress sites will be configured going forward, since Google is strongly encouraging website owners to use SSL/TLS encryption for all web pages..
Also, WordPress is PHP 7.2 compatible.. so why not use the latest PHP? However, before using PHP 7.2, make sure all your plugins and themes are compatible or you’ll seriously run into issues..
When you’re ready to get WordPress working, continue with the steps below:
Step 1: Install Apache2 HTTP Server on Ubuntu
Apache2 HTTP Server represents the A in the LAMP stack… It’s the most popular web server in use… so install it, since WordPress needs it..
To install Apache2 HTTP on Ubuntu server, run the commands below…
After installing Apache2, the commands below can be used to stop, start and enable Apache2 service to always start up with the server boots.
To test Apache2 setup, open your browser and browse to the server hostname or IP address and you should see Apache2 default test page as shown below.. When you see that, then Apache2 is working as expected..
http://localhost
Step 2: Install MariaDB Database Server
MariaDB database server is a great place to start when looking at open source database server to use with WordPress… To install MariaDB run the commands below…
sudo apt-get install mariadb-server mariadb-client
After installing MariaDB, the commands below can be used to stop, start and enable MariaDB service to always start up when the server boots..
Run these on Ubuntu 16.04 LTS
Run these on Ubuntu 17.10 and 18.04 LTS
After that, run the commands below to secure MariaDB server by creating a root password and disallowing remote root access.
sudo mysql_secure_installation
When prompted, answer the questions below by following the guide.
- Enter current password for root (enter for none): Just press the Enter
- Set root password? [Y/n]: Y
- New password: Enter password
- Re-enter new password: Repeat password
- Remove anonymous users? [Y/n]: Y
- Disallow root login remotely? [Y/n]: Y
- Remove test database and access to it? [Y/n]: Y
- Reload privilege tables now? [Y/n]: Y
Restart MariaDB server
To test if MariaDB is installed, type the commands below to logon to MariaDB server
sudo mysql -u root -p
Then type the password you created above to sign on… if successful, you should see MariaDB welcome message
Step 3: Install PHP 7.2 and Related Modules
PHP 7.2 isn’t available on Ubuntu default repositories… in order to install it, you will have to get it from third-party repositories.
Run the commands below to add the below third party repository to upgrade to PHP 7.2
Then update and upgrade to PHP 7.2
Install Ubuntu On Windows 10
sudo apt update
Next, run the commands below to install PHP 7.2 and related modules.
sudo apt install php7.2 libapache2-mod-php7.2 php7.2-common php7.2-mbstring php7.2-xmlrpc php7.2-soap php7.2-gd php7.2-xml php7.2-intl php7.2-mysql php7.2-cli php7.2-zip php7.2-curl
After installing PHP 7.2, run the commands below to open PHP default config file for Apache2…
Then make the changes on the following lines below in the file and save. The value below are great settings to apply in your environments.
After making the change above, save the file and close out.
Step 4: Restart Apache2
After installing PHP and related modules, all you have to do is restart Apache2 to reload PHP configurations…
To restart Apache2, run the commands below
sudo systemctl restart apache2.service
To test PHP 7.2 settings with Apache2, create a phpinfo.php file in Apache2 root directory by running the commands below
sudo nano /var/www/html/phpinfo.php
Then type the content below and save the file.
<?php phpinfo( ); ?>
Save the file.. then browse to your server hostname followed by /phpinfo.php
http://localhost/phpinfo.php
You should see PHP default test page…
Step 5: Create WordPress Database
Now that you’ve installed all the packages that are required for WordPress to work, continue below to start configuring the servers. First run the commands below to create a blank WordPress database.
To logon to MariaDB database server, run the commands below.
sudo mysql -u root -p
Then create a database called wpdb
CREATE DATABASE wpdb;
Create a database user called wpuser with new password
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'new_password_here';
Then grant the user full access to the database.
GRANT ALL ON wpdb.* TO 'wpuser'@'localhost' IDENTIFIED BY 'user_password_here' WITH GRANT OPTION;
Finally, save your changes and exit.
Step 6: Download WordPress Latest Release
Next, visit WordPress site and download the latest version….
After downloading, run the commands below to extract the downloaded file and move it into a new WordPress root directory.
Then run the commands below to set the correct permissions for WordPress direcotories.
Step 7: Configure Apache2 HTTP Server
Next, configure Apache2 site configuration file for WordPress. This file will control how users access WordPress content. Run the commands below to create a new configuration file called wordpress.conf
sudo nano /etc/apache2/sites-available/wordpress.conf
Then copy and paste the content below into the file and save it. Replace the highlighted line with your own domain name and directory root location.
Save the file and exit.
Step 8: Enable the WordPress Site and Rewrite Module
After configuring the VirtualHost above, enable it by running the commands below, then restart Apache2 server…
STEP 9: CONFIGURE WORDPRESS
Now that Apache2 is configured, run the commands below to create WordPress wp-config.php file.
sudo mv /var/www/html/wordpress/wp-config-sample.php /var/www/html/wordpress/wp-config.php
Then run the commands below to open WordPress configuration file.
sudo nano /var/www/html/wordpress/wp-config.php
Enter the highlighted text below that you created for your database and save.
Step 10: Install Let’s Encrypt Client
To get Let’s Encrypt free SSL/TLS certificates on your Ubuntu machine, you should first install its client. The client helps automate the process for you. To install it, run the commands below.
sudo apt-get install python-certbot-apache
Step 11: Obtaining your free SSL/TLS Certificates
After installing Let’s Encrypt Certbot client module for Apache2, run the commands below to obtain your free Let’s Encrypt SSL/TLS certificate the domain specified… make sure to replace example.com with your own domain..
sudo certbot --apache -m admin@example.com -d example.com -d www.example.com
After running the above commands, you should get prompted to accept the licensing terms. If everything is checked, the client should automatically install the free SSL/TLS certificate and configure the Apache2 site to use the certs.
Choose Yes ( Y ) to share your email address
This is how easy is it to obtain your free SSL/TLS certificate for your Apache2 powered website.
Pick option 2 to redirect all traffic over HTTPS. This is important!
After that, the SSL client should install the cert and configure your website to redirect all traffic over HTTPS.
The highlighted code block should be added to your Apache2 WordPress configuration file automatically by Let’s Encrypt certbot. Your WordPress site is ready to be used over HTTPS.
A new configuration file for the domain should also be created named /etc/apache2/sites-available/example.com-le-ssl.conf. This is Apache2 SSL module configuration file and should contain the certificate definitions defined in it.
Ubuntu 10 10 Download
You’ll have to manually renew the certificates. You’ll get email reminder to reset when the certificates are about to expire. To test the renewal process run the commands below.
Ubuntu 10.10 Iso
sudo certbot renew --dry-run
To setup a process to automatically renew the certificates, add a cron job to execute the renewal process.
sudo crontab -e
Then add the line below and save.
0 1 * * * /usr/bin/certbot renew & > /dev/null
Install Apache For Ubuntu 10.10 Usb
The cron job will attempt to renew 30 days before expiring
After that, open your browser and browse to your domain name to launch WordPress configuration wizard.
You should see WordPress setup wizard to complete. Please follow the wizard carefully.
https://example.com
Then type the WordPress website name and create a new admin user and password.. the click install.
This should install WordPress.
Congratulations! You’ve successfully installed WordPress on Ubuntu with Apache2, MariaDB, PHP 7.2 with Let’s Encrypt free SSL/TLS certificates
Install Apache Ubuntu 18
You may also like the post below: