I had hosted my WordPress websites on the shared hosting plan for years and finally made the change a few months back. The result, I will never look back. And that’s why I decided to post a series of posts to record this transition and hope to help anyone who came across wishing to do the same.
First one up, the steps to take to install the latest WordPress on Ubuntu 16.04.
Basically, you need have two things ready before starting on any real work.
$ adduser edge $ usermode -aG sudo edge
A “LAMP” stack is a group of open source software that is typically installed together to enable a server to host dynamic websites and web apps. The term is an acronym that represents:
We’ve already got the letter “L” taken care of. Now, let’s go after the rest. We will be using Ubuntu’s package manager, apt, to do the work.
$ sudo apt-get update $ sudo apt-get install apache2
The commands will be executed with root privileges because of the sudo we are using here. Depends on the setup, it may ask you your user password to proceed.
You can do a quick check to verify if it works by visiting your server’s public IP address in a web browser on your own computer.
http://your_server_IP/
If everything works as planned, the Apache2 Ubuntu Default Page opens up.
$ sudo apt-get install mysql-server
You will see a list of packages that will be installed during this installation. Answer Y to continue.
You will be prompted to select and confirm a password for the MySQL “root” user. Make sure you choose a strong password and don’t leave it blank.
You will also need to run a simple security script that will remove some dangerous defaults and lock down the access to the database system.
$ sudo mysql_secure_installation
Along the way, you will be asked if you want to enable and configure the Validate Password Plugin. It’s totally optional. When enabled, passwords that don’t match the specified criteria will be rejected by MySQL. It’s safe to leave the plugin disabled. Just to make sure you always use a strong password for database credentials.
$ sudo apt-get install php7.0 php7.0-mysql libapache2-mod-php7.0 php7.0-mcrypt $ sudo apt-get install php7.0-curl php7.0-gd php7.0-mbstring php7.0-cli php7.0-cgi php7.0-xml php7.0-xmlrpc
You may not need all these php7 packages installed. Depending on the WordPress plugins you will be using, you may need fewer or more.
You also need to modify Apache configuration so it can recognize PHP’s default home page file, index.php.
$ sudo nano /etc/apache2/mods-enabled/dir.conf
And add index.php in the line. Save and close the file by pressing Ctrl+X.
Restart the Apache2 service, and it’s ready to go.
$ sudo service apache2 restart
Before moving forward, let’s test your server to see if it’s configured properly.
The default Apache web directory in Ubuntu is located at
/var/www/html
Let’s create a file called info.php in that directory by typing:
$ sudo nano /var/www/html/info.php
with the following content:
<?php phpinfo(); ?>
Now you can test it out by visiting the following.
http://your_server_IP/info.php
If you see this page showing up, your PHP is working as expected. Now, let’s remove it.
$ sudo rm /var/www/html/info.php
Here are the things you need to do to getting a WordPress instance set up on a LAMP stack.
Now let’s dive in.
To get started, log into MySQL root account by
$ mysql -u root -p
Enter the password for the root account, and you are in MySQL environment.
First, let’s create a database that will be used for WordPress site. Naming isn’t important, as long as it can be easily remembered.
Then, create a separate user account so you can use that account exclusively operate the database and grant that user account’s access to the database you just created.
mysql> create database dbname; mysql> create user username@localhost identified by 'password' password expire never; mysql> grant all privileges on dbname.* to username@localhost; mysql> flush privileges; mysql> exit;
With the proper setup, you can host multiple sites within one VPS. And that’s the beauty of the concept of the virtual host. Here are steps to take.
Create a subfolder for the virtual host.
$> sudo mkdir /var/www/site-name
Navigate to the folder that hosts all the virtual host configuration files and make a copy of the default one for your own host.
$> cd /etc/apache2/sites-available
$> sudo cp 000-default.conf site-name.conf
Then update the host configuration file.
$> sudo nano site-name.conf
Basically, there are four things to change in the file here:
ServerAdmin your_email_address ServerName site-name.com ServerAlias www.site-name.com DocumentRoot /var/www/site-name
Once done, enable the virtual host and restart the Apache service.
$> sudo a2ensite site-name $> service apache2 restart
Download the latest WordPress package from WordPress website and extract it to the user profile folder.
$> wget http://wordpress.org/latest.tar.gz $> tar xzvf latest.tar.gz
Then sync the extracted WordPress files to the virtual host directory you created above.
$> sudo rsync -avP ~/wordpress/ /var/www/site-name
Now go to the /var/www/site-name folder, rename the existing wp-config-sample.php to wp-config.php.
$> sudo mv wp-config-sample.php wp-config.php
And update the wp-config.php with the database information under the MySQL settings section.
// ** MySQL settings - You can get this info from your web host ** // /** The name of the database for WordPress */ define('DB_NAME', 'database_name_here
'); /** MySQL database username */ define('DB_USER', 'username_here
'); /** MySQL database password */ define('DB_PASSWORD', 'password_here
'); /** MySQL hostname */ define('DB_HOST', 'localhost
'); /** Database Charset to use in creating database tables. */ define('DB_CHARSET', 'utf8
'); /** The Database Collate type. Don't change this if in doubt. */ define('DB_COLLATE',''
);
Open your web browser, go to site address like below and complete the installation through the web interface.
http://site_domain_or_IP
Once it’s done, log back into the server and apply the proper access rights to the site directory.
$> sudo chown -R www-data:www-data /var/www/site-name
That’s all to get everything started…until next time.
If using Copilot right from the Taskbar isn't your thing, you should disable it. Even…
In an environment where standardizing things does matter, setting default fonts in Microsoft Office apps…
Wake-On-LAN is a networking standard that lets you wake up a computer from either a…
First of all, this is not to bypass a PDF file that requires a password…
Microsoft has been lurking about the idea of placing the Outlook navigation bar to the…
One colleague came up to me the other day asking me to take look at…
View Comments
Excellent tutorial on building a LAMP stack for WordPress! Still, if you've got multiple servers to set up, you can save yourself so much time by using a service like ServerPilot and its one-click WordPress installer. All you have to do is connect a clean Ubuntu 16.04 server to ServerPilot, complete a quick form, and let ServerPilot do the rest. It'll even manage all the package updates and security patches for you. Check it out at https://serverpilot.io.