Sunday, February 4, 2018
How to install wordpress with apache, mod_proxy_fcgi and php-fpm on Ubuntu 16.04
Hi everyone,
In one of the previous posts we've discussed how to setup basic website to work with apache and php-fpm. And today I'd like to continue that topic and install wordpress to work with apache and php-fpm. Once you've got that basic website to work with php-fpm, there are not many differences from 'non-php-fpm' wordpress setup. Anyway, I am still going to describe it here in details.
1. Install packages:
2. Create apache virtual host config file (/etc/apache2/sites-available/site.conf):
3. Enable proxy_fcgi module and site.conf:
4. Create file structure of your site:
5. Create pool for php-fpm.
Navigate to php-fpm pool directory:
- pool name: replace [www] => [site]
- listen:
6. Restart php-fpm:
1. Install required packages:
2. Create database and database user
Login to database as root:
3. Download wordpress, extract files
4. Create wp-config.php
5. Fix file permissions
6. Enable rewrite module, fix apache config (This is necessary for permalinks to work)
This is it. I hope I didn't forget anything. But if I did, please let me know in comments below. Now if you try to access http://site.com your wordpress should be working correctly.
If you're still confused you can also watch this video where I do all the same steps:
In one of the previous posts we've discussed how to setup basic website to work with apache and php-fpm. And today I'd like to continue that topic and install wordpress to work with apache and php-fpm. Once you've got that basic website to work with php-fpm, there are not many differences from 'non-php-fpm' wordpress setup. Anyway, I am still going to describe it here in details.
Part 1. Apache, mod_proxy_fcgi, php-fpm
1. Install packages:
sudo apt-get install apache2 php-fpm
2. Create apache virtual host config file (/etc/apache2/sites-available/site.conf):
<VirtualHost *:80> ServerName site.com DocumentRoot /var/www/site <FilesMatch \.php> SetHandler proxy:fcgi://127.0.0.1:9000 </FilesMatch> </VirtualHost>
3. Enable proxy_fcgi module and site.conf:
sudo a2enmod proxy_fcgi sudo a2ensite site sudo service apache2 restart
4. Create file structure of your site:
sudo mkdir -p /var/www/site sudo touch index.phpand add the following code to your index.php file:
<?php phpinfo(); ?>Using this file we will check that php code works, but you will need to remove that file later, because it's not secure to print that info on live website.
5. Create pool for php-fpm.
Navigate to php-fpm pool directory:
cd /etc/php/7.0/fpm/pool.d/Use default template as a base for the pool for our new website. So copy it:
sudo cp www.conf site.confThen open site.conf and change two parameters:
- pool name: replace [www] => [site]
- listen:
listen = /run/php/php7.0-fpm.sockchange it to this:
;listen = /run/php/php7.0-fpm.sock listen = 127.0.0.1:9000Here I use tcp sockets instead of file sockets. This is just for simplicity. You can change it to whatever value later, once the basic setup is working.
6. Restart php-fpm:
sudo service php7.0-fpm restartAt this point you should have basic website working. When you access http://site.com/index.php it should print some information about your server.
Part 2. Wordpress
1. Install required packages:
sudo apt-get install mysql-server php-mysql php-gd
2. Create database and database user
Login to database as root:
mysql -u root -pCreate database and user:
create database sitedb; grant all privileges on sitedb.* to siteuser@'localhost' identified by 'password';
3. Download wordpress, extract files
sudo chown $USER /var/www/site cd /var/www/site wget wordpress.org/latest.zip unzip latest.zip cp -R wordpress/* ./ rm -rf wordpress rm latest.zip
4. Create wp-config.php
cp wp-config-sample.php wp-config.phpIn the config file change database name, database user name, database user password and also add this setting:
define('FS_METHOD', 'direct');
5. Fix file permissions
sudo chown -R $USER:www-data /var/www/site sudo find /var/www/site -type f -exec chmod 660 {} \; sudo find /var/www/site -type d -exec chmod 2770 {} \;Here I used group www-data under which php-fpm/apache is running. This will allow php-fpm/apache to read and write files. But ideally it would be good to have different users/permissions for apache and php-fpm, so that apache could only read and php-fpm read/write. I leave this task for you as a homework ;-)
6. Enable rewrite module, fix apache config (This is necessary for permalinks to work)
sudo a2enmod rewriteAlso edit apache virtual host config file (/etc/apache/sites-available/site.conf) and add this setting which makes apache to honor .htaccess files:
<Directory /var/www/site> AllowOverride all </Directory>Restart apache:
sudo service apache2 restart
This is it. I hope I didn't forget anything. But if I did, please let me know in comments below. Now if you try to access http://site.com your wordpress should be working correctly.
If you're still confused you can also watch this video where I do all the same steps:
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment