LAMP on Mandriva

From Christoph's Personal Wiki
Jump to: navigation, search

In this article, I will describe how to setup a LAMP environment on Mandriva Linux (version 2007.1).

MySQL (5.0)

To install MySQL 5.0, we simply run:

urpmi MySQL MySQL-client libmysql15-devel

(See: Notes for details.) By default, networking is not enabled in Mandriva 2007's MySQL package, but networking is required by ISPConfig. We can change this by commenting out the line skip-networking in /etc/my.cnf:

% vi /etc/my.cnf
  # Don't listen on a TCP/IP port at all. This can be a security enhancement,
  # if all processes that need to connect to mysqld run on the same host.
  # All interaction with mysqld must be made via Unix sockets or named pipes.
  # Note that using this option without enabling named pipes on Windows
  # (via the "enable-named-pipe" option) will render mysqld useless!

Afterwards, we start MySQL:

/etc/init.d/mysqld start

Now check that networking is enabled:

netstat -tap

It should show a line like this:

  Active Internet connections (servers and established)
  Proto Recv-Q Send-Q Local Address   Foreign Address   State   PID/Program name
  tcp        0      0 *:mysql-im      *:*               LISTEN  22188/mysqlmanager
  tcp        0      0 *:mysql         *:*               LISTEN  22196/mysqld

Next, run

mysqladmin -u root password yourrootsqlpassword
mysqladmin -h localhost -u root password yourrootsqlpassword

to set a password for the user root (Note: It is strongly recommended that you do not set your MySQL root password to be the same as your system root password!).


  • More information on package MySQL-5+

The initscript used to start mysql has been reverted to use the one shipped by MySQL AB. This means the following changes:

  • The MYSQLD_OPTIONS="--skip-networking" option in the /etc/sysconfig/mysqld file has been removed, this is now set in the /etc/my.cnf file.
  • The MySQL Instance Manager is used by default, set use_mysqld_safe="1" in the /etc/sysconfig/mysqld file to use the old mysqld_safe script.

The extra MySQL-NDB server package has been merged into the MySQL-Max package and ndb related pieces has been split into different sub packages as done by MySQL AB. The MySQL libraries and the MySQL-common sub package uses the MySQL-Max build so that no functionality required by for example the NDB parts are lost.

The MySQL-common package now ships with a default /etc/my.cnf file that is based on the my-medium.cnf file that comes with the source code. The /etc/my.cnf file is constructed at build time of this package.

To connect to the Instance Manager you need to pass the correct command line options like in the following examples:

mysql -u root --password=my_password --port=2273 --protocol=TCP
mysql -u root --password=my_password --socket=/var/lib/mysql/mysqlmanager.sock

Please note you also need to add a user in the /etc/mysqlmanager.passwd file and make sure the file is owned by the user under which the Instance Manager service is running under.

You might need to

chkconfig mysqld

Moving the MySQL's datadir directory

By default, MySQL's datadir is placed in the /var/lib/mysql directory. However, if you are planning on using MySQL tables to store a lot of data and your /var partition is small, it might cause you problem at a later stage. In such a scenario, it is better to move the MySQL's datadir to another partition (like /home.

The steps are:

  1. Stop your mysql server before starting this operation
  2. Create the directories that will be new datadir
  3. chown the directory to the mysql:mysql user
  4. copy the files from the old datadir to the new location. However, make sure that the files named ib_arch_log_0000000000, ib_logfile0 etc. are not copied to the newer location.
  5. Make sure that the files and directories are owned by mysql user
  6. Make changes in the my.cnf to point the new datadir.
  7. Restart the MySQL database
  8. You might need to do varying degree of troubleshooting to get the server working if there is some problem
  9. Create a new database and verify that the files for this database are getting created in the new datadir
  10. After the server is running for a few days properly, get rid of the old data.

Apache2 with PHP5

To install Apache2 and PHP5, run the following command (in one line):

urpmi apache-mod_php libphp5_common5 php-bz2 php-calendar php-ctype php-curl php-devel \
php-dio php-dom php-eaccelerator php-enchant php-esmtp php-event php-exif php-fam php-ffmpeg \
php-fileinfo php-filepro php-ftp php-gd php-gettext php-gmp php-iconv php-id3 php-idn php-imap \
php-imlib2 php-mailparse php-mbstring php-mcache php-mcrypt php-mhash php-ming php-mysql \
php-mysqli php-ncurses php-newt php-odbc php-oggvorbis php-pam_auth php-pcntl php-pcre \
php-pear-Net_IDNA php-posix php-pspell php-readline php-recode php-session php-shmop \
php-simplexml php-snmp php-soap php-sockets php-sqlite php-ssh2 php-sysvmsg php-sysvsem \
php-sysvshm php-tclink php-tcpwrap php-tidy php-xml php-xmlrpc php-zip php5-ini curl \
libcurl4-devel perl-libwww-perl ImageMagick

Start Apache:

/etc/init.d/httpd restart

Disable PHP Globally

(Note: If you do not plan to install ISPConfig on this server, please skip this section.)

In ISPConfig you will configure PHP on a per-website basis, i.e. you can specify which website can run PHP scripts and which one cannot. This can only work if PHP is disabled globally because otherwise all websites would be able to run PHP scripts, no matter what you specify in ISPConfig.

Edit /etc/httpd/modules.d/70_mod_php.conf and comment out the AddType lines:

<IfDefine HAVE_PHP5>
    <IfModule !mod_php5.c>
        LoadModule php5_module    extramodules/

<IfModule mod_mime.c>
#    AddType application/x-httpd-php .php
#    AddType application/x-httpd-php .phtml
#    AddType application/x-httpd-php-source .phps

<IfModule mod_php5.c>
    <IfModule mod_dir.c>
        DirectoryIndex index.php index.phtml

Edit /etc/httpd/conf/mime.types and comment out the following lines:

#application/x-perl             perl pl
#application/x-php              php php3 php4

Edit /etc/httpd/conf/httpd.conf and add the following line to the LoadModule section:

LoadModule php5_module    extramodules/

(Note: For a fresh list of available modules for apache2, please visit

Although this line is already in /etc/httpd/modules.d/70_mod_php.conf this is very important because otherwise the command

httpd -t

will report errors instead of Syntax OK when the virtual hosts created by ISPConfig contain lines like php_admin_flag safe_mode On or the like.)

Restart Apache:

/etc/init.d/httpd restart