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.
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
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
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.
sed -i "s/www-data/USERNAME/g" /etc/apache2/envvars chown -R USERNAME:USERNAME /var/lib/php/
Create Apache VirtualHost entry
vi /etc/apache2/sites-available/DOMAIN.COM.conf
Add
ServerName DOMAIN.COM ServerAlias www.DOMAIN.COM ServerAdmin [email protected] DocumentRoot /home/DOMAIN.COM/html Options All AllowOverride All Require all granted Order allow,deny allow from all
To activate the web site, run
a2ensite DOMAIN.COM
Create document root and set permission
mkdir -p /home/DOMAIN.COM/html chown -R USERNAME:USERNAME /home/DOMAIN.COM/ chmod -R 755 /home/DOMAIN.COM/html/
Restart Apache
systemctl restart apache2
Create MySQL Database
Login to mysql, on ubuntu, as user root, run
mysql
Now you will be in MySQL command promt, run following 2 commands to create a Database and User.
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
wget https://raw.githubusercontent.com/serverok/server-setup/master/install/letsencrypt.sh bash ./letsencrypt.sh
To get SSL for your domain, run
certbot --authenticator webroot --webroot-path /home/DOMAIN.COM/html/ --installer apache --email [email protected] -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
ssh USER@SERVER_IP_ADDR
You will be asked to enter password. Enter password you created before.
Download wordpress
wget https://wordpress.org/latest.tar.gz
Extract wordpress files with
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
mv html html-old mv wordpress html
Now you can go to the site, you will see wordpress install screen.
See WordPress