LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Blogs > beachboy2
User Name
Password

Notices


Rate this Entry

Installing WordPress on a Linux (LAMP) Server

Posted 03-16-2017 at 10:15 AM by beachboy2
Updated 04-18-2020 at 09:46 AM by beachboy2 (Adding screenshots)

Plan:
Install an Apache2 web server on Linux with PHP 7.0 (mod_php) and MySQL support. Then install WordPress and create your own website or blog, either just for testing/learning, or live transmission via a web host.

LAMP
is short for Linux, Apache, *MySQL, PHP.
A LAMP setup is perfect for a Content Managed System like Wordpress:
https://codex.wordpress.org/

(*Alternatively, you can use MariaDB from the original developers of MySQL. It is guaranteed to stay open source).

It is a good idea to test your WordPress website locally, using localhost (http:/127.0.0.1), before uploading it later to your live server, hopefully without any errors, bugs or security flaws.

To move your website later, I recommend Method 2 on “How To Move Your WordPress Website From localhost To Live Server”:
http://www.wpexplorer.com/wordpress-local-to-live/

You may prefer to just run a WordPress “test” website on a LAMP server using a spare PC/laptop via localhost and never actually go “live” on a hosted production server.

I first installed Linux Mint 18.1 MATE as the base Linux distribution, as opposed to Ubuntu Server 16.04.2, CentOS or Debian etc. The choice is entirely yours.

Install Apache


To install Apache, enter:

Code:
sudo apt-get install apache2
Enable and start your apache (as root):

Code:
sudo su
systemctl enable apache2
systemctl start apache2
systemctl status apache2
Test Apache:

Open your web browser and navigate to http://localhost/ (localhost is http:/127.0.0.1)

Install MySQL (or MariaDB):

Code:
sudo apt-get install mysql-server mysql-client
During installation, you will be asked to setup the MySQL “root” user password. Enter the password myrooting874tootING?! and click OK. Repeat.

MySQL is being installed now.

You can verify the MySQL server status using command:

Code:
sudo systemctl status mysql
Next, harden the security on MySQL using the following configuration script:

Code:
sudo /usr/bin/mysql_secure_installation
Apart from the current root password, which is retained, select Y (Yes) to everything else.

Install PHP 7.0

Install PHP with following commands:

Code:
sudo apt-get update 
sudo apt-get install php7.0-mysql php7.0-curl php7.0-json php7.0-cgi php7.0 libapache2-mod-php7.0
sudo apt-get install php-mbstring php7.0-mbstring php-gettext
Restart apache2:

Code:
sudo systemctl restart apache2
Then test your php:

To test PHP, create a sample “testing.php” file in the Apache document root folder, which is: /var/www/html

Code:
sudo nano /var/www/html/testing.php
Copy and paste the following lines to the file:

Code:
<?php
phpinfo();
?>
Save the changes by using Ctrl+O, then press Enter. Exit using Ctrl+X.

Restart apache2 service:

Code:
sudo systemctl restart apache2
Navigate to http://localhost/testing.php

It will display all the details about php such as version, build date and commands etc.
Next, for security, remove the “testing.php” file:

Code:
sudo rm -f /var/www/html/testing.php
Install phpMyAdmin

Code:
sudo apt-get install phpmyadmin
Select the web server that should be automatically configured to run phpMyAdmin. In my case, it is apache2.

Use the spacebar to insert * inside brackets for apache2, press Tab and Enter. Ignore lighttpd.

The phpMyAdmin must have a database installed and configured before it can be used. This can be optionally handled by dbconfig-common.

Select ‘Yes’ to configure database for phpmyadmin with dbconfig-common.

Enter MySQL application password (rarely used) for phpmyadmin: somethingorother
(NOT myrooting874tootING?! which is the root MySQL password).
Re-enter password.

Success! phpMyAdmin installation is installed.

If you followed all steps carefully, phpMyAdmin should work just fine.
In case phpMyAdmin is not working, please do the following:
Open terminal, and type:

Code:
sudo nano /etc/apache2/apache2.conf
Add the following line at the end:
Code:
Include /etc/phpmyadmin/apache.conf
Save and Exit.

Restart apache service:
Code:
sudo systemctl restart apache2
Access phpMyAdmin Web Console

Navigate to:
http://localhost/phpmyadmin/ from your browser.

Enter your MySQL username and password which you have given in previous steps. In this case: root and myrooting874tootING?!

You will be redirected to phpMyAdmin main web interface.
From here, you can manage your MySQL databases from phpMyAdmin web interface.
Your LAMP stack is ready to use.
.......................................................................................
Wordpress Database Initialisation

NB wp-config is located at: /var/www/html/wordpress/wp-config.php

Create the database for Wordpress as follows:

Login to the MySQL database as root user:

Code:
sudo mysql -u root -p
Type the MySQL root password myrooting874tootING?! and press Enter.

At the mysql > prompt create a database with:

Name: fredjdb
Database user: fredj and the
Database password: amotv769TZG?$

THIS IS STEP 2 (referred to later when installing WordPress).

At the mysql > prompt, enter the following 3 lines separately, including the semi-colon (;) at the end. Press Enter after adding each line:

