{"id":4060,"date":"2021-02-04T22:15:44","date_gmt":"2021-02-04T22:15:44","guid":{"rendered":"https:\/\/linuxways.net\/?p=4060"},"modified":"2021-02-04T22:15:47","modified_gmt":"2021-02-04T22:15:47","slug":"how-to-setup-wordpress-on-ubuntu-server-with-apache","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/ubuntu\/how-to-setup-wordpress-on-ubuntu-server-with-apache\/","title":{"rendered":"How to Setup WordPress on Ubuntu Server with Apache"},"content":{"rendered":"<p>WordPress is a free and open-source content management system (CMS) that you can use to create, publish and manage great-looking websites, blogs, and associated content with minimal coding experience. WordPress is used by many globally recognized organizations and celebrities.<\/p>\n<p>To get started with WordPress, you could either use a hosting provider or download and install it yourself. This guide focuses on installing WordPress by yourself for development or testing purposes on a Ubuntu 20.04 Linux server with Apache<\/p>\n<h2>Install Apache<\/h2>\n<p>Let us begin by installing the Apache webserver if it\u2019s not already installed. Run the following commands to check for package updates and install the latest Apache version respectively.<\/p>\n<pre>$ <strong>sudo apt-get update<\/strong><\/pre>\n<pre>$ <strong>sudo apt-get install apache2 -y<\/strong><\/pre>\n<p>Check the status of the Apache web service as follows.<\/p>\n<pre>$<strong> sudo systemctl status apache2<\/strong><\/pre>\n<p>The output of the command should indicate that apache2 is active (running) as shown in figure 1 below. If not, run the following command to start Apache.<\/p>\n<pre><strong>sudo systemctl start apache2<\/strong><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"739\" height=\"187\" class=\"wp-image-4061\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-39.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-39.png 739w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-39-300x76.png 300w\" sizes=\"auto, (max-width: 739px) 100vw, 739px\" \/><\/p>\n<p><strong>Figure 1: Check apache service status<\/strong><\/p>\n<p>Press <strong>q<\/strong> to return to the terminal prompt.<\/p>\n<h2>Install WordPress, PHP and MySQL<\/h2>\n<p>The next step is to install WordPress, PHP, MySQL, and associated components by running the command below.<\/p>\n<pre>$ <strong>sudo apt-get install wordpress php libapache2-mod-php mysql-server php-mysql<\/strong><\/pre>\n<p>If prompted, enter<strong> y<\/strong> to continue.<\/p>\n<h3>Configure MySQL for WordPress<\/h3>\n<p>After the installation completes successfully, run the next command and follow the instructions to secure your MySQL installation.<\/p>\n<pre>$ <strong>sudo mysql_secure_installation<\/strong><\/pre>\n<p>The script will guide you accordingly.<\/p>\n<p>Next, you would need to create a database as well as a user account in MySQL for WordPress. Run the command below to login to MySQL. Enter your MySQL root password when prompted.<\/p>\n<pre>$ <strong>sudo mysql -u root -p<\/strong><\/pre>\n<p>To create a database for WordPress, run the following command.<\/p>\n<pre>$ <strong>CREATE DATABASE wordpress;<\/strong><\/pre>\n<p>To create a user account for WordPress in MySQL, run the next commands. Replace <strong>wordpressuser<\/strong> and <strong>password<\/strong> with your own values.<\/p>\n<pre>$ <strong>CREATE USER 'wordpressuser'@'localhost' IDENTIFIED BY 'password';<\/strong><\/pre>\n<p>To save changes, run:<\/p>\n<pre>$<strong> FLUSH PRIVILEGES<\/strong><\/pre>\n<p>Now, run the following command to grant the <strong>wordpressuser<\/strong> account the required permissions on the WordPress database.<\/p>\n<pre>$ <strong>GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpressuser'@'localhost';<\/strong><\/pre>\n<p>Save changes again and quit MySQL with the following commands.<\/p>\n<pre>$<strong> FLUSH PRIVILEGES<\/strong><\/pre>\n<pre>$<strong> quit<\/strong><\/pre>\n<h3>Configure Apache for WordPress<\/h3>\n<p>Run the command below to copy the WordPress installation folder from \/usr\/share to the default website root var\/www\/html.<\/p>\n<pre>$ <strong>sudo cp -R \/usr\/share\/wordpress \/var\/www\/html<\/strong><\/pre>\n<p>Change ownership of the WordPress folder and content to the default apache web service account and group.<\/p>\n<pre>$<strong> sudo chown -R www-data:www-data \/var\/www\/wordpress<\/strong><\/pre>\n<p>Also, grant the apache web service account and group full permissions on the WordPress folder and content as follows.<\/p>\n<pre>$ <strong>sudo chmod -R 775 \/var\/www\/html\/wordpress<\/strong><\/pre>\n<p>Next, open the default virtual host configuration file and change the value of the DocumentRoot directive to \/var\/www\/html\/wordpress as shown in figure 2 below.<\/p>\n<pre>$ sudo nano \/etc\/apache2\/sites-available\/000-default.conf<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"685\" height=\"255\" class=\"wp-image-4062\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-40.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-40.png 685w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-40-300x112.png 300w\" sizes=\"auto, (max-width: 685px) 100vw, 685px\" \/><\/p>\n<p><strong>Figure 2: Change default apache document root<\/strong><\/p>\n<p>Save changes to the file with CTRL + O, hit the enter key to confirm, and then press CTRL + X to exit.<\/p>\n<h3>Configure WordPress<\/h3>\n<p>First, change the working directory to the WordPress installation folder by running the command below.<\/p>\n<pre>$ <strong>cd \/var\/www\/html\/wordpress<\/strong><\/pre>\n<p>Next, copy the sample config file as follows.<\/p>\n<pre>$ <strong>sudo cp wp-config-sample.php wp-config.php<\/strong><\/pre>\n<p>Now, open the wp-config.php file, scroll down and input the WordPress database name, database user account, and password which you created earlier while configuring MySQL for WordPress.<\/p>\n<pre>$ <strong>sudo nano wp-config.php<\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"591\" height=\"209\" class=\"wp-image-4063\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-41.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-41.png 591w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-41-300x106.png 300w\" sizes=\"auto, (max-width: 591px) 100vw, 591px\" \/><\/strong><\/p>\n<p><strong>Figure 3: Configure WordPress settings<\/strong><\/p>\n<p>Save changes and close the wp-config.php file.<\/p>\n<p>Reload the apache web service by running the next command.<\/p>\n<pre>$ <strong>sudo systemctl reload apache2<\/strong><\/pre>\n<h3>Launch the WordPress Web Installer<\/h3>\n<p>Open a web browser and enter the IP address of your Ubuntu server. You should see the WordPress installation wizard as shown in figure 4 below. Follow the wizard to complete your WordPress installation.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"669\" height=\"341\" class=\"wp-image-4064\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-42.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-42.png 669w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-42-300x153.png 300w\" sizes=\"auto, (max-width: 669px) 100vw, 669px\" \/><\/p>\n<p><strong>Figure 4: WordPress installation wizard<\/strong><\/p>\n<h2>Conclusion<\/h2>\n<p>In this guide, we successfully installed WordPress &#8212; including Apache, MySQL, and PHP, on the Ubuntu Linux server. We hope that you enjoy using WordPress. We would be glad to read about your experiences using this content management system.<\/p>","protected":false},"excerpt":{"rendered":"<p>WordPress is a free and open-source content management system (CMS) that you can use to create, publish and manage great-looking websites, blogs, and associated content with minimal coding&hellip;<\/p>","protected":false},"author":28,"featured_media":4065,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[178,27,100,177],"class_list":["post-4060","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ubuntu","tag-apache","tag-mysql","tag-ubuntu-20-04","tag-wordpress"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/4060","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/28"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=4060"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/4060\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/4065"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=4060"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=4060"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=4060"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}