How can I install Apache2, php, mysql and set it up with virtual hosts and preferably Let's Encrypt SSL certificate, and then proceed to install Wordpress on it?
How can I install Apache2, php, mysql and set it up with virtual hosts and preferably Let's Encrypt SSL certificate, and then proceed to install Wordpress on it?
I assume that you have a running Ubuntu installation. This is written with 16.04 in mind but should work with some adaptions on other versions as well.
In this answers,
#
denotes a root shell, whilst$
denotes a normal user shell.example.org is used as an example (D'oh) in this answer, and should be changed to suit your installation.
Installing Apache2, PHP, MariaDB and so forth
This will install Apache2, PHP, MariaDB, and some dependencies, in addition to PHP bindings for accessing mysql.
At this stage, you should be able to access http://example.org, and see a default page:
Setting up a vhost
Vhosts are virtual hosts, which is used to serve different content for different domain names.
Start editing a new file called
/etc/apache2/sites-available/01-example.org.conf
in your favorite editor:Enter the following configuration:
First, we define the primary ServerName. This is the domain used to access the site. Only one can be defined per vhost. In addition, we define a ServerAlias, in case someone enters www.example.org in their browser. This ensures that Apache replies to both names. Both names has to point to your server, either in DNS, or in
/etc/hosts
for local testing.Any number of server aliases can be specified, and they do not have to contain parts of the ServerName. Thus,
ServerAlias example.com
would be valid.Create the new DocumentRoot
I've placed the new documentroot in
/var/www/html/example.org
. This is a location that is allowed to be served by Apache in Ubuntu. If I, for instance, placed it in/srv/
, I would have to include a Directory stanza for it. For now, create the webroot, fill it with some content, and activate the new config:If you now visit http://example.org, you should see the output *This is a test". Congratulations! Your first vhost is running!
Install letsencrypt and grab certificates
To receive certificates from Let's Encrypt, we need a client. The letsencrypt package included with 16.04 is ancient, so we need a ppa for this.
Run certbot as root:
Select the domain you want to get a certificate for and follow the on-screen instructions by certbot. When asked if you want to redirect, select redirect if you want https only, and no redirect if you want both http and https. Today, there's almost no reason to not redirect.
Try visiting http://example.com again - it should change to show that it is secure.
Congratulations, you have not set up apache2 with a valid TLS certificate that ensures traffic is encrypted!
Install WordPress
Next step is to install some application. I've picked WordPress as example to install.
First become root by entering
sudo -i
. Next, change directory to your webroot, and download, unpack and change ownership to Apache's user:You will now have a WordPress instance at https://example.com/wordpress/ - let's go there.
The wizard tells you that you need a MySQL table, user, and password. Let's make them!
By default, Ubuntu will use unix socket authentication for MariaDB. Thus, to log in to MariaDB as root, you have to use
or run the command in a root shell (for instance
sudo -i
). This will log you in without entering any passwordFill in the username
wordpress_user
, databasenamewordpress_db
and passwordpassw0rd
in WordPress' configuration. That's basically it; the rest is about following WordPress' installation guidelines.To add more vhosts, simply start from "Setting up a vhost".
Further reading
/var/www/html
Install Apache In Ubuntu
Check Apache Server You can check your apache server is properly working or not via your IP. Enter in your Browser
http://server_domain_or_IP
You will find the Default page.
Mange Apache Process