Tag Archives: LAMP

Moving a live WordPress site to a local LAMP Server

Linux, Apache, MySql, WordPress, Web Development, Algarve, Portugal
LAMP on Ubuntu 18.04

Audience: Ubuntu Desktop and Server users. Tested on 18.04

Steps to follow to setup a local development WordPress installation.

1) Copy your entire live WordPress directory to your local LAMP server.

Do this by means of FTP using and FTP Client such as Filezilla.

This should include your wp-admin, wp-includes , wp-admin and all the files in the root directory in which these reside. This is where the wp-config.php, wp-login.php, .htaccess files etc reside.

2) On your LAMP server these should be placed in the directory. It is advisable to create a folder under the html directory where these files will go if you are hosting more than one test site. e.g var/www/html/testsite

3) Backup the MySql database related to your WordPress live site. It is easiest to do this using PHPMyAdmin provided by your control panel of your hosting site. This is the only way have done it so far. Accept defaults and export the database. You will be given the option to save the file as a *.sql file.

Ubuntu 18.04, WordPress, Stack Exchange, Ask Ubuntu, Algarve, Portugal

4) On your LAMP server create a MySql database and database user. You can use PHPMyAdmin. However I have had problems, with PHPMyAdmin throwing up errors and not importing the database correctly or granting user privileges correctly. I have had to do it via command line like this. I strongly advise this method, as command line rules. 🙂

By command line.

Log into mysql as root

Create database

mysql> create database db_name;

Import the database:

mysql> use db_name;

mysql> source backup-file.sql;

Create a user and grant privileges

GRANT ALL PRIVILEGES ON mydb.sql TO myuser@localhost IDENTIFIED BY "mypassword";

5) Edit your WordPress wp-config.php ensuring that the database name, username and user password match the ones created.

6) Update your tables to ensure your links work but running the following 3 command line MySql queries on the following tables. You can do this by logging into mysql as root via command line.

UPDATE wp_options SET option_value = replace(option_value, 'https://www.example.com', 'https://localhost/test-site') WHERE option_name = 'home' OR option_name = 'siteurl';

UPDATE wp_posts SET post_content = replace(post_content, 'https://www.example.com', 'https://localhost/test-site');

UPDATE wp_postmeta SET meta_value = replace(meta_value,'https://www.example.com','https://localhost/test-site');

These queries will replace references to your live site’s URL from database with the localhost URL.

7) Lastly, an mostly importantly this pertains to the Ubuntu operating system environment. Apache here is installed differently from a native install for security reasons. In order to get your development WordPress running, you must do the following otherwise none of the symlinks ( symbolic links) to other pages on your site will work.

Note: nano is a text editor that’s pre-installed on Ubuntu

  1. In /etc/apache2/apache2.conf, edit AllowOverride None for /var/www/ to AllowOverride All
  2. To edit use

sudo nano /etc/apache2/apache2.conf

Press CTRL + W and search for “<Directory /var/www/>â€

Change here AllowOverride None to AllowOverride All

Save file and exit. (Press CTRL + X, press Y and then press ENTER)

  1. Type in the following command to enable mod_rewrite for .htaccess

sudo a2enmod rewrite

  1. Restart your apache server:

sudo service apache2 restart

Finally make sure you have a .htaccess file in the root directory where WordPress is installed.

It should contain code similar to this:

# BEGIN WordPress

<IfModule mod_rewrite.c>

RewriteEngine On

RewriteBase /your_directory/

RewriteRule ^index\.php$ - [L]

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . /your_directory index.php [L]

</IfModule>

# END WordPress

That’s about it for now! Coming soon, a Control Panel App for a local LAMP install.

Sources:

Credits to: https://wordpress.stackexchange.com/users/84055/avinash (April,2020)

Credits to: https://www.wpbeginner.com, Editorial Staff at WPBeginner led by Syed Balkhi. (April,2020)

LAMP on Ubuntu 18.04

I took the leap and migrated to linux, ditching MS Windows 7 as my main operating system.

On the whole I am very pleased with Ubuntu 18.04.

I was running XAMPP on Windows 7 as test environment for hosting WordPress and PHP based applications.

