Ubuntu Apache Setup for WordPress
On a Fresh Ubuntu 18.04 server, run following commands to setup Apache, PHP and MySQL needed for WordPress installation.
You can go to each file and manually run the commands if you want to see what commands are executed.
1 2 3 4 5 6 |
wget https://raw.githubusercontent.com/serverok/server-setup/master/ubuntu/1-basic-tools.sh wget https://raw.githubusercontent.com/serverok/server-setup/master/ubuntu/2-apache-php-mysql.sh wget https://raw.githubusercontent.com/serverok/server-setup/master/install/update-php-ini.sh bash ./1-basic-tools.sh bash ./2-apache-php-mysql.sh bash ./update-php-ini.sh |
At this stage, you have LAMP server setup and ready to go.
To get your domain work with Apache, first you need to point your domain to server IP. This can be done by editing DNS records with your domain registrar or DNS provider.
In commands below, replace
DOMAIN.COM = replace with your actual domain name
USERNAME = you can use any username you wnat, first 8 chars of domain name for example
Create SFTP User
1 2 |
useradd -m --shell /bin/bash --home /home/DOMAIN.COM USERNAME usermod -aG sudo USERNAME |
Set a password for the user. This will be used to login to SFTP
1 |
passwd USERNAME |
You will be asked to enter password 2 times.
Configure Apache
First lets make Apache run as the user, this will make WordPress upgrade easier.
1 2 |
sed -i "s/www-data/USERNAME/g" /etc/apache2/envvars chown -R USERNAME:USERNAME /var/lib/php/ |
Create Apache VirtualHost entry
1 |
vi /etc/apache2/sites-available/DOMAIN.COM.conf |
Add
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<VirtualHost *:80> ServerName DOMAIN.COM ServerAlias www.DOMAIN.COM ServerAdmin info@DOMAIN.COM DocumentRoot /home/DOMAIN.COM/html <Directory "/home/DOMAIN.COM/html"> Options All AllowOverride All Require all granted Order allow,deny allow from all </Directory> </VirtualHost> |
To activate the web site, run
1 |
a2ensite DOMAIN.COM |
Create document root and set permission
1 2 3 |
mkdir -p /home/DOMAIN.COM/html chown -R USERNAME:USERNAME /home/DOMAIN.COM/ chmod -R 755 /home/DOMAIN.COM/html/ |
Restart Apache
1 |
systemctl restart apache2 |
Create MySQL Database
Login to mysql, on ubuntu, as user root, run
1 |
mysql |
Now you will be in MySQL command promt, run following 2 commands to create a Database and User.
1 2 |
create database DB_NAME; grant all on DB_NAME.* to 'DB_USER'@'localhost' identified by 'MYSQL_PASSWORD'; |
Replace MYSQL_PASSWORD with your own MySQL password. DB_NAME with name of database you need. DB_USER with username for the db.
You will need these when installing WordPress.
Installing LetsEncrypt
First install letsEncrypt with
1 2 |
wget https://raw.githubusercontent.com/serverok/server-setup/master/install/letsencrypt.sh bash ./letsencrypt.sh |
To get SSL for your domain, run
1 |
certbot --authenticator webroot --webroot-path /home/DOMAIN.COM/html/ --installer apache --email admin@DOMAIN.COM -d DOMAIN.COM -d www.DOMAIN.COM |
Replace [email protected] with your actual email address.
Installing WordPress
You can now SFTP/SSH into the server. Upload WordPress into html folder. Make sure you use the newly created USER to do this, if you do it as user root, you will get permission error. Visit the web site, you wil get WordPress install wizzard. Just fill the form to do the install. You will need to enter MySQL login details you created before.
Install WordPress using SSH
First login with SSH user you created with command
1 |
ssh USER@SERVER_IP_ADDR |
You will be asked to enter password. Enter password you created before.
Download wordpress
1 |
wget https://wordpress.org/latest.tar.gz |
Extract wordpress files with
1 |
tar xvf latest.tar.gz |
This will create a folder “wordpress” with the files.
To make the site live, we need to replace folder html with this new wordpress folder
1 2 |
mv html html-old mv wordpress html |
Now you can go to the site, you will see wordpress install screen.
See WordPress