I`ve experimented with many VPS configurations in the last several months and I decided to write a wordpress tutorial about the fastest, and most optimized solution I`ve come up with. The server I`ll be using is Dual-Core, 3 GB RAM, Ubuntu 12.04 64-bit(Not the best OS solution I know but it easy to work with) it will be hosting only one WordPress MU with several hundred sites. The configuration I`ll be using is Apache Worker(Nginx is also a good alternative but I`ll add an article about that in the future), PHP-FPM fastcgi process manager, standart MySQL and APC. So enough details let`s start.
First thing you need to do is install Apache Worker:
sudo apt-get install apache2-mpm-worker
I won`t change the apache2. conf because it suits my needs for now, but if any of you needs to tweak it because of less/more memory:
vi /etc/apache2/apache2.conf
and find the following segment:
StartServers 2 MaxClients 150 MinSpareThreads 25 MaxSpareThreads 75 ThreadsPerChild 25 MaxRequestsPerChild 0
Enable mod_rewrite for “pretty permalinks”:
a2enmod rewrite
Next step is to install Php5 on the Ubuntu Server and all needed modules for the wordpress normal operation:
sudo apt-get install php5 sudo apt-get install php5-mysql sudo apt-get install php5-gd
After the php5 and its modules are installed it is time to install the Mysql Server and Client
apt-get install mysql-server mysql-client
Installing fastcgi(libapache2-mod-fastcgi) is a little bit tricky. First try installing it with the standard command:
sudo apt-get install libapache2-mod-fastcgi
If that doesn`t work you`ll either have to enable the multiverse repository or just download it from debian here
wget http://ftp.de.debian.org/debian/pool/non-free/liba/libapache-mod-fastcgi/libapache2-mod-fastcgi_2.4.6-1_amd64.deb dpkg -i libapache2-mod-fastcgi_2.4.6-1_amd64.deb a2enmod fastcgi service apache2 restart
After the apache2, php and the mysql are installed it is time for the PHP-FPM fastcgi process manager
sudo apt-get install php5-fpm
Installing APC(Alternative page cache) is next in my list.
sudo apt-get install php-apc
It is a good idea to download apc.php in order to track your APC graphs. After you download it you can move it to your default DocumentRoot(which is /var/www in Apache2)
wget -O apc.php http://svn.php.net/viewvc/pecl/apc/trunk/apc.php?revision=325483&view=co mv apc.php /var/www
Restart your apache server and open http://your-server-domain.com/apc.php in your browser. That way you`ll test if your apache/php and apc are working at the same time.
After everything we need is installed we can start configuring the system for our wordpress multiuser/multisite installation. First of all I never run my sites by the default user(www-data) i create a separate user and use its /home folder for default document root.
useradd -m -d /home/multisite multisite passwd multisite
The passwd command will ask you for password for the new user. I strongly encourage people to use random generated passwords! There are a lot of online random password generators. I personally use Bitmill.
Now after the user has been created we`re ready to create the php-fpm pool for that site. I`m creating the pool after the user, because I want the php processes running by that user so that we can easily identify the load if needed later. You have to options for creating php pool. One is copy the default www.conf and edit it for your needs the other use the pool i`ll provide below(and again edit it if your server has less memory then 3GB Ram):
Option 1 – Edit the default pool(www.conf):
</p>
<p>vi /etc/php5/fpm/pool.d/www.conf</p>
<p>
Option 2 – Use the following pool(multisite.conf)
Again this is just a sample pool for a server with 3GB of RAM
[multisite] user = multisite group = multisite listen = /home/multisite/multisite-php5-fpm.sock listen.owner = multisite listen.group = multisite listen.mode = 0666 pm = dynamic pm.max_children = 20 pm.start_servers = 10 pm.min_spare_servers = 5 pm.max_spare_servers = 15 pm.max_requests = 0 request_terminate_timeout = 5 catch_workers_output = yes php_flag[display_errors] = on ;You`ll have to create folder logs in your home folder if you`re going to use that mkdir /home/multisite/logs php_admin_value[error_log] = /home/multisite/logs/php_err.log php_admin_flag[log_errors] = on php_admin_value[memory_limit] = 512M
Now our system is ready for the final step. Creating the vhost for our WordPress MU system. Again you can write your own or use the sample I`ll provide below.
In order to use the sample you`ll have tocreate a folder www in your home folder and create an empty vhost file and paste the code:
mkdir/home/multisite/www sudo vi /etc/apache2/sites-enabled/multisite
Vhost:
<VirtualHost *:80> ServerName multisite.example.com ServerAlias multisite.example.com DocumentRoot /home/multisite/www <IfModule mod_fastcgi.c> AddHandler php5-fcgi .php Action php5-fcgi /php5-fcgi virtual Alias /php5-fcgi /usr/lib/cgi-bin/multisite-php5-fcgi FastCgiExternalServer /usr/lib/cgi-bin/multisite-php5-fcgi -socket /home/multisite/multisite-php5-fpm.sock </IfModule> <Directory /home/multisite/www> AllowOverride all Order allow,deny Allow from all </Directory> </VirtualHost>
That is pretty much it restart apache(sudo service apache2 restart) download and extract the latest wordpress files in /home/multisite/www and you`re good to go.