LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Blogs > beachboy2
User Name
Password

Notices


Rate this Entry

Installing WordPress on a Linux (LAMP) Server-UPDATED 2023

Posted 04-22-2023 at 04:10 AM by beachboy2
Updated 04-22-2023 at 09:57 AM by beachboy2

Plan:
Install an Apache2 web server on Linux with PHP 8.1.2 and MySQL (or MariaDB) 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.
*Using MariaDB in this instance.

LAMP setup is perfect for a Content Managed System like WordPress:
https://codex.wordpress.org/

It is a good idea to test your WordPress website locally, using localhost http://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 using either the Duplicator plugin or doing it manually.

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 21 MATE as the base Linux distribution, as opposed to Ubuntu Server, CentOS or Debian etc. The choice is entirely yours.

START:

Code:
sudo apt update && sudo apt upgrade
Install Apache:

To install Apache, enter:

Code:
sudo https://linuxhint.com/install-wordpress-ubuntu-server/apt install apache2 apache2-utils
Enable and start apache (as root):

We need to enable the Apache2 web server to start at system boot time, as well as start the service and verify the status as follows:
Code:
$ sudo systemctl enable apache2
$ sudo systemctl start apache2
$ sudo systemctl status apache2

Test Apache
:
Open your web browser and navigate to http://localhost/

(localhost is http:/127.0.0.1)
.................................................................................................... ......................................................

Install MySQL:

Code:
sudo apt install mariadb-server mariadb-client

sudo systemctl enable --now mariadb

sudo systemctl start mariadb

sudo systemctl status mariadb

sudo mysql_secure_installation
NB When asked for the current password for the root user, just press Enter (blank password).
.................................................................................................... .......................................................

Full explanation:

In order to log into MariaDB to secure it, we need the current password for the root user. If you've just installed MariaDB, and you haven't set the root password yet, the password will be blank,so you should just press Enter here.

Enter current password for root (press Enter for none):

OK, successfully used password, moving on...
Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorisation.
You already have your root account protected, so you can safely answer 'n'.
Switch to unix_socket authentication [Y/n] n
... skipping.

Enter current password for root (Press Enter):

Change the root password? [Y/n] Y

New root password: acorn^^^***274JMZ?!

Re-enter new root password: acorn^^^***274JMZ?!

Remove anonymous users? [Y/n] Y

Disallow root login remotely? [Y/n] Y

Remove test database and access to it? [Y/n] Y

Reload privilege tables now? [Y/n] Y

All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.

If all is well, you should see the following message:
Thanks for using MariaDB!
.................................................................................................... ......................................................

Next, create a WordPress database to store the details of the users and WordPress.

Login to the MySQL database as root user:

Code:
sudo mysql -u root -p
Type the MySQL root password acorn^^^***274JMZ?! and press Enter.

At the mysql > prompt create a database with:

Name: frankdb

Database user: frank
and the
Database password: tjh$^854TZG?*

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 frankdb;

CREATE USER frank@localhost IDENTIFIED BY 'tjh$^854TZG?*';

GRANT ALL PRIVILEGES ON frankdb.* TO frank@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 PHP 8.1.2

Install PHP with following commands:

Code:
sudo apt update
sudo apt install -y php php-{common,mysql,xml,xmlrpc,curl,gd,imagick,cli,dev,imap,mbstring,opcache,soap,zip,intl}
Confirm installation and PHP version:
Code:
php –version
Version was 8.1.2

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 gedit /var/www/html/testing.php
VERY IMPORTANT: Copy and paste the following lines to the file, NOTING THAT PPP must be replaced by php.

The reason I had to do this was because almost every time I mentioned php, Cloudflare web security would automatically block my blog post, so do be warned if you have a similar problem in the future!

PHP Code:
<?PPP
PPPinfo
();
?>
Save & close file.

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 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:
bgtPQJ5539^$ (NOT acorn^^^***274JMZ?! which is the root MySQL password).

Re-enter application 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:

Code:
sudo gedit /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 acorn^^^***274JMZ?!

You will be redirected to phpMyAdmin main web interface. IT WORKS!!

From here, you can manage your MySQL databases from phpMyAdmin web interface.

Your LAMP stack is ready to use. Hooray!!
.................................................................................................... .....................................................

Wordpress Database Initialisation

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

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

Go to: https://wordpress.org/download/

Download wordpress-6.2.zip to Desktop and then extract the wordpress folder:

Code:
cd Desktop           
unzip wordpress-6.2.zip
The document root folder is www/html

Move the extracted wordpress folder on Desktop to /var/www/html/ using:

Code:
sudo mv /home/frank/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 = Frank’s Website
Admin Email = frank123@whatever.com
Username = Frank
Admin password = pmg^^7429XZ?

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
OR
http://localhost/wordpress/wp-login.php
.................................................................................................... ......................................................

Links:

https://linuxhint.com/install-wordpress-ubuntu-server/

Hardening Wordpress Security:

https://wordpress.org/documentation/...ing-wordpress/

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

Duplicator:
https://wordpress.org/plugins/duplicator/
Posted in Uncategorized
Views 1262 Comments 0
« Prev     Main     Next »
Total Comments 0

Comments

 

  



All times are GMT -5. The time now is 07:09 PM.

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