Installation on Ubuntu 22.04 with Apache Web Server
In WordPress: Installation on Ubuntu 22.04, we will walk you through the steps to install WordPress on a fresh installation of Ubuntu 22.04. You will learn how to set up the necessary LAMP stack components (Linux, Apache, MySQL, and PHP), download and configure WordPress, and ensure everything runs smoothly for your website or blog.
By the end of this post, you’ll have a fully functional WordPress site running on your Ubuntu 22.04 server. Whether you’re setting up a personal blog or a professional site, this guide will help you get up and running quickly and easily.
About WordPress
WordPress is a widely-used open-source content management system (CMS) that powers a significant portion of websites on the internet. Known for its user-friendly interface and extensive plugin ecosystem, WordPress allows users to easily create and manage websites without extensive coding knowledge. Initially designed for blogging, it has evolved into a versatile platform for various types of websites, from personal blogs to corporate sites. Its themes and plugins offer customization options, making it a go-to choice for both beginners and experienced developers seeking flexibility and scalability in website development.
More information at the page: https://wordpress.com/about/
Install Dependencies
sudo apt update
sudo apt install apache2 \
ghostscript \
libapache2-mod-php \
mysql-server \
php \
php-bcmath \
php-curl \
php-imagick \
php-intl \
php-json \
php-mbstring \
php-mysql \
php-xml \
php-zip
Install WordPress
In our case we will install WordPress in /srv/www folder. It is recommend by https://ubuntu.com/tutorials/install-and-configure-wordpress#3-install-wordpress
sudo mkdir -p /srv/www
sudo chown www-data: /srv/www
curl https://wordpress.org/latest.tar.gz | sudo -u www-data tar zx -C /srv/www
Configure Apache
nano /etc/apache2/sites-available/wordpress.conf
Copy the following content:
<VirtualHost *:80>
ServerName hostname.example.com
DocumentRoot /home/defenced/public_html
<Directory /srv/www/wordpress>
Options FollowSymLinks
AllowOverride Limit Options FileInfo
DirectoryIndex index.php
Require all granted
</Directory>
<Directory /home/defenced/public_html/wp-content>
Options FollowSymLinks
Require all granted
</Directory>
</VirtualHost>
Enable site with
sudo a2ensite wordpress
Enable URL rewriting with:
sudo a2enmod rewrite
Disable the default “It Works” site with:
sudo a2dissite 000-default
Restart Apache2 Service:
sudo service apache2 reload
Configure Database
sudo mysql -u root
mysql> CREATE DATABASE wordpress;
Query OK, 1 row affected (0.00 sec)
mysql> CREATE USER wordpress@localhost IDENTIFIED BY 'YourPassworD';
Query OK, 0 rows affected (0.02 sec)
mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,ALTER ON wordpress.* TO wordpress@localhost;
Query OK, 0 rows affected (0.01 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)
Enable MySQL Service
sudo service mysql start
Configure WordPress to connect to the Database
Copy the sample configuration file to wp-config.php
:
sudo -u www-data cp /home/defenced/public_html/wp-config-sample.php /home/defenced/public_html/wp-config.php
Edit wp-config.php file:
sudo -u www-data nano /home/defenced/public_html/wp-config.php
// ** Database settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'wordpress' );
/** Database username */
define( 'DB_USER', 'wordpress' );
/** Database password */
define( 'DB_PASSWORD', 'YourPassworD' )
Generate salts on the link: https://api.wordpress.org/secret-key/1.1/salt/
Edit the wp-config.php file and replace generated lines:
sudo -u www-data nano /home/defenced/public_html/wp-config.php
With Ctrl+K you can remove complete line and just copy generated lines:
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' );
Check IP Address and open WordPress
hostname -I
Open the WordPress on this way http://IP-ADDRESS