Code:
CREATE DATABASE fredjdb;
CREATE USER fredj@localhost IDENTIFIED BY 'amotv769TZG?$';
GRANT ALL PRIVILEGES ON fredjdb.* TO fredj@localhost;
Then exit the MySQL shell using the following commands and pressing Enter:

Code:
FLUSH PRIVILEGES;
exit
Next, restart services using:

Code:
sudo systemctl restart apache2
sudo systemctl restart mysql
Install WordPress

Go to: https://wordpress.org/download/
Download wordpress-4.7.3.gz to Desktop and then extract the wordpress folder:

Code:
cd Desktop           
tar zxf wordpress-4.7.3.tar.gz
Move the extracted wordpress folder on Desktop to /var/www/html/ using:

Code:
sudo mv /home/fred/Desktop/wordpress/ /var/www/html/
Now DELETE index.html.

If both index.html and index.php are present, index.html loads first overriding the index.php file:
Remove the index.html file from the html folder containing wordpress:

Code:
sudo rm -r /var/www/html/index.html
Now set appropriate permissions for the wordpress directory. NB You MUST be root user to do this!

Code:
sudo su
chown -R www-data:www-data /var/www/html/wordpress
chmod -R 755 /var/www/html/wordpress
Next, create the uploads directory beneath the wp-content directory at our document root. This (wp-content) will be the parent directory of our content:

Code:
sudo mkdir -p /var/www/html/wordpress/wp-content/uploads
We need to allow the web server itself to write to this directory. We can do this by assigning user and group ownership of this directory to our web server user www-data.

This will allow the web server to create files and directories under this directory, which will permit us to upload content to the server.
Proceed like this, as root user:

Code:
sudo su
chown -R www-data:www-data /var/www/html/wordpress/wp-content/uploads
Now proceed to the web installation of Wordpress.

Go to the URL http://localhost/wordpress/ in your web browser. The WordPress installer will show up.

Select English language and press Continue:

The Welcome screen shows up in the selected language. Click on Let's go and type in the Login details of the WordPress database that was created in STEP 2 previously.

The database host is "localhost" and the prefix can be left at its default. Then click on the "Submit" button.

Wordpress saves the database configuration details to the file:
/var/www/html/wordpress/wp-config.php

Click on "Run the install" to proceed to the next part of the installer.

Now enter some details for the Blog like website title, admin username, password and email address.

Site Title = Fred’s Blog
Admin Email = fred@some_email_address
Username = Fred
Admin password = wqm97168LV

Press InstallWordpress to finish the installation.

Next, access the login page by pressing LogIn:

Type in the credentials that you selected during WordPress installation above. The WordPress Dashboard will then appear.

Later, access your live WordPress website via:

http://YOUR-IP-ADDRESS/wp-admin
............................................................................................
For Reference

Code:
sudo systemctl start apache2
sudo systemctl start mysql
WP LOGIN: localhost/wordpress/wp-login.php

Welcome page: localhost/wordpress/index.php/welcome/
............................................................................................

Useful links (thanks to all, especially Till Brehm on HowToForge)

MariaDB:
https://mariadb.org/

WordPress:
https://codex.wordpress.org/

Ubuntu Server guides:
https://help.ubuntu.com/lts/serverguide/
https://help.ubuntu.com/lts/servergu...-overview.html

Wplift Guide:
https://wplift.com/install-wordpress-in-ubuntu

Unixmen:
http://www.unixmen.com/how-to-instal...-ubuntu-16-04/

How to Forge:
https://www.howtoforge.com/tutorial/...tu-16-04-lamp/

Ubuntu Desktop LAMP Development server:
https://www.jackreichert.com/2014/08...opment-server/

Hardening WordPress Security:
https://codex.wordpress.org/Hardening_WordPress

MySQL Security (very important):
http://howtolamp.com/lamp/mysql/5.6/securing/

Installing LAMP from source code:
http://howtolamp.com/lamp/

LAMP Server with WordPress (Raspberry Pi):
https://www.raspberrypi.org/learning...ess/worksheet/

How To Move Your WordPress Website From localhost To Live Server:
http://www.wpexplorer.com/wordpress-local-to-live/

Useful WordPress Plugins

BackWPup:
https://en-gb.wordpress.org/plugins/backwpup/

Akismet Anti-Spam:
https://en-gb.wordpress.org/plugins/akismet/

PDF Embedder:
https://en-gb.wordpress.org/plugins/pdf-embedder/

Easy Updates Manager:
https://en-gb.wordpress.org/plugins/...lugin-updates/

Gallery Manager:
https://wordpress.org/plugins/fancy-gallery/
.........................................................................................
Attached Images
File Type: png Apache2.png (179.0 KB, 4 views)
File Type: png PHP Version 7.0.18.png (180.5 KB, 3 views)
File Type: png phpMyAdmin.png (162.4 KB, 3 views)
File Type: png WordPress-Lets go!.png (99.2 KB, 3 views)
File Type: png WordPress Dashboard.png (172.9 KB, 5 views)
Posted in Uncategorized
Views 6042 Comments 1
« Prev     Main     Next »
Total Comments 1

Comments

  1. Old Comment
    Useful WordPress Plugins: wordfence

    Good Job!
    Posted 03-16-2017 at 11:26 AM by Habitual Habitual is offline
 

  



All times are GMT -5. The time now is 01:27 AM.

Main Menu
Advertisement
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration