Saturday, August 28, 2010

Install and setup PHPList

PHPList is an open-source newsletter manager, free to download, install and use. Follow this link to know more...
http://www.phplist.com/details
Here I'm trying to document how to set up PHPlist on Ubuntu that should work for other distributions with little modifications.

Setup Apache, PHP & MySQL:

Install Apache2 and PHP5
 apt-get install apache2 php5
Following NEW packages will be installed
 apache2 apache2-mpm-prefork apache2-utils apache2.2-common libapache2-mod-php5 libapr1 libaprutil1 libexpat1 libmagic1 libpq5 libxml2 php5 php5-common ucf
Install MySQL that must be 3.23 or higher
aptitude install mysql-server mysql-client libmysqlclient15-dev libapache2-mod-auth-mysql php5-mysql
The following NEW packages will be installed
apparmor apparmor-profiles libapache2-mod-auth-mysql libdbd-mysql-perl libdbi-perl libhtml-template-perl libmysqlclient15-dev libmysqlclient15off libnet-daemon-perl libplrpc-perl libterm-readkey-perl mysql-client mysql-client-5.0 mysql-common mysql-server mysql-server-5.0 php5-mysql zlib1g-dev
You will be also prompted to enter an admin password

Get strong one.

To check whether these packages installed or not, just fire

 dpkg --get-selections
 dpkg -L php5|apache2|mysql-client-5.0
To check whereabouts of MySQL
root@moinhaidar:~# find / -type d -name "mysql"
It will give you sth like this...
/var/lib/mysql
/var/lib/mysql/mysql
/var/log/mysql
/usr/lib/mysql
/usr/lib/perl5/DBD/mysql
/usr/lib/perl5/auto/DBD/mysql
/usr/include/mysql
/usr/share/mysql
/etc/mysql

Setup Database

Lets login to mysql we just installed
root@moinhaidar:~# mysql -uroot -p
Enter the password you fed while installation.
Now you should be on mysql command line as seen like this
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
Create a database for PHPList namely myphplist
mysql> create database myphplist;
Query OK, 1 row affected (0.00 sec)
Grant privileges
mysql> GRANT ALL PRIVILEGES ON myphplist.* TO 'root'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)
Check that out
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| myphplist          |
| mysql              |
+--------------------+
3 rows in set (0.00 sec)
Now its time to look into PHP installation. Create file say test.php using your favorite editor having
<?php
 phpinfo();
?>
Now fire root@moinhaidar:~# php test.php
Ooooo!!! You got an error like php not found! Okay lets install this package to get command line PHP.
 apt-get install php5-cli
So far so good!

Configuring PHP to Work With MYSQL

Again fire root@moinhaidar:~# php test.php and look for extension_dir something like below.
 extension_dir => /usr/lib/php5/20060613 => /usr/lib/php5/20060613
Now its time to find php.ini and get it configured...
 find / -name php.ini
Output should sth like this
/etc/php5/cli/php.ini
/etc/php5/apache2/php.ini
Open /etc/php5/cli/php.ini and search for extension_dir this should be sth like this
; Directory in which the loadable extensions (modules) reside.
;extension_dir = 
Uncomment if commented and set extension_dir what you find with root@moinhaidar:~# php test.php like
extension_dir = "/usr/lib/php5/20060613"

Setup PHPList

Get the latest version of PHPList
wget http://sourceforge.net/projects/phplist/files/phplist-development/2.11.5/phplist-2.11.5.tgz/download
Copy to appropriate loation, usually /var/www/ and untar/unzip whatever...
root@moinhaidar:~# mv phplist-2.11.5.tgz /var/www
root@moinhaidar:~# tar -xvzf phplist-2.11.5.tgz
root@moinhaidar:~# mv phplist-2.11.5 mylists
Now its time to configure ./mylist/config/config.php
[General settings for language and database]
$database_host = "localhost";
$database_name = "myphplist";
$database_user = "root";
$database_password = "dbpassword";
$installation_name = 'Whatever';

[Settings for handling bounces] $message_envelope = 'noreply@yourdomain.com'; $bounce_mailbox_user = 'noreply'; $bounce_protocol = 'mbox'; $bounce_mailbox = '/var/mail/noreply';
[Security related settings] $require_login = 1;
[Debugging and informational] define ("TEST",0); define('SEND_ONE_TESTMAIL',1);
Lets create new site namely phplist
root@moinhaidar:~# cp /etc/apache2/sites-available/default /etc/apache2/sites-available/phplist
Now "vi /etc/apache2/sites-available/phplist" and get it configure...
+ indicates new addition
* indicates modified
+ ServerName yourdomain.com
* ServerAdmin admin@yourdomain.com
+ ServerAlias *.yourdomain.com yourdomain.com
* DocumentRoot /var/www/mylists
#*Setting Off PHP safe mode in order to acheive bounce processing - site wise
php_admin_flag safe_mode Off

        Options FollowSymLinks
        AllowOverride None


        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        allow from all
        + DirectoryIndex index.php index.html

Okay, Now enable mylists site and disable default one
sudo a2dissite default
sudo a2ensite lists
Now Check "vi /etc/apache2/sites-enabled/mylists", that should be same as sites-availabe one.
Installed IMAP module for PHP bcoz phpList bounce processing connects to your mail server via a PHP module called IMAP.
 apt-get install php5-imap

Checklist

#Create a temp dir
Create tmp dir to ./var/www/mylists/ if not there.
root@moinhaidar:~#
#Change permission
root@moinhaidar:~# chmod -R 777 /var/www/mylists
#Restart server
root@moinhaidar:~# /etc/init.d/apache2 restart
Done Hit http://yourdomain.com/admin/
Got uninitialized database?
Hit initialized database link. It will populate your database(myphplist).
Cross check the database
root@mail:~# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 15
Server version: 5.0.51a-3ubuntu5.5 (Ubuntu)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> use myphplist;
mysql> show tables;
+----------------------+
| Tables_in_myphplist  |
+----------------------+
| admin                |
| admin_attribute      |
| admin_task           |
Done! Go to http://yourdomain.com/admin/?page=setup and setup remaining thing and enjoy!

Basic Mail Server Setup

Install follwing package choosing options...
Option 1 - internet site : Mail will be get read/delivered directly via SMTP

Option 2 - mail.youdomain.com : FQDN

root@moinhaidar:~# aptitude install postfix telnet mailx postfix-mysql
Configure /etc/postfix/main.cf adding followings
myhostname = mail.yourdomain.com
myorigin = $mydomain
mydestination =  $mydomain, localhost.$mydomain, localhost
Edit /etc/mailname and /etc/hostname having
 mail.yourdomain.com
Edit /etc/hosts having
127.0.0.1     localhost localhost.localdomain
server-ip    mail.yourdomain.com
Reboot the system
sudo reboot
Add a user namely noreply

Setup Reverse DNS

Quick Test

mail email@yourdomain.com
Subject: test email from yourdomain.com
test body of the email.
.
Cc:
No confirmation is given that the email has been sent but the logs will show the details.

Check the receiving email address and I hope you got expected!!! :)

7 comments:

  1. Thanks a lot for putting this together. I found it very useful.

    ReplyDelete
  2. thanks a lot not tested yet but look's perferct.

    ReplyDelete
  3. Thanks a lot it look's perfect!

    regard
    bl4ck_sh33p

    ReplyDelete
  4. Anyone have tested this tutorial? Works? Or only comment in this page to be ranked up by google ?

    ReplyDelete
  5. This worked a charm for me, thank you.

    ReplyDelete
    Replies
    1. Though its too old but happy to see its still working :)

      Delete