Skip to content

Instantly share code, notes, and snippets.

@moaj257
Last active November 13, 2023 06:27
Show Gist options
  • Save moaj257/b8ba99a177d3a0c32e8005c507021ba7 to your computer and use it in GitHub Desktop.
Save moaj257/b8ba99a177d3a0c32e8005c507021ba7 to your computer and use it in GitHub Desktop.
Install WordPress with LAMP on Ubuntu 18.04

After configuring your Digital Ocean Server using my previous gist, you may follow this. Else go to my previous gist https://gist.github.com/moaj257/2d1a602fcec3f3dd9afd5f667119d342.

Step 1: Create a MySQL Database and User for WordPress

To get started, log into the MySQL root (administrative) account by issuing this command:

mysql -u root -p

Create a new database for a new wordpress installation. I am using wordpress as the database name.

mysql> CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;

Createa new user and asign all priviledges to that user for the new database using the following. I am using wordpressuser as the user name.

mysql> GRANT ALL ON wordpress.* TO 'wordpressuser'@'localhost' IDENTIFIED BY 'password';

After doing this, flush all previously set priviledges

mysql> FLUSH PRIVILEGES;

Then exit from MySql

mysql> EXIT;

Step 2: Install Additional PHP Extensions

Some additional php extensions are required for the wordpress.

sudo apt-get update
sudo apt-get install php-curl php-gd php-mbstring php-mcrypt php-xml php-xmlrpc

Then restart apache

sudo systemctl restart apache2

Step 3: Download WordPress

Change into a writable directory and then download the compressed release by typing:

cd /tmp
curl -O https://wordpress.org/latest.tar.gz

Extract the file downloaded

tar xzvf latest.tar.gz

Create a dummy htaccess file and set permissions to it.

touch /tmp/wordpress/.htaccess
chmod 660 /tmp/wordpress/.htaccess

We'll also copy over the sample configuration file to wp-config.php

cp /tmp/wordpress/wp-config-sample.php /tmp/wordpress/wp-config.php

We can also create the upgrade directory

mkdir /tmp/wordpress/wp-content/upgrade
sudo cp -a /tmp/wordpress/. /var/www/your_domain

Step 4: Configure the WordPress Directory

Adjusting the Ownership and Permissions

Change ownership

sudo chown -R www-data:www-data /var/www/your_domain

We can set the setgid bit on every directory in our WordPress installation by typing:

sudo find /var/www/your_domain -type d -exec chmod g+s {} \;

There are a few other fine-grained permissions we'll adjust. First, we'll give group write access to the wp-content directory so that the web interface can make theme and plugin changes:

sudo chmod g+w /var/www/your_domain/wp-content

As part of this process, we will give the web server write access to all of the content in these two directories:

sudo chmod -R g+w /var/www/your_domain/wp-content/themes
sudo chmod -R g+w /var/www/your_domain/wp-content/plugins

Setting up the WordPress Configuration File

To grab secure values from the WordPress secret key generator, type:

curl -s https://api.wordpress.org/secret-key/1.1/salt/

You will get back unique values that look something like this:

Output
define('AUTH_KEY',         '1jl/vqfs<XhdXoAPz9 DO NOT COPY THESE VALUES c_j{iwqD^<+c9.k<J@4H');
define('SECURE_AUTH_KEY',  'E2N-h2]Dcvp+aS/p7X DO NOT COPY THESE VALUES {Ka(f;rv?Pxf})CgLi-3');
define('LOGGED_IN_KEY',    'W(50,{W^,OPB%PB<JF DO NOT COPY THESE VALUES 2;y&,2m%3]R6DUth[;88');
define('NONCE_KEY',        'll,4UC)7ua+8<!4VM+ DO NOT COPY THESE VALUES #`DXF+[$atzM7 o^-C7g');
define('AUTH_SALT',        'koMrurzOA+|L_lG}kf DO NOT COPY THESE VALUES  07VC*Lj*lD&?3w!BT#-');
define('SECURE_AUTH_SALT', 'p32*p,]z%LZ+pAu:VY DO NOT COPY THESE VALUES C-?y+K0DK_+F|0h{!_xY');
define('LOGGED_IN_SALT',   'i^/G2W7!-1H2OQ+t$3 DO NOT COPY THESE VALUES t6**bRVFSD[Hi])-qS`|');
define('NONCE_SALT',       'Q6]U:K?j4L%Z]}h^q7 DO NOT COPY THESE VALUES 1% ^qUswWgn+6&xqHN&%');

Now, open the WordPress configuration file:

nano /var/www/your_domain/wp-config.php

Find the section that contains the dummy values for those settings. It will look something like this:

. . .

define('AUTH_KEY',         'put your unique phrase here');
define('SECURE_AUTH_KEY',  'put your unique phrase here');
define('LOGGED_IN_KEY',    'put your unique phrase here');
define('NONCE_KEY',        'put your unique phrase here');
define('AUTH_SALT',        'put your unique phrase here');
define('SECURE_AUTH_SALT', 'put your unique phrase here');
define('LOGGED_IN_SALT',   'put your unique phrase here');
define('NONCE_SALT',       'put your unique phrase here');

. . .

Delete those lines and paste in the values you copied from the command line:

. . .

define('AUTH_KEY',         'VALUES COPIED FROM THE COMMAND LINE');
define('SECURE_AUTH_KEY',  'VALUES COPIED FROM THE COMMAND LINE');
define('LOGGED_IN_KEY',    'VALUES COPIED FROM THE COMMAND LINE');
define('NONCE_KEY',        'VALUES COPIED FROM THE COMMAND LINE');
define('AUTH_SALT',        'VALUES COPIED FROM THE COMMAND LINE');
define('SECURE_AUTH_SALT', 'VALUES COPIED FROM THE COMMAND LINE');
define('LOGGED_IN_SALT',   'VALUES COPIED FROM THE COMMAND LINE');
define('NONCE_SALT',       'VALUES COPIED FROM THE COMMAND LINE');

. . .

This setting can be added below the database connection settings, or anywhere else in the file:

. . .

define('DB_NAME', 'wordpress');

/** MySQL database username */
define('DB_USER', 'wordpressuser');

/** MySQL database password */
define('DB_PASSWORD', 'password');

. . .

define('FS_METHOD', 'direct');

Step 5: Complete the Installation Through the Web Interface

In your web browser, navigate to your server's domain name or public IP address:

http://server_domain_or_IP

Complete the setup and you are good to go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment