Compiling PHP on a Linux server can be a bear of a project. The first time you try doing it, you might just frustrated and just want to install PHP with a RPM package. But you don’t get any flexibility with RPM packages, you just get the default install.
With a custom PHP install (compiling), you can pick which PHP options you want and don’t want. Do you need cURL (now default as of PHP 5.2+)? Using MySQL/phpMyAdmin? Then you will want to compile PHP with mcrypt and mbstring. These are just a couple of examples, but you will have plenty to choose from. We’ll learn about these options very soon…
So let’s start with the install. For my installation, I’m on a Red Hat Enterprise Linux 5 Server (RHEL5). So the paths/configurations I use are specific to that operating system (OS). I’m running MySQL 5+ and Apache 2+. For this installation you will need to have ssh access to your server. If you have a shared hosting account, you might have ssh access, but most likely you will not have the proper privileges to compile PHP. I’ll break this down into steps, to hopefully simplify the process.
- ssh to your server (if you don’t have an ssh client, try PuTTY. It’s free.)
- Become root on the server (if you have root access), by typing su - and then enter the root password. Or use sudo if that is an option.
- cd /usr/local/src
- In a browser go to php.net to get the source download URL (this changes depending on PHP version and the mirror location). In this example the download URL is http://us.php.net/get/php-5.3.8.tar.bz2/from/this/mirror
- Now download the file by typing wget http://us.php.net/get/php-5.3.8.tar.bz2/from/this/mirror
- Extract the PHP source files: tar xjvf php-5.3.8.tar.bz2
- cd php-5.3.8
- Now that you have the PHP source, and have extracted the files, you can find out what you’re install options are by typing:
./configure –h.
You’ll get a really long list (a bit overwhelming) of compile options. You can dig through each of these options, or just go with what I’m going to do. The nice thing is that once you have compiled PHP once, it’s fairly painless to re-compile PHP with new options should you miss something.
- So here’s my configure command (notice that this is specific to 64bit RHEL). Note you should copy this into Notepad or similar to make sure all of the line breaks are ok:
./configure –build=x86_64-redhat-linux-gnu –host=x86_64-redhat-linux-gnu –target=x86_64-redhat-linux-gnu –program-prefix= –prefix=/usr –exec-prefix=/usr –bindir=/usr/bin –sbindir=/usr/sbin –sysconfdir=/etc –datadir=/usr/share –includedir=/usr/include –libdir=/usr/lib64 –libexecdir=/usr/libexec –localstatedir=/var –sharedstatedir=/usr/com –mandir=/usr/share/man –infodir=/usr/sh
are/info –cache-file=../config.cache –with-libdir=lib64 –with-config-file-path=/etc –with-config-file-scan-dir=/etc/php.d –disa
ble-debug –with-pic –disable-rpath –with-pear –with-bz2 –with-curl –with-exec-dir=/usr/bin –with-freetype-dir=/usr –with-
png-dir=/usr –enable-gd-native-ttf –without-gdbm –with-gettext –with-gmp –with-iconv –with-jpeg-dir=/usr –with-openssl –with
-pspell –with-pcre-regex=/usr –with-zlib –with-layout=GNU –enable-exif –enable-ftp –enable-magic-quotes –enable-sockets –ena
ble-sysvsem –enable-sysvshm –enable-sysvmsg –enable-wddx –with-kerberos –enable-ucd-snmp-hack –with-unixODBC=shared,/usr –enable-shmop –enable-calendar –with-mime-magic=/usr/share/file/magic.mime –without-sqlite –with-libxml-dir=/usr –enable-force-cgi-
redirect –enable-pcntl –with-imap=shared –with-imap-ssl –enable-mbstring=shared –enable-mbregex –with-ncurses=shared –with-gd
=shared –enable-bcmath=shared –enable-dba=shared –with-db4=/usr –with-xmlrpc=shared –with-ldap=shared –with-ldap-sasl –with-m
ysql=shared,/usr –with-mysqli=shared,/usr/lib64/mysql/mysql_config –enable-dom=shared –with-pgsql=shared –with-snmp=shared,/usr
–enable-soap=shared –with-xsl=shared,/usr –enable-xmlreader=shared –enable-xmlwriter=shared –enable-fastcgi –enable-pdo=shared
–with-pdo-odbc=shared,unixODBC,/usr –with-pdo-mysql=shared,/usr/lib64/mysql/mysql_config –with-pdo-pgsql=shared,/usr –with-pdo-sqlite=shared,/usr –enable-dbase=shared –enable-mbstring –with-mcrypt=/usr/local/bin/mcrypt –with-apxs2=/usr/sbin/apxs
- Note that you will most likely get a lot of errors after executing this command, but no need to panic. In most cases, the packages you are installing are dependent on “devel” packages. For example, you might get this error: Error: configure: error: Cannot find pspell. To fix this you need to install the pspell devel package: yum install aspell-devel. Here are a couple of sites that will help with dependencies: http://www.lifelinux.com/error-compiling-php-on-centos-x64/ and http://www.mickgenie.com/blog/php-compilation-error/
- So you’ll need to go back and forth between installing devel packages with yum, and then running your configure command again. Once your configure command has run successfully, move on to the next step.
- Now type make
- Then make test (really important to do this step)
- Finally make install
- Optional step: libtool –finish /usr/local/src/php-5.3.8/libs
- cp all modules from /usr/local/src/php-5.3.8/modules/*.so to /usr/lib64/php/modules/
- cp /usr/local/src/php-5.3.8/php-recommended to /etc/php.ini (this file contains configuration settings, like file upload size limits)
- edit /etc/php.ini to set modules path to /usr/lib64/php/modules/
- edit /etc/php.ini to set include_path for pear (if you installed pear)
- Now restart Apache: /usr/sbin/apachectl restart
- To test your php install, you should do two things:
- Type php -v (you should list out your new PHP version, in this case PHP 5.3.8)
- Go to your document root, and create a php file with this code: <?php phpinfo(); ?>, then load that file in a browser. This will give you a full configuration listing on PHP, Apache and MySQL
So hopefully everything worked out for you. There are many things that can go (temporarily) wrong with PHP compiles. But once you successfully compile PHP once, you’ll have a better handle on how to do it in the future.
dee php
To reset the auto increment value back to “1″ in the “mytable” database table:
ALTER TABLE mytable AUTO_INCREMENT=1
dee database, mysql
How to migrate WordPress to a different Linux server.
First migrate the database (use database name “wpdb” for this example):
- User either phpMyAdmin or mysql command line to do a database export (export both data and structure). Here’s a mysql command line exampl example:
# mysql -u username -p wpdb > /home/john/wpdb.sql
After you are prompted for “username’s” password, the contents of the database will be dumped to /home/john/wpdb.sql
- Create the “wpdb” database on the new server, and then import the data: mysql -u username -p wpdb < wpdb.sql
- Set up a new database user for this database. It needs to be the same username/password you have in your wp-config.php WordPress file.
- From the linux command line, grant privileges for this user to use the “wpdb” database:GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES ON wpdb.* TO ‘username’@'localhost’ IDENTIFIED BY ‘password’;(you may need to also reload the mysql GRANT tables by typing: FLUSH PRIVILEGES;)
- Now update the database entries:UPDATE wp_options SET option_value = replace(option_value, ‘http://old-domain.com’, ‘http://new-domain.com’) WHERE option_name = ‘home’;UPDATE wp_options SET option_value = replace(option_value, ‘http://old-domain.com’, ‘http://new-domain.com’) WHERE option_name = ‘siteurl’;UPDATE wp_posts SET guid = replace(guid, ‘http://old-domain.com’,”);UPDATE wp_posts SET post_content = replace(post_content, ‘http://old-domain.com’, ”);
- Using the Worpress Dashboard, update the upload directory by going to Settings–>Miscellaneous Settings
Next migrate the site files:
- cd to the document root of the WordPress site
- tar -cvf myWordpressSite.tar *
- scp or ftp the tar file to your new server
- cd to the document root on the new server
- tar -xvf myWordpressSite.tar
dee migration, wordpress
Here’s how to add a new system user “john” on Solaris 9:
- login as root
- useradd -g modern -m -d /export/home/john -s /usr/bin/bash john
- now create a password: passwd john
dee linux/unix, solaris
Here’s how you can get basic webserver info for another server. Please note that this won’t work if the website uses a CDN.
# telnet www.example.com 80
Trying 216.44.201.135…
Connected to www.litaxforum.com (216.44.201.135).
Escape character is ‘^]’.
/* NOW TYPE THIS: */
GET / HTTP/1.1
/* THEN HIT ENTER TWICE AND YOU GET ALL INFO */
dee apache, linux/unix, web server
To update DNS on a Fedora or Red Hat server:
If NetworkManager is running, you need to edit:
/etc/sysconfig/network-scripts/ifcfg-eth0 by changing the DNS entry
on reboot the above will update /etc/resolv.conf
If there is no network manager, then you just need to edit:
/etc/resolv.conf
dee fedora, linux/unix, red hat
As root, use this command:
/sbin/shutdown -h now
After shutting everything down, the -h option halts the machine, or alternatively
the -r option reboots
If the computer does not power itself down, be careful not to turn off the computer until a message appears indicating that the system is halted (I believe you will see an “ok” prompt). Failure to wait for this message can mean that not all the hard drive partitions are unmounted, which can
lead to file system corruption.
dee fedora, linux/unix red hat
This upgrade was not as simple as upgrading from 10 to 11 or 11 to 12 (I used the yum/preupgrade update method for both of those).
Upgrading F12 to 13 was more involved. My /boot partition was not big enough to complete the installation via yum/preupgrade (F13 wants 500Mb /boot partition). Instead I had to switch repositories to complete the upgrade. Here’s the steps (please note this is on a i386 machine):
- Since my /boot partition was limited, I have to follow these directions for force the the download of the installer: http://fedoraproject.org/wiki/PreUpgrade#Method_2:_Trick_preupgrade_into_downloading_the_installer
- yum update rpm
- yum -y update
- yum clean all
-
wget ftp://download.fedora.redhat.com/pub/fedora/linux/releases/13/Fedora/i386/os/Packages/fedora-release-*.noarch.rpm
- rpm -Uvh fedora-release-*.noarch.rpm
- Now get out of the graphical interface: ctrl + alt + F2
- login as root
- telinit 3
- yum upgrade
- yum groupupdate Base
- /sbin/grub-install –recheck /dev/sda
- /sbin/grub-install /dev/sda
- cd /etc/rc.d/init.d; for f in *; do /sbin/chkconfig $f resetpriorities; done
- reboot
dee fedora, linux/unix fedora, preupgrade, yum
This upgrade was pretty straight forward for me. I used the “preupgrade-cli” method. Here’s the step:
- su -
- yum update rpm
- yum -y update
- yum -y install preupgrade
- yum clean all
- preupgrade-cli “Fedora 12 (Constantine)”
- Once you have gone through the preupgrade, you will be asked to reboot: reboot
Upgrading from Fedora 10 to 11 requires the same steps, except changing step 6 to the appropriate version info.
Upgrading from Fedora 12 to 13 was more involved for me, since the /boot partition of the PC was too small. I used this method for that upgrade: http://techblog.deeblake.com/?p=95
dee fedora, linux/unix preupgrade, yum
This upgrade was pretty straight forward for me. I used the “preupgrade-cli” method. Here’s the steps:
- su -
- yum update rpm
- yum -y update
- yum -y install preupgrade
- yum clean all
- preupgrade-cli “Fedora 11 (Leonidas)”
- Once you have gone through the preupgrade, you will be asked to reboot: reboot
- After reboot you will be lead through the actual upgrade.
I found that after my upgrade I had no internet connection. I fixed this through the GUI by clicking System->Administration->Network and then checking “Activate device when computer starts”. Then you will need to restart network services.
Upgrading from Fedora 11 to 12 requires the same steps, except changing step 6 to the appropriate version info.
Upgrading from Fedora 12 to 13 was more involved for me, since the /boot partition of the PC was too small. I used this method for that upgrade: http://techblog.deeblake.com/?p=95
dee fedora, linux/unix preupgrade, yum