So I needed to install a similar test environment on Ubuntu 18.04 desktop. In the Linux world this is LAMP. The components of LAMP are Linux, Apache Web Server, MySQL Server and PHP

Here is how to install LAMP on Ubuntu 18.04

Using command line via Terminal (press Control+Alt+T ) Terminal  Ubuntu 18.04

Install Mysql.

  • Ensure you have an internet connection then open Terminal.
  • Type sudo apt install mysql-server

Press Enter on the keyboard. This will install the Mysql Metapackage from the Debian repositories.

Test your Mysql server installation by typing mysql in the terminal window. You used be able to login with your Ubuntu user login password.

Install Apache 2

To install Apache you must install the Metapackage apache2 from the Debian repositories. This can by

  • Ensure you have an internet connection then open Terminal.
  • Type sudo apt install apache2

Install PHP

  • Ensure you have an internet connection then open Terminal.
  • sudo apt install php-pear php-fpm php-dev php-zip php-curl php-xmlrpc php-gd php-mysql php-mbstring
  • Your server should restart Apache automatically after the installation of both MySQL and PHP. If it doesn't, execute this command.

Check Apache

You should see the following page with a message saying that it work

Apache Web Server running

Check PHP

  • You can check your PHP by executing any PHP file from within /var/www/.
  • Alternatively you can execute the following command, which will make PHP run the code without the need for creating a file . $ php -r 'echo "Your PHP installation is working\n";'

Pat yourself on the back and take a break. Congratulations! You have just successfully installed a LAMP server on Apache.

As a reward install and play Chromium BSU.

  • Ensure you have an internet connection then open Terminal.
  • Type sudo apt install chromium-bsu

This should download and install this excellent arcade game which you can play for 5 minutes to have a break :). I tried downloading it from the Ubuntu Snap store but it didn’t install correctly from there. Chromium B.S.U Debian, Ubuntu 18.04

Preparing LAMP to run as a local WordPress and Web Hosting Test Environment.

Ubuntu installs Apache in modules and splits the configuration files which is different from the standard install.

The Mysql server installs with the Ubuntu user as root for authentication. WordPress and other applications use native mysql authentication.

Here is how to enable native root user authentication and change the mysql root user password.

  • Stop mysql:
  • $ sudo service mysql stop
  • (Be sure to stop the current server before performing the steps. Only one server can run at a time.)
  • $ sudo mkdir /var/run/mysqld; sudo chown mysql /var/run/mysqld
  • $ sudo mysqld_safe –skip-grant-tables&
You should see sonething like this if it runs successfully

[1] 1901

*@*-desktop:~$ 2020-04-29T20:36:42.126862Z mysqld_safe Logging to syslog.

2020-04-29T20:36:42.132327Z mysqld_safe Logging to '/var/log/mysql/error.log'.

  • 2020-04-29T20:36:42.197722Z mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
  • Next run $ sudo mysql --user=root mysql
  • This will log you in as the native mysql root user.

“Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 2

Server version: 5.7.29-0ubuntu0.18.04.1 (Ubuntu)..â€

and you should have the mysql prompt mysql>

  • to change the root pasword run

mysql> update user set authentication_string=PASSWORD('new_password') where user='root';

You should see

“Query OK, 1 row affected, 1 warning (0.03 sec)

Rows matched: 1 Changed: 1 Warnings: 1â€

  • To change the authentication plugin run

mysql> UPDATE user SET plugin='mysql_native_password';

You should see someething like

Query OK, 4 rows affected (0.00 sec)

Rows matched: 4 Changed: 4 Warnings: 0

  • Finally

mysql> FLUSH PRIVILEGES;

  • mysql> quit
  • stop and start the mysql server and test root login:

Stop mysql:

$ sudo service mysql stop

Start mysql (normal):

$ sudo service mysql start

Log in as root on localhost:

$ mysql -h localhost -u root -p 

That’s it for now! 

Sources:
Ask Ubuntu - software installation - mysql doesn't ask for root password when installing - Ask Ubuntu

Initial Server Setup with Ubuntu 18.04 | DigitalOcean

https://howtoubuntu.org/ ,How to Install LAMP on Ubuntu, April,2020