Page 1 of 11 123 ... LastLast
Results 1 to 15 of 153

Thread: How-to Lighttpd, PHP, MySQL and Eaccelerator

  1. #1
    Join Date
    Dec 2007
    Location
    The Netherlands - Eindhoven
    Posts
    1,767

    Post How-to Lighttpd, PHP, MySQL and Eaccelerator

    this how-to can be found on my website also: http://wpte.kicks-ass.net/forum/view...p?thread_id=14

    Change-log
    Code:
    11-07-09      Added clean-up for lighttpd so it always start after a reboot.
    11-07-09      Activated PEAR in php.ini
    31-07-09      Fixed mysql starting under non-root user
    21-09-09      Fixed possible insecurity for the www folder
    21-09-09      Added fix for TraceWatch web counter ip2country database update
    20-11-09      Added update for possible lighttpd version 1.4.24-1 problems
    12-03-10      Updated a lot of messy unclear stuff
    12-03-10      Updated eaccelerator howto because of a new stable version
    12-03-10      Added ipkg eaccelerator howto for the ones that don't like building after a php update
    12-03-10      Include the ipkg update and upgrade parts so users won't download old software
    10-09-10      Massive cleanup and bug fixing because of ipkg package fixes:
                      MySQL starting, php-fcgi, eaccelerator
    Introduction
    First of all, you might wonder what all these packages are...
    lighttpd: quite a famous web-server used by a few well known sites like youtube (yes youtube), mininova and thepiratebay! (see the whole list: http://redmine.lighttpd.net/wiki/lig...eredByLighttpd)

    php: probably the most used web-based scripting language

    MySQL: Free database software, also widely used in combination with php and CMS packages.

    Eaccelerator: a free open-source PHP accelerator, optimizer, and dynamic content cache.

    So there are some how-to's out there already about these packages, but they are not really that complete, or contain some old unfixed things.


    What do you need?
    1. A valid wengi-like ipkg installation
    2. Build enviroment if you want to build eaccelerator (no worries, this will be explained newbie proof)
    3. A few ipkg packages
    4. Eaccelerator source code if you want to build eaccelerator
    5. knowledge of basic linux stuff
    6. about 300mb free optware space
    7. enough swap space (About 15mb swap free)




    Installation: Lighttpd
    Well, lets start of easy by typing:
    ipkg update
    ipkg upgrade
    ipkg install lighttpd
    this will install the basic lighttpd package.

    When done enter:
    vi /opt/etc/lighttpd/lighttpd.conf
    now edit the following lines:
    (note: uncomment means remove the # in the beginning of the line)
    Code:
    line 40: change 
    server.document-root        = "/tmp/harddisk/www"
    (presuming you have the same mount point as in wengi's)
    This is for fixing the excluded e-poll:
    line 51: change

    # server.event-handler = "freebsd-kqueue" # needed on OS X

    into

    server.event-handler = "poll" # needed on OS X
    Code:
    line 139: change
    server.port                = 8081
    into:
    server.port                = 80
    (changing the webinterface port will be explained later)
    and save it!

    now create the folder where your web pages will be saved (remember this)
    mkdir /tmp/harddisk/www
    chmod 744 /tmp/harddisk/www
    By installing php-fcgi, the fast-cgi server will be enabled automatically, so there is no need of manually uncommenting the settings anymore.

    Because we want to host our web pages on the standard port of 80, we need to change the port of the web interface, since this is also hosted on port 80.
    When someone thinks he can change it by doing portforwarding or virtual server... yeah, you can but you most likely get problems with cookies (and that isn't nice).

    changing the port:
    Code:
    nvram set http_lanport=8080
    nvram commit
    after a reboot you will need to access the web interface by this url:
    http://your-asus-router-ip:8080






    Installation: php with some extensions
    To be sure you are as covered as you can on this router, you can just add all the php packages available:
    ipkg install php php-curl php-dev php-fcgi php-gd php-imap php-ldap php-mbstring php-mysql php-pear php-xmlrpc
    activate pear:
    vi /opt/etc/php.ini
    Code:
    Line 426:
    change the lines into this:
    
    ; UNIX: "/path1:/path2"
    include_path = ".:/opt/lib/php/extentions:/opt/share/pear"
    Save the file

    as you will notice it will also install mysql, since we don't have to do anything for php yet lets move on to mysql!







    Installation: MySQL
    now we have mysql installed and started we have to set a password.
    use this command:
    /opt/bin/mysqladmin -u root password 'secretpassword'
    note: leave the '' in the command, otherwise mysql won't understand!

    edit the my.cfg again to add the password for automatic login when you're in shell.
    vi /opt/etc/my.cnf
    Code:
    line 20: uncomment and type your password 
    password = yourpassword
    
    ofcourse change "yourpassword" into something you want to use as password!
    
    end result:
    [client]
    password        = secret
    port            = 3306
    socket          = /tmp/mysql.sock
    save it!

    now type:
    mysql
    and you will enter the mysql console, which is important to control your mysql server!

    a few handy commands:
    Code:
    Create a database = create database mydatabase;
    Remove a database = drop database mydatabase;
    select a database to use = use mydatabase;
    import sql queries = source /some/sql/file.sql;
    exit the prompt = exit;
    for more commands please read the mysql manual.





    Installation: Eaccelerator
    In this how-to you can choose which eaccelerator you want.
    The ipkg version is for people who don't want to worry about manually updating the php extension.
    for now the build-your-own eaccelerator is more up to date.
    (just pick the installation you prefer)

    Installation: IPKG Eaccelerator
    The worry-less installation
    ipkg install eaccelerator
    follow the final steps in "FINAL STEPS"



    Installation: OWN-BUILD Eaccelerator
    for the die-hards (still it's simple to follow)
    Don't forget to update eaccelerator when php receives an update

    first of all we need the build environment, which takes a while to download:
    ipkg install wget optware-devel buildroot
    you'll probably receive an error like:
    Code:
    Collected errors:
    ERROR: The following packages conflict with wget-ssl:
             wget
    don't worry, wget-ssl is reported as not working here, and wget is working just as well

    while you are downloading everything, lets get the sources:
    http://bart.eaccelerator.net/source/...-0.9.6.tar.bz2
    (at this moment this is the latest version, you may download a newer version if available)
    Just save the file to your pc, unpack it somewhere and place it on your router via samba share or ftp. Lets say you place the folder into /tmp/harddisk/eaccelerator-0.9.6

    after the ipkg package installation is done, you can continue:
    Before we start building, we need to install some libraries required by eaccelerator:
    ipkg install re2c grep
    now lets get to the real building stuff:
    cd /tmp/harddisk/eaccelerator-0.9.6
    export PHP_PREFIX="/opt"
    $PHP_PREFIX/bin/phpize
    ./configure --prefix=/opt --enable-eaccelerator=shared --with-eaccelerator-disassembler --with-eaccelerator-userid
    make
    make install
    please execute these command 1 at a time, to make sure everything goes well!
    you shouldn't get any errors... (don't pay too mutch attention to the configure command, unless it tells you there is an error in the end)
    note that make test is not possible and not required.

    after you executed make install, the files are in place, ready to be used.

    Now we only need to create a php configuration file.
    vi /opt/etc/php.d/eaccelerator.ini
    and copy paste this into the file
    Code:
    ;;EACCELERATOR
    ;;the settings for eaccelerator
    extension=eaccelerator.so
    eaccelerator.shm_size="16"
    eaccelerator.cache_dir="/opt/tmp/eaccelerator"
    eaccelerator.enable="1"
    eaccelerator.optimizer="1"
    eaccelerator.check_mtime="1"
    eaccelerator.debug="0"
    eaccelerator.filter=""
    eaccelerator.shm_max="0"
    eaccelerator.shm_ttl="0"
    eaccelerator.shm_prune_period="0"
    eaccelerator.shm_only="0"
    eaccelerator.compress="1"
    eaccelerator.compress_level="3"
    save the file and execute the final commands to create the cache dir:
    mkdir -p /opt/tmp/eaccelerator
    chmod 777 /opt/tmp/eaccelerator


    FINAL STEPS
    lets create a file to test everything after the reboot:
    vi /tmp/harddisk/www/index.php
    and enter the code:
    Code:
    <?php 
      phpinfo();
    ?>
    save it,
    chmod 766 /tmp/harddisk/www/index.php
    and done you are, just a final reboot to restart everything properly:
    reboot
    after the reboot you can visit http://your-asus-router/
    and you should get a page with information about the php installation... something you shouldn't get is a http 500 error.
    if you get this error here, please look over the how-to again, because you might have missed something.
    It is however possible that not all web packages work in this set-up, which is unfortunate, but there is no other option than find an alternative web package.
    Last edited by wpte; 10-09-2010 at 13:30.

  2. #2
    Join Date
    Dec 2007
    Location
    The Netherlands - Eindhoven
    Posts
    1,767
    ANY problems/issues you found in this how-to, please report it so I can fix it
    and yes, this is the way I got it working, but maybe there are some problems here and there








    Using the mysql server
    When installing a web package like a cms, you probably need to fill in mysql information.
    these are the settings:
    server: localhost
    port: 3306
    username: root
    password: (the password filled in the configuration file)
    database: (you need to use the created database name by the commands found in the handy commands list)

    Some web-packages
    Here are some packages that work well in this setup:
    http://www.tracewatch.com/ an advanced pagecounter (without ads). You might need to increase the execution time in php.ini due to large mysql dumping (about 4mb of sql)

    http://php-fusion.co.uk/ A CMS which is lightweight but has lots of functions. something I'm using now.

    http://cutephp.com/ Well... more lightweight than this is not possible, easy to use CMS, but you might need to find some good templates or create them yourself.

    http://www.rivetcode.com/software/rivettracker/ A real torrent tracker that allows you to put your own torrents on. Easy to use and easy to install.

    http://e107.org/ a nice cms with lots of possebilities. But do mind that it can give you some longer page-generation times.

    TraceWatch
    There is a bug in this pagecounter, fortunately it's easy to fix!
    Whenever you try to update to a newer ip2country database (http://ip-to-country.webhosting.info...ountry.csv.zip)
    you will find errors while dumping them into the mysql database...
    What you need to do is open the csv file in a text editor (like notepad, notepad++ etc) and replace the "" by " " (space between the quotation marks).
    now save it and try to load it up, it should work.
    Last edited by wpte; 10-09-2010 at 13:31.

  3. #3
    Join Date
    Nov 2004
    Location
    Sweden
    Posts
    259
    1) How much does Eaccelerator improve your web server? Any benchmark? What is the clock frequency of your router?
    2) How much RAM does this setup (Lighttpd, PHP, MySQL and Eaccelerator) requires? Can you please run and publish "ps axv" and "free"?

  4. #4
    Join Date
    Dec 2007
    Location
    The Netherlands - Eindhoven
    Posts
    1,767
    Quote Originally Posted by Tamadite View Post
    1) How much does Eaccelerator improve your web server? Any benchmark? What is the clock frequency of your router?
    2) How much RAM does this setup (Lighttpd, PHP, MySQL and Eaccelerator) requires? Can you please run and publish "ps axv" and "free"?
    Ah, we are talking performance here
    Well... it improves the overall generation time, and cold-start generation time. Normally a page on my site would be generated in 1 sec, now I usually see this is below 1 sec.
    The fastest time I ever had with generation is 0.63 sec without eaccelerator, but with I've seen up to 0.48 sec.
    I'm running at 300MHz.

    free space, this is with other things running tho.
    Code:
                 total       used       free     shared    buffers     cached
    Mem:         30176      29356        820          0       2064       9348
    -/+ buffers/cache:      17944      12232
    Swap:       522072      26084     495988
    ps avfx:
    Code:
      PID TTY      STAT   TIME  MAJFL   TRS   DRS   RSS %MEM COMMAND
      336 ?        S      0:00    103   717  1390     4  0.0 /bin/sh /opt/bin/mysqld_safe --datadir=/opt/var/lib/mysql --pid-file
      369 ?        S      0:00   1011  3107  4596   420  1.3  \_ /opt/libexec/mysqld --basedir=/opt --datadir=/opt/var/lib/mysql
      370 ?        S      0:00     26  3107  4596   420  1.3      \_ /opt/libexec/mysqld --basedir=/opt --datadir=/opt/var/lib/my
      371 ?        S      0:00     24  3107  4596   420  1.3          \_ /opt/libexec/mysqld --basedir=/opt --datadir=/opt/var/li
      378 ?        S      0:00   2102   194  4085   652  2.1 /opt/sbin/lighttpd -f /opt/etc/lighttpd/lighttpd.conf
      384 ?        Ss     0:00   1160  3285 35858     4  0.0  \_ /opt/bin/php-fcgi
      426 ?        S      0:00      4  3285 35886     4  0.0  |   \_ /opt/bin/php-fcgi
      385 ?        Ss     0:01   1164  3285 35858     4  0.0  \_ /opt/bin/php-fcgi
      427 ?        S      0:00      4  3285 35886     4  0.0  |   \_ /opt/bin/php-fcgi
      386 ?        Ss     0:00   1165  3285 35858     4  0.0  \_ /opt/bin/php-fcgi
      428 ?        S      0:01   1221  3285 36434     4  0.0  |   \_ /opt/bin/php-fcgi
      387 ?        Ss     0:01   1171  3285 35858     4  0.0  \_ /opt/bin/php-fcgi
      429 ?        S      0:14   7740  3285 36746  3868 12.8      \_ /opt/bin/php-fcgi
    I chose for the fast-cgi without creating a socket first because you'll never have the problem any more that the socket is unavailable!
    together it's using about 11MB ram/swap
    so what do you think?
    Last edited by wpte; 09-07-2009 at 11:03.

  5. #5
    Hello
    Gr8 tutorial but i'm getting errors while trying to connect to mysql

    Code:
    /opt/bin/mysqladmin -u admin password '********'
    /opt/bin/mysqladmin: connect to server at 'localhost' failed
    error: 'Access denied for user 'admin'@'localhost' (using password: YES)'
    [admin@router root]$ mysql
    ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
    [admin@router init.d]$ /opt/bin/mysqladmin -u root -p '********'
    Enter password:
    /opt/bin/mysqladmin: connect to server at 'localhost' failed
    error: 'Access denied for user 'root'@'localhost' (using password: YES)'
    and my config of my.cnf

    Code:
    # The following options will be passed to all MySQL clients
    [client]
    password        = ********
    port            = 3306
    socket          = /tmp/mysql.sock
    
    
    # The MySQL server
    [mysqld]
    user            = admin
    datadir         = /opt/var/lib/mysql
    port            = 3306
    socket          = /tmp/mysql.sock
    
    [mysql.server]
    user=root
    As you can see i was trying to connect to mysql wit admin and root username and it didn't help. What could be wrong?

  6. #6
    Join Date
    Dec 2007
    Location
    The Netherlands - Eindhoven
    Posts
    1,767
    Oh, seems I've made a mistake

    try to change
    [mysql.server]
    user=root
    into:
    [mysql.server]
    user=admin
    does that work?

    otherwise you might try these commands as well to rebuild the database:
    rm -R /opt/var/lib/mysql/mysql
    mkdir /opt/var/lib/mysql/mysql
    /opt/bin/mysql_install_db

  7. #7
    Hello,
    I've already tried to change
    Code:
    [mysql.server]
    user=root
    into admin but this didn't helped

    Also when i'm trying to execute
    Code:
    ipkg install optware-devel buildroot
    at the end of downloading i get an error about wget (it can't be used to download package to ipkg temp folder)

    I'll try to install the database once again after i'm thru with recoverying my files from hdd after moving opt partition (was to small when i wanted to install optware-devel buildroot, alhough it had 512MB).
    Last edited by cichy; 28-07-2009 at 19:21. Reason: Added 1 problem

  8. #8
    Join Date
    Dec 2007
    Location
    The Netherlands - Eindhoven
    Posts
    1,767
    uhm... have you restarted the mysql server after the config change?

    and when installing the build packages...
    if you install wget-ssl manually like this:
    ipkg install wget-ssl
    and then install the build enviroment


    I'm sorry to see that the mysql server is a bit of a trouble. I couldn't have tested it out myself on the router. I did test it on ubuntu which seemed to work out right

  9. #9
    Hmm i've restarted whole router just to make sure If i recall You didn't mentioned about manual installation of wget-ssl. Also there's new version of eaccelerator (http://bart.eaccelerator.net/source/....6-rc1.tar.bz2) will it work with all other components (i've checked folder structure and they're different in 0.9.5.3 & 0.9.6):>

  10. #10
    Join Date
    Dec 2007
    Location
    The Netherlands - Eindhoven
    Posts
    1,767
    Quote Originally Posted by cichy View Post
    Hmm i've restarted whole router just to make sure If i recall You didn't mentioned about manual installation of wget-ssl. Also there's new version of eaccelerator (http://bart.eaccelerator.net/source/....6-rc1.tar.bz2) will it work with all other components (i've checked folder structure and they're different in 0.9.5.3 & 0.9.6):>
    It'll probably work

    btw, can you confirm the mysql server works now? then I'll know what parts I need to update in the how-to

    No, I indeed dindn't mentioned manual installation of wget-ssl.
    The problem is, that usually wget is installed, and it doesnt work together with wget-ssl.
    wget-ssl is inculed in the building eviroment tho

  11. #11
    Quote Originally Posted by cichy View Post
    Hello
    Gr8 tutorial but i'm getting errors while trying to connect to mysql

    Code:
    /opt/bin/mysqladmin -u admin password '********'
    /opt/bin/mysqladmin: connect to server at 'localhost' failed
    error: 'Access denied for user 'admin'@'localhost' (using password: YES)'
    I also had that problem after following this tutorial.

    I solved it by commenting-out the password line in my.cnf (like it was by default).

  12. #12
    Join Date
    Dec 2007
    Location
    The Netherlands - Eindhoven
    Posts
    1,767
    so Dr. Chair... nothing wrong with the users then?

    Oh yes, I see I need to fix a few things there

  13. #13
    I've rebuilt whole mysql database, changed name from admin to root and vice versa and it didn't helped, I can't get to mysqladmin.
    Code:
    Enter password:
    /opt/bin/mysqladmin: connect to server at 'localhost' failed
    error: 'Access denied for user 'root'@'localhost' (using password: YES)'
    Dunno what to do now, removing ' didn't help, any sugestions?

    P.S. I've installed whole system from a scratch, wget, transmission, ftp are working fine but i ca't get lighttpd to work. Sure I installed it, index.htm* files are working without problem but i can't get fast-cgi to work. Htop shows this
    Code:
      152 ?        Ss     0:00      1   146  1365   340  1.1 /usr/sbin/vsftpd
      154 ?        Ss     0:00     36   119  2572   924  3.0 /usr/sbin/nmbd -D
      156 ?        Ss     0:00      9   343  2588   852  2.8 /usr/sbin/smbd -D
      170 ?        S      0:00    103   717  1390   456  1.5 /bin/sh /opt/bin/mysqld_safe --datadir=/opt/var/lib/mysql --pid-file=/opt/var/lib/mysql/router.pid
      203 ?        S      0:00    599  3107  4236  2576  8.5  \_ /opt/libexec/mysqld --basedir=/opt --datadir=/opt/var/lib/mysql --user=admin --pid-file=/opt/var/lib/mysql/router.pi
      206 ?        S      0:00      0  3107  4236  2576  8.5      \_ /opt/libexec/mysqld --basedir=/opt --datadir=/opt/var/lib/mysql --user=admin --pid-file=/opt/var/lib/mysql/route
      207 ?        S      0:00      2  3107  4236  2576  8.5          \_ /opt/libexec/mysqld --basedir=/opt --datadir=/opt/var/lib/mysql --user=admin --pid-file=/opt/var/lib/mysql/r
      225 ?        S      0:00     22   578  4633  2792  9.2 /opt/bin/transmission-daemon -g /tmp/harddisk/transmission/config
      226 ?        S      0:00      0   578  4633  2792  9.2  \_ /opt/bin/transmission-daemon -g /tmp/harddisk/transmission/config
      227 ?        S      0:24    241   578  4633  2792  9.2      \_ /opt/bin/transmission-daemon -g /tmp/harddisk/transmission/config
      383 ?        S      0:00     42   194  3853  1416  4.6 /opt/sbin/lighttpd -f /opt/etc/lighttpd/lighttpd.conf
      384 ?        Z      0:00   1078     0     0     0  0.0  \_ [php-fcgi] <defunct>
      385 ?        Z      0:00   1078     0     0     0  0.0  \_ [php-fcgi] <defunct>
      386 ?        Z      0:00   1078     0     0     0  0.0  \_ [php-fcgi] <defunct>
      388 ?        Z      0:00   1078     0     0     0  0.0  \_ [php-fcgi] <defunct>
    I'm attaching my installed packages, maybe something is missing? Also after reinstallation i can't compile latest eaccelerator (it worked earlier).
    Attached Files Attached Files
    Last edited by cichy; 30-07-2009 at 00:08.

  14. #14
    Join Date
    Dec 2007
    Location
    The Netherlands - Eindhoven
    Posts
    1,767
    well lets focus on the mysql server first:
    the idea is:
    • change the usernames in my.cfg and remove the password line, save it
    • stop the server
    • Rebuild the database
    • start the server
    • do the password setting: /opt/bin/mysqladmin -u admin password '********'
    • add the password line in my.cfg
    • try getting in by: mysql

  15. #15
    Ok, concerning mysql server i've managed to login to root account and later on into admin account. After restart mysql is working fine and you can both login as admin and as as a root. Next restart brought disappointment i couldn't login to mysql either by root nor admin account (s!c).

Page 1 of 11 123 ... LastLast

Similar Threads

  1. Full server config: Samba ftp http xmail mysql forum motor
    By KisVuK in forum WL-500gP Tutorials
    Replies: 14
    Last Post: 15-12-2008, 21:34

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •